Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef _plbase64_h |
michael@0 | 7 | #define _plbase64_h |
michael@0 | 8 | |
michael@0 | 9 | #include "prtypes.h" |
michael@0 | 10 | |
michael@0 | 11 | PR_BEGIN_EXTERN_C |
michael@0 | 12 | |
michael@0 | 13 | /* |
michael@0 | 14 | * PL_Base64Encode |
michael@0 | 15 | * |
michael@0 | 16 | * This routine encodes the data pointed to by the "src" parameter using the |
michael@0 | 17 | * base64 algorithm, and returns a pointer to the result. If the "srclen" |
michael@0 | 18 | * parameter is not zero, it specifies the length of the source data. If it |
michael@0 | 19 | * is zero, the source data is assumed to be null-terminated, and PL_strlen |
michael@0 | 20 | * is used to determine the source length. If the "dest" parameter is not |
michael@0 | 21 | * null, it is assumed to point to a buffer of sufficient size (which may be |
michael@0 | 22 | * calculated: ((srclen + 2)/3)*4) into which the encoded data is placed |
michael@0 | 23 | * (without any termination). If the "dest" parameter is null, a buffer is |
michael@0 | 24 | * allocated from the heap to hold the encoded data, and the result *will* |
michael@0 | 25 | * be terminated with an extra null character. It is the caller's |
michael@0 | 26 | * responsibility to free the result when it is allocated. A null is returned |
michael@0 | 27 | * if the allocation fails. |
michael@0 | 28 | * |
michael@0 | 29 | * NOTE: when calculating ((srclen + 2)/3)*4), first ensure that |
michael@0 | 30 | * srclen <= (PR_UINT32_MAX/4) * 3 |
michael@0 | 31 | * to avoid PRUint32 overflow. |
michael@0 | 32 | */ |
michael@0 | 33 | |
michael@0 | 34 | PR_EXTERN(char *) |
michael@0 | 35 | PL_Base64Encode |
michael@0 | 36 | ( |
michael@0 | 37 | const char *src, |
michael@0 | 38 | PRUint32 srclen, |
michael@0 | 39 | char *dest |
michael@0 | 40 | ); |
michael@0 | 41 | |
michael@0 | 42 | /* |
michael@0 | 43 | * PL_Base64Decode |
michael@0 | 44 | * |
michael@0 | 45 | * This routine decodes the data pointed to by the "src" parameter using |
michael@0 | 46 | * the base64 algorithm, and returns a pointer to the result. The source |
michael@0 | 47 | * may either include or exclude any trailing '=' characters. If the |
michael@0 | 48 | * "srclen" parameter is not zero, it specifies the length of the source |
michael@0 | 49 | * data. If it is zero, PL_strlen will be used to determine the source |
michael@0 | 50 | * length. If the "dest" parameter is not null, it is assumed to point to |
michael@0 | 51 | * a buffer of sufficient size (which may be calculated: (srclen * 3)/4 |
michael@0 | 52 | * when srclen includes the '=' characters) into which the decoded data |
michael@0 | 53 | * is placed (without any termination). If the "dest" parameter is null, |
michael@0 | 54 | * a buffer is allocated from the heap to hold the decoded data, and the |
michael@0 | 55 | * result *will* be terminated with an extra null character. It is the |
michael@0 | 56 | * caller's responsibility to free the result when it is allocated. A null |
michael@0 | 57 | * is retuned if the allocation fails, or if the source is not well-coded. |
michael@0 | 58 | * |
michael@0 | 59 | * NOTE: when calculating (srclen * 3)/4, first ensure that |
michael@0 | 60 | * srclen <= PR_UINT32_MAX/3 |
michael@0 | 61 | * to avoid PRUint32 overflow. Alternatively, calculate |
michael@0 | 62 | * (srclen/4) * 3 + ((srclen%4) * 3)/4 |
michael@0 | 63 | * which is equivalent but doesn't overflow for any value of srclen. |
michael@0 | 64 | */ |
michael@0 | 65 | |
michael@0 | 66 | PR_EXTERN(char *) |
michael@0 | 67 | PL_Base64Decode |
michael@0 | 68 | ( |
michael@0 | 69 | const char *src, |
michael@0 | 70 | PRUint32 srclen, |
michael@0 | 71 | char *dest |
michael@0 | 72 | ); |
michael@0 | 73 | |
michael@0 | 74 | PR_END_EXTERN_C |
michael@0 | 75 | |
michael@0 | 76 | #endif /* _plbase64_h */ |