michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Public prototypes for base64 encoding/decoding. michael@0: */ michael@0: #ifndef _NSSB64_H_ michael@0: #define _NSSB64_H_ michael@0: michael@0: #include "utilrename.h" michael@0: #include "seccomon.h" michael@0: #include "nssb64t.h" michael@0: michael@0: SEC_BEGIN_PROTOS michael@0: michael@0: /* michael@0: * Functions to start a base64 decoding/encoding context. michael@0: */ michael@0: michael@0: extern NSSBase64Decoder * michael@0: NSSBase64Decoder_Create (PRInt32 (*output_fn) (void *, const unsigned char *, michael@0: PRInt32), michael@0: void *output_arg); michael@0: michael@0: extern NSSBase64Encoder * michael@0: NSSBase64Encoder_Create (PRInt32 (*output_fn) (void *, const char *, PRInt32), michael@0: void *output_arg); michael@0: michael@0: /* michael@0: * Push data through the decoder/encoder, causing the output_fn (provided michael@0: * to Create) to be called with the decoded/encoded data. michael@0: */ michael@0: michael@0: extern SECStatus michael@0: NSSBase64Decoder_Update (NSSBase64Decoder *data, const char *buffer, michael@0: PRUint32 size); michael@0: michael@0: extern SECStatus michael@0: NSSBase64Encoder_Update (NSSBase64Encoder *data, const unsigned char *buffer, michael@0: PRUint32 size); michael@0: michael@0: /* michael@0: * When you're done processing, call this to close the context. michael@0: * If "abort_p" is false, then calling this may cause the output_fn michael@0: * to be called one last time (as the last buffered data is flushed out). michael@0: */ michael@0: michael@0: extern SECStatus michael@0: NSSBase64Decoder_Destroy (NSSBase64Decoder *data, PRBool abort_p); michael@0: michael@0: extern SECStatus michael@0: NSSBase64Encoder_Destroy (NSSBase64Encoder *data, PRBool abort_p); michael@0: michael@0: /* michael@0: * Perform base64 decoding from an ascii string "inStr" to an Item. michael@0: * The length of the input must be provided as "inLen". The Item michael@0: * may be provided (as "outItemOpt"); you can also pass in a NULL michael@0: * and the Item will be allocated for you. michael@0: * michael@0: * In any case, the data within the Item will be allocated for you. michael@0: * All allocation will happen out of the passed-in "arenaOpt", if non-NULL. michael@0: * If "arenaOpt" is NULL, standard allocation (heap) will be used and michael@0: * you will want to free the result via SECITEM_FreeItem. michael@0: * michael@0: * Return value is NULL on error, the Item (allocated or provided) otherwise. michael@0: */ michael@0: extern SECItem * michael@0: NSSBase64_DecodeBuffer (PLArenaPool *arenaOpt, SECItem *outItemOpt, michael@0: const char *inStr, unsigned int inLen); michael@0: michael@0: /* michael@0: * Perform base64 encoding of binary data "inItem" to an ascii string. michael@0: * The output buffer may be provided (as "outStrOpt"); you can also pass michael@0: * in a NULL and the buffer will be allocated for you. The result will michael@0: * be null-terminated, and if the buffer is provided, "maxOutLen" must michael@0: * specify the maximum length of the buffer and will be checked to michael@0: * supply sufficient space space for the encoded result. (If "outStrOpt" michael@0: * is NULL, "maxOutLen" is ignored.) michael@0: * michael@0: * If "outStrOpt" is NULL, allocation will happen out of the passed-in michael@0: * "arenaOpt", if *it* is non-NULL, otherwise standard allocation (heap) michael@0: * will be used. michael@0: * michael@0: * Return value is NULL on error, the output buffer (allocated or provided) michael@0: * otherwise. michael@0: */ michael@0: extern char * michael@0: NSSBase64_EncodeItem (PLArenaPool *arenaOpt, char *outStrOpt, michael@0: unsigned int maxOutLen, SECItem *inItem); michael@0: michael@0: SEC_END_PROTOS michael@0: michael@0: #endif /* _NSSB64_H_ */