home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / lib / libc / include / plbase64.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.0 KB  |  80 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef _plbase64_h
  20. #define _plbase64_h
  21.  
  22. #include "prtypes.h"
  23.  
  24. PR_BEGIN_EXTERN_C
  25.  
  26. /*
  27.  * PL_Base64Encode
  28.  *
  29.  * This routine encodes the data pointed to by the "src" parameter using the
  30.  * base64 algorithm, and returns a pointer to the result.  If the "srclen"
  31.  * parameter is not zero, it specifies the length of the source data.  If it
  32.  * is zero, the source data is assumed to be null-terminated, and PL_strlen
  33.  * is used to determine the source length.  If the "dest" parameter is not
  34.  * null, it is assumed to point to a buffer of sufficient size (which may be
  35.  * calculated: ((srclen + 2)/3)*4) into which the encoded data is placed 
  36.  * (without any termination).  If the "dest" parameter is null, a buffer is
  37.  * allocated from the heap to hold the encoded data, and the result *will*
  38.  * be terminated with an extra null character.  It is the caller's 
  39.  * responsibility to free the result when it is allocated.  A null is returned 
  40.  * if the allocation fails.
  41.  */
  42.  
  43. PR_EXTERN(char *)
  44. PL_Base64Encode
  45. (
  46.     const char *src,
  47.     PRUint32    srclen,
  48.     char       *dest
  49. );
  50.  
  51. /*
  52.  * PL_Base64Decode
  53.  *
  54.  * This routine decodes the data pointed to by the "src" parameter using
  55.  * the base64 algorithm, and returns a pointer to the result.  The source
  56.  * may either include or exclude any trailing '=' characters.  If the
  57.  * "srclen" parameter is not zero, it specifies the length of the source
  58.  * data.  If it is zero, PL_strlen will be used to determine the source
  59.  * length.  If the "dest" parameter is not null, it is assumed to point to
  60.  * a buffer of sufficient size (which may be calculated: (srclen * 3)/4
  61.  * when srclen includes the '=' characters) into which the decoded data
  62.  * is placed (without any termination).  If the "dest" parameter is null,
  63.  * a buffer is allocated from the heap to hold the decoded data, and the
  64.  * result *will* be terminated with an extra null character.  It is the
  65.  * caller's responsibility to free the result when it is allocated.  A null
  66.  * is retuned if the allocation fails, or if the source is not well-coded.
  67.  */
  68.  
  69. PR_EXTERN(char *)
  70. PL_Base64Decode
  71. (
  72.     const char *src,
  73.     PRUint32    srclen,
  74.     char       *dest
  75. );
  76.  
  77. PR_END_EXTERN_C
  78.  
  79. #endif /* _plbase64_h */
  80.