sanitized pcp_unpadfour(), just return the number of zero padding, leave the input pointer untouched; fixed header

This commit is contained in:
TLINDEN
2014-02-10 08:46:52 +01:00
parent 91f94a532e
commit ab03a10340
2 changed files with 6 additions and 8 deletions

View File

@@ -30,10 +30,10 @@
/* convert a binary stream to one which gets accepted by zmq_z85_encode */ /* convert a binary stream to one which gets accepted by zmq_z85_encode */
/* we pad it with zeroes and put the number of zerores in front of it */ /* we pad it with zeroes and put the number of zerores in front of it */
unsigned char *pcp_unpadfour(unsigned char *src, size_t srclen, size_t *dstlen); unsigned char *pcp_padfour(unsigned char *src, size_t srclen, size_t *dstlen);
/* the reverse of the above */ /* the reverse of the above */
unsigned char *pcp_unpadfour(unsigned char *src, size_t srclen, size_t *dstlen); size_t pcp_unpadfour(unsigned char *src, size_t srclen);
/* wrapper around zmq Z85 encoding function */ /* wrapper around zmq Z85 encoding function */
unsigned char *pcp_z85_decode(char *z85block, size_t *dstlen); unsigned char *pcp_z85_decode(char *z85block, size_t *dstlen);

View File

@@ -39,7 +39,7 @@ unsigned char *pcp_padfour(unsigned char *src, size_t srclen, size_t *dstlen) {
return dst; return dst;
} }
unsigned char *pcp_unpadfour(unsigned char *src, size_t srclen, size_t *dstlen) { size_t pcp_unpadfour(unsigned char *src, size_t srclen) {
size_t outlen; size_t outlen;
size_t i; size_t i;
@@ -52,13 +52,11 @@ unsigned char *pcp_unpadfour(unsigned char *src, size_t srclen, size_t *dstlen)
} }
} }
*dstlen = outlen; return outlen;
return src;
} }
unsigned char *pcp_z85_decode(char *z85block, size_t *dstlen) { unsigned char *pcp_z85_decode(char *z85block, size_t *dstlen) {
unsigned char *bin = NULL; unsigned char *bin = NULL;
unsigned char *raw = NULL;
size_t binlen, outlen; size_t binlen, outlen;
binlen = strlen(z85block) * 4 / 5; binlen = strlen(z85block) * 4 / 5;
@@ -69,11 +67,11 @@ unsigned char *pcp_z85_decode(char *z85block, size_t *dstlen) {
return NULL; return NULL;
} }
raw = pcp_unpadfour(bin, binlen, &outlen); outlen = pcp_unpadfour(bin, binlen);
*dstlen = outlen; *dstlen = outlen;
return raw; return bin;
} }
char *pcp_z85_encode(unsigned char *raw, size_t srclen, size_t *dstlen) { char *pcp_z85_encode(unsigned char *raw, size_t srclen, size_t *dstlen) {