security/nss/lib/util/nssb64.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/util/nssb64.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/*
     1.9 + * Public prototypes for base64 encoding/decoding.
    1.10 + */
    1.11 +#ifndef _NSSB64_H_
    1.12 +#define _NSSB64_H_
    1.13 +
    1.14 +#include "utilrename.h"
    1.15 +#include "seccomon.h"
    1.16 +#include "nssb64t.h"
    1.17 +
    1.18 +SEC_BEGIN_PROTOS
    1.19 +
    1.20 +/*
    1.21 + * Functions to start a base64 decoding/encoding context.
    1.22 + */
    1.23 +
    1.24 +extern NSSBase64Decoder *
    1.25 +NSSBase64Decoder_Create (PRInt32 (*output_fn) (void *, const unsigned char *,
    1.26 +					       PRInt32),
    1.27 +			 void *output_arg);
    1.28 +
    1.29 +extern NSSBase64Encoder *
    1.30 +NSSBase64Encoder_Create (PRInt32 (*output_fn) (void *, const char *, PRInt32),
    1.31 +			 void *output_arg);
    1.32 +
    1.33 +/*
    1.34 + * Push data through the decoder/encoder, causing the output_fn (provided
    1.35 + * to Create) to be called with the decoded/encoded data.
    1.36 + */
    1.37 +
    1.38 +extern SECStatus
    1.39 +NSSBase64Decoder_Update (NSSBase64Decoder *data, const char *buffer,
    1.40 +			 PRUint32 size);
    1.41 +
    1.42 +extern SECStatus
    1.43 +NSSBase64Encoder_Update (NSSBase64Encoder *data, const unsigned char *buffer,
    1.44 +			 PRUint32 size);
    1.45 +
    1.46 +/*
    1.47 + * When you're done processing, call this to close the context.
    1.48 + * If "abort_p" is false, then calling this may cause the output_fn
    1.49 + * to be called one last time (as the last buffered data is flushed out).
    1.50 + */
    1.51 +
    1.52 +extern SECStatus
    1.53 +NSSBase64Decoder_Destroy (NSSBase64Decoder *data, PRBool abort_p);
    1.54 +
    1.55 +extern SECStatus
    1.56 +NSSBase64Encoder_Destroy (NSSBase64Encoder *data, PRBool abort_p);
    1.57 +
    1.58 +/*
    1.59 + * Perform base64 decoding from an ascii string "inStr" to an Item.
    1.60 + * The length of the input must be provided as "inLen".  The Item
    1.61 + * may be provided (as "outItemOpt"); you can also pass in a NULL
    1.62 + * and the Item will be allocated for you.
    1.63 + *
    1.64 + * In any case, the data within the Item will be allocated for you.
    1.65 + * All allocation will happen out of the passed-in "arenaOpt", if non-NULL.
    1.66 + * If "arenaOpt" is NULL, standard allocation (heap) will be used and
    1.67 + * you will want to free the result via SECITEM_FreeItem.
    1.68 + *
    1.69 + * Return value is NULL on error, the Item (allocated or provided) otherwise.
    1.70 + */
    1.71 +extern SECItem *
    1.72 +NSSBase64_DecodeBuffer (PLArenaPool *arenaOpt, SECItem *outItemOpt,
    1.73 +			const char *inStr, unsigned int inLen);
    1.74 +
    1.75 +/*
    1.76 + * Perform base64 encoding of binary data "inItem" to an ascii string.
    1.77 + * The output buffer may be provided (as "outStrOpt"); you can also pass
    1.78 + * in a NULL and the buffer will be allocated for you.  The result will
    1.79 + * be null-terminated, and if the buffer is provided, "maxOutLen" must
    1.80 + * specify the maximum length of the buffer and will be checked to
    1.81 + * supply sufficient space space for the encoded result.  (If "outStrOpt"
    1.82 + * is NULL, "maxOutLen" is ignored.)
    1.83 + *
    1.84 + * If "outStrOpt" is NULL, allocation will happen out of the passed-in
    1.85 + * "arenaOpt", if *it* is non-NULL, otherwise standard allocation (heap)
    1.86 + * will be used.
    1.87 + *
    1.88 + * Return value is NULL on error, the output buffer (allocated or provided)
    1.89 + * otherwise.
    1.90 + */
    1.91 +extern char *
    1.92 +NSSBase64_EncodeItem (PLArenaPool *arenaOpt, char *outStrOpt,
    1.93 +		      unsigned int maxOutLen, SECItem *inItem);
    1.94 +
    1.95 +SEC_END_PROTOS
    1.96 +
    1.97 +#endif /* _NSSB64_H_ */

mercurial