Skip to content

Commit

Permalink
Add some additional docs and sentenials
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkx committed Apr 1, 2021
1 parent 72ac169 commit 27307bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 6 additions & 0 deletions base45.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ int base45_decode(unsigned char * dst, size_t * _max_dst_len, const char * src,
size_t out_len = 0, max_dst_len;
max_dst_len = _max_dst_len ? *_max_dst_len : src_len;

if (dst == NULL && _max_dst_len == NULL)
return -2;

if (src == NULL)
return -2;

if (src_len == 0)
src_len = strlen(src);

Expand Down
19 changes: 15 additions & 4 deletions base45.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
src source data
src_len source length
If the encoded string is longer than *dst_lenOrNull the actual length will still be returned.
If the encoded string is longer than *dst_lenOrNull the actual length will still be returned. This
can be used in conjuction with a NULL destination to get the length of the buffer needed. (Though x3
is always safe).
The resulting buffer will be \0 terminated. This \0 does not count in the returned length.
returns 0 on sucess.
*/
Expand All @@ -25,12 +29,19 @@ int base45_encode(char * dstOrNull, size_t *dst_lenOrNull, const unsigned char *
or NULL to skip writing.
dst_lenOrNull pointer to the length of the dstOrNull buffer; will return actual value.
src source data
src_len source length or null (in which case the terminating \0 of the string is used).
src_len source length or 0 (in which case the terminating \0 of the string is used).
If the encoded string is longer than *dst_lenOrNull the actual length will still be returned. This
can also be used, in combiantion with a NULL destination, to get the size of the buffer needed.
The decode is case-insensitive; and will give an error on unknown characters (including on \r
and \n). If dst_lenOrNull is null; dstOrNull, when non-null, is assumed to be of a suitable
length. Having both null will result in an error (return value -2)
If the encoded string is longer than *dst_lenOrNull the actual length will still be returned.
The resulting buffer will not be \0 terminated.
returns 0 on sucess.
returns -1 on illegal values or impossible lengths.
returns -1 on illegal values or impossible lengths, -2 on illegal inputs.
*/

int base45_decode(unsigned char * dstOrNull, size_t *dst_lenOrNull, const char * src, size_t src_len);
Expand Down

0 comments on commit 27307bb

Please sign in to comment.