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 |
|
---|
38 | #ifndef _plbase64_h
|
---|
39 | #define _plbase64_h
|
---|
40 |
|
---|
41 | #include "prtypes.h"
|
---|
42 |
|
---|
43 | #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
|
---|
44 | #define PL_Base64Decode VBoxNsplPL_Base64Decode
|
---|
45 | #define PL_Base64Encode VBoxNsplPL_Base64Encode
|
---|
46 | #endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
|
---|
47 |
|
---|
48 | PR_BEGIN_EXTERN_C
|
---|
49 |
|
---|
50 | /*
|
---|
51 | * PL_Base64Encode
|
---|
52 | *
|
---|
53 | * This routine encodes the data pointed to by the "src" parameter using the
|
---|
54 | * base64 algorithm, and returns a pointer to the result. If the "srclen"
|
---|
55 | * parameter is not zero, it specifies the length of the source data. If it
|
---|
56 | * is zero, the source data is assumed to be null-terminated, and PL_strlen
|
---|
57 | * is used to determine the source length. If the "dest" parameter is not
|
---|
58 | * null, it is assumed to point to a buffer of sufficient size (which may be
|
---|
59 | * calculated: ((srclen + 2)/3)*4) into which the encoded data is placed
|
---|
60 | * (without any termination). If the "dest" parameter is null, a buffer is
|
---|
61 | * allocated from the heap to hold the encoded data, and the result *will*
|
---|
62 | * be terminated with an extra null character. It is the caller's
|
---|
63 | * responsibility to free the result when it is allocated. A null is returned
|
---|
64 | * if the allocation fails.
|
---|
65 | */
|
---|
66 |
|
---|
67 | PR_EXTERN(char *)
|
---|
68 | PL_Base64Encode
|
---|
69 | (
|
---|
70 | const char *src,
|
---|
71 | PRUint32 srclen,
|
---|
72 | char *dest
|
---|
73 | );
|
---|
74 |
|
---|
75 | /*
|
---|
76 | * PL_Base64Decode
|
---|
77 | *
|
---|
78 | * This routine decodes the data pointed to by the "src" parameter using
|
---|
79 | * the base64 algorithm, and returns a pointer to the result. The source
|
---|
80 | * may either include or exclude any trailing '=' characters. If the
|
---|
81 | * "srclen" parameter is not zero, it specifies the length of the source
|
---|
82 | * data. If it is zero, PL_strlen will be used to determine the source
|
---|
83 | * length. If the "dest" parameter is not null, it is assumed to point to
|
---|
84 | * a buffer of sufficient size (which may be calculated: (srclen * 3)/4
|
---|
85 | * when srclen includes the '=' characters) into which the decoded data
|
---|
86 | * is placed (without any termination). If the "dest" parameter is null,
|
---|
87 | * a buffer is allocated from the heap to hold the decoded data, and the
|
---|
88 | * result *will* be terminated with an extra null character. It is the
|
---|
89 | * caller's responsibility to free the result when it is allocated. A null
|
---|
90 | * is retuned if the allocation fails, or if the source is not well-coded.
|
---|
91 | */
|
---|
92 |
|
---|
93 | PR_EXTERN(char *)
|
---|
94 | PL_Base64Decode
|
---|
95 | (
|
---|
96 | const char *src,
|
---|
97 | PRUint32 srclen,
|
---|
98 | char *dest
|
---|
99 | );
|
---|
100 |
|
---|
101 | PR_END_EXTERN_C
|
---|
102 |
|
---|
103 | #endif /* _plbase64_h */
|
---|