Back to index

lightning-sunbird  0.9+nobinonly
plbase64.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _plbase64_h
00039 #define _plbase64_h
00040 
00041 #include "prtypes.h"
00042 
00043 PR_BEGIN_EXTERN_C
00044 
00045 /*
00046  * PL_Base64Encode
00047  *
00048  * This routine encodes the data pointed to by the "src" parameter using the
00049  * base64 algorithm, and returns a pointer to the result.  If the "srclen"
00050  * parameter is not zero, it specifies the length of the source data.  If it
00051  * is zero, the source data is assumed to be null-terminated, and PL_strlen
00052  * is used to determine the source length.  If the "dest" parameter is not
00053  * null, it is assumed to point to a buffer of sufficient size (which may be
00054  * calculated: ((srclen + 2)/3)*4) into which the encoded data is placed 
00055  * (without any termination).  If the "dest" parameter is null, a buffer is
00056  * allocated from the heap to hold the encoded data, and the result *will*
00057  * be terminated with an extra null character.  It is the caller's 
00058  * responsibility to free the result when it is allocated.  A null is returned 
00059  * if the allocation fails.
00060  */
00061 
00062 PR_EXTERN(char *)
00063 PL_Base64Encode
00064 (
00065     const char *src,
00066     PRUint32    srclen,
00067     char       *dest
00068 );
00069 
00070 /*
00071  * PL_Base64Decode
00072  *
00073  * This routine decodes the data pointed to by the "src" parameter using
00074  * the base64 algorithm, and returns a pointer to the result.  The source
00075  * may either include or exclude any trailing '=' characters.  If the
00076  * "srclen" parameter is not zero, it specifies the length of the source
00077  * data.  If it is zero, PL_strlen will be used to determine the source
00078  * length.  If the "dest" parameter is not null, it is assumed to point to
00079  * a buffer of sufficient size (which may be calculated: (srclen * 3)/4
00080  * when srclen includes the '=' characters) into which the decoded data
00081  * is placed (without any termination).  If the "dest" parameter is null,
00082  * a buffer is allocated from the heap to hold the decoded data, and the
00083  * result *will* be terminated with an extra null character.  It is the
00084  * caller's responsibility to free the result when it is allocated.  A null
00085  * is retuned if the allocation fails, or if the source is not well-coded.
00086  */
00087 
00088 PR_EXTERN(char *)
00089 PL_Base64Decode
00090 (
00091     const char *src,
00092     PRUint32    srclen,
00093     char       *dest
00094 );
00095 
00096 PR_END_EXTERN_C
00097 
00098 #endif /* _plbase64_h */