Back to index

lightning-sunbird  0.9+nobinonly
nssb64.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /*
00038  * Public prototypes for base64 encoding/decoding.
00039  *
00040  * $Id: nssb64.h,v 1.3 2004/04/25 15:03:17 gerv%gerv.net Exp $
00041  */
00042 #ifndef _NSSB64_H_
00043 #define _NSSB64_H_
00044 
00045 #include "seccomon.h"
00046 #include "nssb64t.h"
00047 
00048 SEC_BEGIN_PROTOS
00049 
00050 /*
00051  * Functions to start a base64 decoding/encoding context.
00052  */
00053 
00054 extern NSSBase64Decoder *
00055 NSSBase64Decoder_Create (PRInt32 (*output_fn) (void *, const unsigned char *,
00056                                           PRInt32),
00057                       void *output_arg);
00058 
00059 extern NSSBase64Encoder *
00060 NSSBase64Encoder_Create (PRInt32 (*output_fn) (void *, const char *, PRInt32),
00061                       void *output_arg);
00062 
00063 /*
00064  * Push data through the decoder/encoder, causing the output_fn (provided
00065  * to Create) to be called with the decoded/encoded data.
00066  */
00067 
00068 extern SECStatus
00069 NSSBase64Decoder_Update (NSSBase64Decoder *data, const char *buffer,
00070                       PRUint32 size);
00071 
00072 extern SECStatus
00073 NSSBase64Encoder_Update (NSSBase64Encoder *data, const unsigned char *buffer,
00074                       PRUint32 size);
00075 
00076 /*
00077  * When you're done processing, call this to close the context.
00078  * If "abort_p" is false, then calling this may cause the output_fn
00079  * to be called one last time (as the last buffered data is flushed out).
00080  */
00081 
00082 extern SECStatus
00083 NSSBase64Decoder_Destroy (NSSBase64Decoder *data, PRBool abort_p);
00084 
00085 extern SECStatus
00086 NSSBase64Encoder_Destroy (NSSBase64Encoder *data, PRBool abort_p);
00087 
00088 /*
00089  * Perform base64 decoding from an ascii string "inStr" to an Item.
00090  * The length of the input must be provided as "inLen".  The Item
00091  * may be provided (as "outItemOpt"); you can also pass in a NULL
00092  * and the Item will be allocated for you.
00093  *
00094  * In any case, the data within the Item will be allocated for you.
00095  * All allocation will happen out of the passed-in "arenaOpt", if non-NULL.
00096  * If "arenaOpt" is NULL, standard allocation (heap) will be used and
00097  * you will want to free the result via SECITEM_FreeItem.
00098  *
00099  * Return value is NULL on error, the Item (allocated or provided) otherwise.
00100  */
00101 extern SECItem *
00102 NSSBase64_DecodeBuffer (PRArenaPool *arenaOpt, SECItem *outItemOpt,
00103                      const char *inStr, unsigned int inLen);
00104 
00105 /*
00106  * Perform base64 encoding of binary data "inItem" to an ascii string.
00107  * The output buffer may be provided (as "outStrOpt"); you can also pass
00108  * in a NULL and the buffer will be allocated for you.  The result will
00109  * be null-terminated, and if the buffer is provided, "maxOutLen" must
00110  * specify the maximum length of the buffer and will be checked to
00111  * supply sufficient space space for the encoded result.  (If "outStrOpt"
00112  * is NULL, "maxOutLen" is ignored.)
00113  *
00114  * If "outStrOpt" is NULL, allocation will happen out of the passed-in
00115  * "arenaOpt", if *it* is non-NULL, otherwise standard allocation (heap)
00116  * will be used.
00117  *
00118  * Return value is NULL on error, the output buffer (allocated or provided)
00119  * otherwise.
00120  */
00121 extern char *
00122 NSSBase64_EncodeItem (PRArenaPool *arenaOpt, char *outStrOpt,
00123                     unsigned int maxOutLen, SECItem *inItem);
00124 
00125 SEC_END_PROTOS
00126 
00127 #endif /* _NSSB64_H_ */