mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 12:00:56 +01:00
do only pad if ! %4
This commit is contained in:
12
libpcp/z85.c
12
libpcp/z85.c
@@ -212,10 +212,18 @@ byte *pcp_z85_decode(PCPCTX *ptx, char *z85block, size_t *dstlen) {
|
|||||||
|
|
||||||
char *pcp_z85_encode(byte *raw, size_t srclen, size_t *dstlen) {
|
char *pcp_z85_encode(byte *raw, size_t srclen, size_t *dstlen) {
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
byte *padded;
|
||||||
size_t outlen, blocklen, zlen;
|
size_t outlen, blocklen, zlen;
|
||||||
|
|
||||||
|
if(srclen %4 == 0) {
|
||||||
|
/* no padding required */
|
||||||
|
padded = raw;
|
||||||
|
outlen = srclen;
|
||||||
|
}
|
||||||
|
else {
|
||||||
/* make z85 happy (size % 4) */
|
/* make z85 happy (size % 4) */
|
||||||
byte *padded = pcp_padfour(raw, srclen, &outlen);
|
padded = pcp_padfour(raw, srclen, &outlen);
|
||||||
|
}
|
||||||
|
|
||||||
/* encode to z85 */
|
/* encode to z85 */
|
||||||
zlen = (outlen * 5 / 4) + 1;
|
zlen = (outlen * 5 / 4) + 1;
|
||||||
@@ -245,6 +253,8 @@ char *pcp_z85_encode(byte *raw, size_t srclen, size_t *dstlen) {
|
|||||||
|
|
||||||
*dstlen = blocklen;
|
*dstlen = blocklen;
|
||||||
free(z85);
|
free(z85);
|
||||||
|
|
||||||
|
if(srclen %4 != 0)
|
||||||
free(padded);
|
free(padded);
|
||||||
|
|
||||||
return z85block;
|
return z85block;
|
||||||
|
|||||||
Reference in New Issue
Block a user