Skip to content

Commit

Permalink
[include] refs fibercrypto#5 Refactor make lint-libc
Browse files Browse the repository at this point in the history
  • Loading branch information
Maykel Arias Torres committed Dec 6, 2019
1 parent 39e5da0 commit 6914124
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 178 deletions.
24 changes: 14 additions & 10 deletions include/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ Thank you for inspiration:

#include <stdio.h>

//Base64 char table function - used internally for decoding
// Base64 char table function - used internally for decoding
int b64_int(unsigned int ch);

// in_size : the number bytes to be encoded.
// Returns the recommended memory size to be allocated for the output buffer excluding the null byte
// Returns the recommended memory size to be allocated for the output buffer
// excluding the null byte
unsigned int b64e_size(unsigned int in_size);

// in_size : the number bytes to be decoded.
Expand All @@ -23,22 +24,25 @@ unsigned int b64d_size(unsigned int in_size);

// in : buffer of "raw" binary to be encoded.
// in_len : number of bytes to be encoded.
// out : pointer to buffer with enough memory, user is responsible for memory allocation, receives null-terminated string
// returns size of output including null byte
unsigned int b64_encode(const unsigned char* in, unsigned int in_len, unsigned char* out);
// out : pointer to buffer with enough memory, user is responsible for memory
// allocation, receives null-terminated string returns size of output including
// null byte
unsigned int b64_encode(const unsigned char *in, unsigned int in_len,
unsigned char *out);

// in : buffer of base64 string to be decoded.
// in_len : number of bytes to be decoded.
// out : pointer to buffer with enough memory, user is responsible for memory allocation, receives "raw" binary
// returns size of output excluding null byte
int b64_decode(const unsigned char* in, unsigned int in_len, unsigned char* out);
// out : pointer to buffer with enough memory, user is responsible for memory
// allocation, receives "raw" binary returns size of output excluding null byte
int b64_decode(const unsigned char *in, unsigned int in_len,
unsigned char *out);

// file-version b64_encode
// Input : filenames
// returns size of output
unsigned int b64_encodef(char* InFile, char* OutFile);
unsigned int b64_encodef(char *InFile, char *OutFile);

// file-version b64_decode
// Input : filenames
// returns size of output
int b64_decodef(char* InFile, char* OutFile);
int b64_decodef(char *InFile, char *OutFile);
2 changes: 1 addition & 1 deletion include/fcassert.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef LIBFC_ASSERT_H
#define LIBFC_ASSERT_H

#include "libfibercrypto.h"
#include "fcerrors.h"
#include "libfibercrypto.h"

extern GoInt isGoStringEq(GoString string1, GoString string2);

Expand Down
24 changes: 12 additions & 12 deletions include/fcstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
#include <stdio.h>
#include <stdlib.h>

extern void randBytes(GoSlice* bytes, size_t n);
extern void randBytes(GoSlice *bytes, size_t n);

extern void bytesnhex(unsigned char* buf, char* str, int n);
extern void bytesnhex(unsigned char *buf, char *str, int n);

extern void strnhex(unsigned char* buf, char* str, int n);
extern void strnhex(unsigned char *buf, char *str, int n);

extern void strnhexlower(unsigned char* buf, char* str, int n);
extern void strnhexlower(unsigned char *buf, char *str, int n);

extern int hexnstr(const char* hex, unsigned char* str, int n);
extern int hexnstr(const char *hex, unsigned char *str, int n);

extern void bin2hex(unsigned char* buf, char* str, int n);
extern void bin2hex(unsigned char *buf, char *str, int n);

extern int cmpGoSlice_GoSlice(GoSlice* slice1, GoSlice_* slice2);
extern int cmpGoSlice_GoSlice(GoSlice *slice1, GoSlice_ *slice2);

extern void bin2hex(unsigned char* buf, char* str, int n);
extern void bin2hex(unsigned char *buf, char *str, int n);

extern int string_has_suffix(const char* str, const char* suffix);
extern int string_has_suffix(const char *str, const char *suffix);

extern int string_has_prefix(const char* str, const char* prefix);
extern int string_has_prefix(const char *str, const char *prefix);

extern int count_words(const char* str, int length);
extern int count_words(const char *str, int length);

#endif //LIBFC_STRING_H
#endif // LIBFC_STRING_H
40 changes: 22 additions & 18 deletions include/fctest.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

#include "json.h"
#include "libfibercrypto.h"
#include "fcassert.h"
#include "fctypes.h"
#include "json.h"
#include "libfibercrypto.h"

#ifndef LIBFC_TEST_H
#define LIBFC_TEST_H
Expand All @@ -19,45 +19,49 @@
*----------------------------------------------------------------------
*/

void* registerMemCleanup(void* p);
void *registerMemCleanup(void *p);

int registerJsonFree(void* p);
int registerJsonFree(void *p);

void freeRegisteredJson(void* p);
void freeRegisteredJson(void *p);

int registerHandleClose(Handle handle);

void closeRegisteredHandle(Handle handle);

void freeRegisteredMemCleanup(void* p);
void freeRegisteredMemCleanup(void *p);

int copySlice(GoSlice_* pdest, GoSlice_* psource, int elem_size);
int copyGoSlice_toGoSlice(GoSlice* pdest, GoSlice_* psource, int elem_size);
int copySlice(GoSlice_ *pdest, GoSlice_ *psource, int elem_size);
int copyGoSlice_toGoSlice(GoSlice *pdest, GoSlice_ *psource, int elem_size);

int cutSlice(GoSlice_* slice, int start, int end, int elem_size, GoSlice_* result);
int cutSlice(GoSlice_ *slice, int start, int end, int elem_size,
GoSlice_ *result);

int concatSlices(GoSlice_* slice1, GoSlice_* slice2, int elem_size, GoSlice_* result);
int concatSlices(GoSlice_ *slice1, GoSlice_ *slice2, int elem_size,
GoSlice_ *result);

/*----------------------------------------------------------------------
* JSON helpers
*----------------------------------------------------------------------
*/

json_value* loadJsonFile(const char* filename);
json_value *loadJsonFile(const char *filename);

json_value* json_get_string(json_value* value, const char* key);
json_value *json_get_string(json_value *value, const char *key);

int json_set_string(json_value* value, const char* new_string_value);
int json_set_string(json_value *value, const char *new_string_value);

int compareJsonValues(json_value* value1, json_value* value2);
int compareJsonValues(json_value *value1, json_value *value2);

json_value* get_json_value(json_value* node, const char* path, json_type type);
json_value *get_json_value(json_value *node, const char *path, json_type type);

json_value* get_json_value_not_strict(json_value* node, const char* path, json_type type, int allow_null);
json_value *get_json_value_not_strict(json_value *node, const char *path,
json_type type, int allow_null);

int compareJsonValuesWithIgnoreList(json_value* value1, json_value* value2, const char* ignoreList);
int compareJsonValuesWithIgnoreList(json_value *value1, json_value *value2,
const char *ignoreList);

int parseBoolean(const char* str, int length);
int parseBoolean(const char *str, int length);

/*----------------------------------------------------------------------
* Test infrastructure
Expand Down
1 change: 0 additions & 1 deletion include/fctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ typedef struct {
///< size.
} GoSlice_;


#include "fctypes.gen.h"

/**
Expand Down
Loading

0 comments on commit 6914124

Please sign in to comment.