PageRenderTime 196ms CodeModel.GetById 76ms app.highlight 9ms RepoModel.GetById 61ms app.codeStats 0ms

/gecko_api/include/nssb64.h

http://firefox-mac-pdf.googlecode.com/
C++ Header | 128 lines | 31 code | 16 blank | 81 comment | 0 complexity | ddf2e3a3527c1100a77d5ef6a8a2cae4 MD5 | raw file
  1/* ***** BEGIN LICENSE BLOCK *****
  2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3 *
  4 * The contents of this file are subject to the Mozilla Public License Version
  5 * 1.1 (the "License"); you may not use this file except in compliance with
  6 * the License. You may obtain a copy of the License at
  7 * http://www.mozilla.org/MPL/
  8 *
  9 * Software distributed under the License is distributed on an "AS IS" basis,
 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 11 * for the specific language governing rights and limitations under the
 12 * License.
 13 *
 14 * The Original Code is the Netscape security libraries.
 15 *
 16 * The Initial Developer of the Original Code is
 17 * Netscape Communications Corporation.
 18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
 19 * the Initial Developer. All Rights Reserved.
 20 *
 21 * Contributor(s):
 22 *
 23 * Alternatively, the contents of this file may be used under the terms of
 24 * either the GNU General Public License Version 2 or later (the "GPL"), or
 25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 26 * in which case the provisions of the GPL or the LGPL are applicable instead
 27 * of those above. If you wish to allow use of your version of this file only
 28 * under the terms of either the GPL or the LGPL, and not to allow others to
 29 * use your version of this file under the terms of the MPL, indicate your
 30 * decision by deleting the provisions above and replace them with the notice
 31 * and other provisions required by the GPL or the LGPL. If you do not delete
 32 * the provisions above, a recipient may use your version of this file under
 33 * the terms of any one of the MPL, the GPL or the LGPL.
 34 *
 35 * ***** END LICENSE BLOCK ***** */
 36
 37/*
 38 * Public prototypes for base64 encoding/decoding.
 39 *
 40 * $Id: nssb64.h,v 1.4 2007/10/12 01:44:51 julien.pierre.boogz%sun.com Exp $
 41 */
 42#ifndef _NSSB64_H_
 43#define _NSSB64_H_
 44
 45#include "utilrename.h"
 46#include "seccomon.h"
 47#include "nssb64t.h"
 48
 49SEC_BEGIN_PROTOS
 50
 51/*
 52 * Functions to start a base64 decoding/encoding context.
 53 */
 54
 55extern NSSBase64Decoder *
 56NSSBase64Decoder_Create (PRInt32 (*output_fn) (void *, const unsigned char *,
 57					       PRInt32),
 58			 void *output_arg);
 59
 60extern NSSBase64Encoder *
 61NSSBase64Encoder_Create (PRInt32 (*output_fn) (void *, const char *, PRInt32),
 62			 void *output_arg);
 63
 64/*
 65 * Push data through the decoder/encoder, causing the output_fn (provided
 66 * to Create) to be called with the decoded/encoded data.
 67 */
 68
 69extern SECStatus
 70NSSBase64Decoder_Update (NSSBase64Decoder *data, const char *buffer,
 71			 PRUint32 size);
 72
 73extern SECStatus
 74NSSBase64Encoder_Update (NSSBase64Encoder *data, const unsigned char *buffer,
 75			 PRUint32 size);
 76
 77/*
 78 * When you're done processing, call this to close the context.
 79 * If "abort_p" is false, then calling this may cause the output_fn
 80 * to be called one last time (as the last buffered data is flushed out).
 81 */
 82
 83extern SECStatus
 84NSSBase64Decoder_Destroy (NSSBase64Decoder *data, PRBool abort_p);
 85
 86extern SECStatus
 87NSSBase64Encoder_Destroy (NSSBase64Encoder *data, PRBool abort_p);
 88
 89/*
 90 * Perform base64 decoding from an ascii string "inStr" to an Item.
 91 * The length of the input must be provided as "inLen".  The Item
 92 * may be provided (as "outItemOpt"); you can also pass in a NULL
 93 * and the Item will be allocated for you.
 94 *
 95 * In any case, the data within the Item will be allocated for you.
 96 * All allocation will happen out of the passed-in "arenaOpt", if non-NULL.
 97 * If "arenaOpt" is NULL, standard allocation (heap) will be used and
 98 * you will want to free the result via SECITEM_FreeItem.
 99 *
100 * Return value is NULL on error, the Item (allocated or provided) otherwise.
101 */
102extern SECItem *
103NSSBase64_DecodeBuffer (PRArenaPool *arenaOpt, SECItem *outItemOpt,
104			const char *inStr, unsigned int inLen);
105
106/*
107 * Perform base64 encoding of binary data "inItem" to an ascii string.
108 * The output buffer may be provided (as "outStrOpt"); you can also pass
109 * in a NULL and the buffer will be allocated for you.  The result will
110 * be null-terminated, and if the buffer is provided, "maxOutLen" must
111 * specify the maximum length of the buffer and will be checked to
112 * supply sufficient space space for the encoded result.  (If "outStrOpt"
113 * is NULL, "maxOutLen" is ignored.)
114 *
115 * If "outStrOpt" is NULL, allocation will happen out of the passed-in
116 * "arenaOpt", if *it* is non-NULL, otherwise standard allocation (heap)
117 * will be used.
118 *
119 * Return value is NULL on error, the output buffer (allocated or provided)
120 * otherwise.
121 */
122extern char *
123NSSBase64_EncodeItem (PRArenaPool *arenaOpt, char *outStrOpt,
124		      unsigned int maxOutLen, SECItem *inItem);
125
126SEC_END_PROTOS
127
128#endif /* _NSSB64_H_ */