libpcp  0.2.1
Functions
Z85

Z85 Encoding functions. More...

Functions

unsigned char * pcp_padfour (unsigned char *src, size_t srclen, size_t *dstlen)
 Zero-pad some input data.
 
size_t pcp_unpadfour (unsigned char *src, size_t srclen)
 Unpad padded input data.
 
unsigned char * pcp_z85_decode (char *z85block, size_t *dstlen)
 Decode data from Z85 encoding.
 
char * pcp_z85_encode (unsigned char *raw, size_t srclen, size_t *dstlen)
 Encode data to Z85 encoding.
 
char * pcp_readz85file (FILE *infile)
 Read a Z85 encoded file.
 
char * pcp_readz85string (unsigned char *input, size_t bufsize)
 Read a Z85 encoded string.
 

Detailed Description

Z85 Encoding functions.

The Z85 encoding format is described here: ZeroMQ Spec.32. It's part of ZeroMQ. Z85 is based on ASCII85 with a couple of modifications (portability, readability etc).

To fulfil the requirements of the ZeroMQ Z85 functions, PCP does some additional preparations of raw input before actually doing the encoding, since the input for zmq_z85_encode() must be divisible by 4. Therefore we pad the input with zeroes and remove them after decoding.

Function Documentation

unsigned char* pcp_padfour ( unsigned char *  src,
size_t  srclen,
size_t *  dstlen 
)

Zero-pad some input data.

This function allocates new memory for the returned data. It puts the original pointer into it and adds a number of zeros so that the result has a size divisable by 4.

Parameters
[in]srcUnpadded data.
[in]srclenSize of unpadded data.
[in]dstlenReturned size of padded data (pointer to int).
Returns
Returns a pointer to the padded data.
char* pcp_readz85file ( FILE *  infile)

Read a Z85 encoded file.

Reads a file and returns the raw Z85 encoded string. It ignores newlines, comments and Headerstrings.

Parameters
[in]infileFILE stream to read from.
Returns
Raw Z85 encoded string with comments, headers and newlines removed.
char* pcp_readz85string ( unsigned char *  input,
size_t  bufsize 
)

Read a Z85 encoded string.

Parses the given input string and returns the raw Z85 encoded string. It ignores newlines, comments and Headerstrings.

Parameters
[in]inputZ85 encoded string.
[in]bufsizeSize of the string.
Returns
Raw Z85 encoded string with comments, headers and newlines removed.
size_t pcp_unpadfour ( unsigned char *  src,
size_t  srclen 
)

Unpad padded input data.

It just calculates the size of the unpadded result (size - all trailing zeroes). Doesn't allocate any memory or modify anything.

Parameters
[in]srcPadded data.
[in]srclenSize of padded data.
Returns
Returns the unpadded size of the data.
unsigned char* pcp_z85_decode ( char *  z85block,
size_t *  dstlen 
)

Decode data from Z85 encoding.

The input z85block may contain newlines which will be removed.

Parameters
[in]z85blockThe Z85 encoded string.
[in]dstlenReturned size of decoded data (pointer to int).
Returns
Returns a newly allocated pointer to the decoded data. If decoding failed, returns NULL. Check fatals_if_any().
char* pcp_z85_encode ( unsigned char *  raw,
size_t  srclen,
size_t *  dstlen 
)

Encode data to Z85 encoding.

Beside Z85 encoding it also adds a newline everiy 72 characters.

Parameters
[in]rawPointer to raw data.
[in]srclenSize of the data.
[in]dstlenReturned size of encoded data (pointer to int).
Returns
Returns a string (char array) containing the Z85 encoded data.