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