plbase64.h 3.9 KB

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