tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nssb64.h (3248B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /*
      6 * Public prototypes for base64 encoding/decoding.
      7 */
      8 #ifndef _NSSB64_H_
      9 #define _NSSB64_H_
     10 
     11 #include "utilrename.h"
     12 #include "seccomon.h"
     13 #include "nssb64t.h"
     14 
     15 SEC_BEGIN_PROTOS
     16 
     17 /*
     18 * Functions to start a base64 decoding/encoding context.
     19 */
     20 
     21 extern NSSBase64Decoder *
     22 NSSBase64Decoder_Create(PRInt32 (*output_fn)(void *, const unsigned char *,
     23                                             PRInt32),
     24                        void *output_arg);
     25 
     26 extern NSSBase64Encoder *
     27 NSSBase64Encoder_Create(PRInt32 (*output_fn)(void *, const char *, PRInt32),
     28                        void *output_arg);
     29 
     30 /*
     31 * Push data through the decoder/encoder, causing the output_fn (provided
     32 * to Create) to be called with the decoded/encoded data.
     33 */
     34 
     35 extern SECStatus
     36 NSSBase64Decoder_Update(NSSBase64Decoder *data, const char *buffer,
     37                        PRUint32 size);
     38 
     39 extern SECStatus
     40 NSSBase64Encoder_Update(NSSBase64Encoder *data, const unsigned char *buffer,
     41                        PRUint32 size);
     42 
     43 /*
     44 * When you're done processing, call this to close the context.
     45 * If "abort_p" is false, then calling this may cause the output_fn
     46 * to be called one last time (as the last buffered data is flushed out).
     47 */
     48 
     49 extern SECStatus
     50 NSSBase64Decoder_Destroy(NSSBase64Decoder *data, PRBool abort_p);
     51 
     52 extern SECStatus
     53 NSSBase64Encoder_Destroy(NSSBase64Encoder *data, PRBool abort_p);
     54 
     55 /*
     56 * Perform base64 decoding from an ascii string "inStr" to an Item.
     57 * The length of the input must be provided as "inLen".  The Item
     58 * may be provided (as "outItemOpt"); you can also pass in a NULL
     59 * and the Item will be allocated for you.
     60 *
     61 * In any case, the data within the Item will be allocated for you.
     62 * All allocation will happen out of the passed-in "arenaOpt", if non-NULL.
     63 * If "arenaOpt" is NULL, standard allocation (heap) will be used and
     64 * you will want to free the result via SECITEM_FreeItem.
     65 *
     66 * Return value is NULL on error, the Item (allocated or provided) otherwise.
     67 */
     68 extern SECItem *
     69 NSSBase64_DecodeBuffer(PLArenaPool *arenaOpt, SECItem *outItemOpt,
     70                       const char *inStr, unsigned int inLen);
     71 
     72 /*
     73 * Perform base64 encoding of binary data "inItem" to an ascii string.
     74 * The output buffer may be provided (as "outStrOpt"); you can also pass
     75 * in a NULL and the buffer will be allocated for you.  The result will
     76 * be null-terminated, and if the buffer is provided, "maxOutLen" must
     77 * specify the maximum length of the buffer and will be checked to
     78 * supply sufficient space space for the encoded result.  (If "outStrOpt"
     79 * is NULL, "maxOutLen" is ignored.)
     80 *
     81 * If "outStrOpt" is NULL, allocation will happen out of the passed-in
     82 * "arenaOpt", if *it* is non-NULL, otherwise standard allocation (heap)
     83 * will be used.
     84 *
     85 * Return value is NULL on error, the output buffer (allocated or provided)
     86 * otherwise.
     87 */
     88 extern char *
     89 NSSBase64_EncodeItem(PLArenaPool *arenaOpt, char *outStrOpt,
     90                     unsigned int maxOutLen, SECItem *inItem);
     91 
     92 SEC_END_PROTOS
     93 
     94 #endif /* _NSSB64_H_ */