-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #270 from mfrey/remove_c_includes
removes source file includes in ccnl-utils
- Loading branch information
Showing
29 changed files
with
667 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// base64.c | ||
// from stackoverflow.com, user RYYST | ||
|
||
#ifndef BASE64_H | ||
#define BASE64_H | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
|
||
/** | ||
* @brief Initializes the base64 decoding table | ||
*/ | ||
void base64_build_decoding_table(void); | ||
|
||
/** | ||
* @brief Encodes a string \p data into a base64 string | ||
* | ||
* @param[in] data The data to encode | ||
* @param[in] input_length The size of the data to encode | ||
* @param[out] output_length The size of the encoded date | ||
* | ||
* @return Upon success, a base64 encoded representation of \p data | ||
* @return NULL if \p data was NULL | ||
* @return NULL if allocating the result string failed | ||
* @return NULL if \p input_length is not in multiples of four | ||
*/ | ||
char *base64_encode(const char *data, | ||
size_t input_length, | ||
size_t *output_length); | ||
|
||
/** | ||
* @brief Decodes a string \p data into a base64 string | ||
* | ||
* @param[in] data The data to decode | ||
* @param[in] input_length The size of the data to decode | ||
* @param[out] output_length The size of the decoded date | ||
* | ||
* @return Upon success, the base64 decoded \p data | ||
* @return NULL if \p data was NULL | ||
* @return NULL if allocating the result string failed | ||
* @return NULL if \p input_length is not in multiples of four | ||
*/ | ||
unsigned char *base64_decode(const char *data, | ||
size_t input_length, | ||
size_t *output_length); | ||
|
||
/** | ||
* @brief Frees the previously allocated decoding table | ||
*/ | ||
void base64_cleanup(void); | ||
|
||
#endif // EOF | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/** | ||
* @addtogroup CCNL-utils | ||
* @{ | ||
* | ||
* @file ccnl-common.h | ||
* @brief Common functions for the CCN-lite utilities | ||
* | ||
* Copyright (C) 2013-18 Christian Tschudin, University of Basel | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
#ifndef CCNL_COMMON_H | ||
#define CCNL_COMMON_H | ||
|
||
#ifndef CCNL_UAPI_H_ // if CCNL_UAPI_H_ is defined then the following config is taken care elsewhere in the code composite | ||
|
||
|
||
#define _DEFAULT_SOURCE | ||
#define _BSD_SOURCE | ||
#define _SVID_SOURCE | ||
|
||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <time.h> | ||
#include <unistd.h> | ||
#include <getopt.h> | ||
#include <limits.h> | ||
|
||
#include <arpa/inet.h> | ||
#include <sys/types.h> | ||
#include <sys/select.h> | ||
#include <sys/socket.h> | ||
#include <netinet/in.h> | ||
#include <sys/stat.h> | ||
#include <sys/un.h> | ||
|
||
#include "base64.h" | ||
|
||
#include "ccnl-os-includes.h" | ||
#include "ccnl-defs.h" | ||
#include "ccnl-core.h" | ||
#include "ccnl-pkt-builder.h" | ||
#include "ccnl-malloc.h" | ||
#include "ccnl-os-time.h" | ||
#include "ccnl-logging.h" | ||
#include "ccnl-pkt-builder.h" | ||
|
||
#ifndef USE_DEBUG_MALLOC | ||
#define ccnl_malloc(s) malloc(s) | ||
#define ccnl_calloc(n,s) calloc(n,s) | ||
#define ccnl_realloc(p,s) realloc(p,s) | ||
#define ccnl_free(p) free(p) | ||
#endif //USE_DEBUG_MALLOC | ||
#define free_2ptr_list(a,b) ccnl_free(a), ccnl_free(b) | ||
|
||
struct ccnl_prefix_s* ccnl_prefix_new(int suite, int cnt); | ||
int ccnl_pkt_prependComponent(int suite, char *src, int *offset, unsigned char *buf); | ||
|
||
#include "ccnl-core.h" | ||
#include "ccnl-pkt-ccnb.h" | ||
#include "ccnl-pkt-ccntlv.h" | ||
#include "ccnl-pkt-localrpc.h" | ||
#include "ccnl-pkt-ndntlv.h" | ||
#include "ccnl-pkt-switch.h" | ||
|
||
#include "ccnl-socket.h" | ||
|
||
#define ccnl_core_addToCleanup(b) do{}while(0) | ||
|
||
// include only the utils, not the core routines: | ||
#ifdef USE_FRAG | ||
#include "../ccnl-frag.h" | ||
#endif | ||
|
||
#else // CCNL_UAPI_H_ is defined | ||
|
||
#include "base64.c" | ||
#ifdef RIOT_VERSION | ||
#include "ccnl-defs.h" | ||
#include "net/packet.h" | ||
#include <unistd.h> | ||
#include "sys/socket.h" | ||
#include "ccn-lite-riot.h" | ||
#include "ccnl-headers.h" | ||
#include "ccnl-pkt-ndntlv.h" | ||
#include "ccnl-pkt-ccntlv.h" | ||
#include "ccnl-pkt-ccnb.h" | ||
|
||
|
||
extern int ccnl_suite2defaultPort(int suite); | ||
#endif | ||
|
||
#endif // CCNL_UAPI_H_ | ||
|
||
|
||
// ---------------------------------------------------------------------- | ||
|
||
const char* ccnl_enc2str(int enc); | ||
|
||
// ---------------------------------------------------------------------- | ||
|
||
#define extractStr(VAR,DTAG) \ | ||
if (typ == CCN_TT_DTAG && num == DTAG) { \ | ||
char *s; unsigned char *valptr; int vallen; \ | ||
if (ccnl_ccnb_consume(typ, num, &buf, &buflen, &valptr, &vallen) < 0) \ | ||
goto Bail; \ | ||
s = ccnl_malloc(vallen+1); if (!s) goto Bail; \ | ||
memcpy(s, valptr, vallen); s[vallen] = '\0'; \ | ||
ccnl_free(VAR); \ | ||
VAR = (unsigned char*) s; \ | ||
continue; \ | ||
} do {} while(0) | ||
|
||
#define extractStr2(VAR,DTAG) \ | ||
if (typ == CCN_TT_DTAG && num == DTAG) { \ | ||
char *s; unsigned char *valptr; int vallen; \ | ||
if (ccnl_ccnb_consume(typ, num, buf, buflen, &valptr, &vallen) < 0) \ | ||
goto Bail; \ | ||
s = ccnl_malloc(vallen+1); if (!s) goto Bail; \ | ||
memcpy(s, valptr, vallen); s[vallen] = '\0'; \ | ||
ccnl_free(VAR); \ | ||
VAR = (unsigned char*) s; \ | ||
continue; \ | ||
} do {} while(0) | ||
|
||
// ---------------------------------------------------------------------- | ||
|
||
struct key_s { | ||
struct key_s *next; | ||
unsigned char* key; | ||
int keylen; | ||
}; | ||
|
||
struct key_s* load_keys_from_file(char *path); | ||
|
||
// ---------------------------------------------------------------------- | ||
|
||
int | ||
ccnl_parseUdp(char *udp, int suite, char **addr, int *port); | ||
|
||
#endif | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @addtogroup CCNL-utils | ||
* @{ | ||
* | ||
* @file ccnl-crypto.h | ||
* @brief Crypto functions for CCN-lite utilities | ||
* | ||
* Copyright (C) 2013-2018, Christian Tschudin, University of Basel | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
#ifndef CCNL_CRYPTO_H | ||
#define CCNL_CRYPTO_H | ||
|
||
#ifdef USE_SIGNATURES | ||
#include <openssl/pem.h> | ||
#include <openssl/sha.h> | ||
#include <openssl/rsa.h> | ||
#include <openssl/objects.h> | ||
#include <openssl/err.h> | ||
#endif | ||
|
||
int sha(void* input, unsigned long length, unsigned char* md); | ||
|
||
int sign(char* private_key_path, unsigned char *msg, int msg_len, | ||
unsigned char *sig, unsigned int *sig_len); | ||
|
||
int | ||
verify(char* public_key_path, unsigned char *msg, int msg_len, | ||
unsigned char *sig, unsigned int sig_len); | ||
|
||
int | ||
add_signature(unsigned char *out, char *private_key_path, | ||
unsigned char *file, unsigned int fsize); | ||
|
||
#endif | ||
/** @} */ |
Oops, something went wrong.