| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org> | 2 * Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org> |
| 3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> | 3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #ifndef Base64_h | 27 #ifndef Base64_h |
| 28 #define Base64_h | 28 #define Base64_h |
| 29 | 29 |
| 30 #include "wtf/Vector.h" | 30 #include "wtf/Vector.h" |
| 31 #include "wtf/WTFExport.h" | 31 #include "wtf/WTFExport.h" |
| 32 #include "wtf/text/CString.h" | 32 #include "wtf/text/CString.h" |
| 33 #include "wtf/text/WTFString.h" | 33 #include "wtf/text/WTFString.h" |
| 34 | 34 |
| 35 namespace WTF { | 35 namespace WTF { |
| 36 | 36 |
| 37 enum Base64EncodePolicy { | 37 enum Base64EncodePolicy { Base64DoNotInsertLFs, Base64InsertLFs }; |
| 38 Base64DoNotInsertLFs, | |
| 39 Base64InsertLFs | |
| 40 }; | |
| 41 | 38 |
| 42 enum Base64DecodePolicy { | 39 enum Base64DecodePolicy { Base64DoNotValidatePadding, Base64ValidatePadding }; |
| 43 Base64DoNotValidatePadding, | |
| 44 Base64ValidatePadding | |
| 45 }; | |
| 46 | 40 |
| 47 WTF_EXPORT void base64Encode(const char*, unsigned, Vector<char>&, Base64EncodeP
olicy = Base64DoNotInsertLFs); | 41 WTF_EXPORT void base64Encode(const char*, |
| 48 WTF_EXPORT void base64Encode(const Vector<char>&, Vector<char>&, Base64EncodePol
icy = Base64DoNotInsertLFs); | 42 unsigned, |
| 49 WTF_EXPORT void base64Encode(const CString&, Vector<char>&, Base64EncodePolicy =
Base64DoNotInsertLFs); | 43 Vector<char>&, |
| 50 WTF_EXPORT String base64Encode(const char*, unsigned, Base64EncodePolicy = Base6
4DoNotInsertLFs); | 44 Base64EncodePolicy = Base64DoNotInsertLFs); |
| 51 WTF_EXPORT String base64Encode(const Vector<char>&, Base64EncodePolicy = Base64D
oNotInsertLFs); | 45 WTF_EXPORT void base64Encode(const Vector<char>&, |
| 52 WTF_EXPORT String base64Encode(const Vector<unsigned char>&, Base64EncodePolicy
= Base64DoNotInsertLFs); | 46 Vector<char>&, |
| 53 WTF_EXPORT String base64Encode(const CString&, Base64EncodePolicy = Base64DoNotI
nsertLFs); | 47 Base64EncodePolicy = Base64DoNotInsertLFs); |
| 48 WTF_EXPORT void base64Encode(const CString&, |
| 49 Vector<char>&, |
| 50 Base64EncodePolicy = Base64DoNotInsertLFs); |
| 51 WTF_EXPORT String base64Encode(const char*, |
| 52 unsigned, |
| 53 Base64EncodePolicy = Base64DoNotInsertLFs); |
| 54 WTF_EXPORT String base64Encode(const Vector<char>&, |
| 55 Base64EncodePolicy = Base64DoNotInsertLFs); |
| 56 WTF_EXPORT String base64Encode(const Vector<unsigned char>&, |
| 57 Base64EncodePolicy = Base64DoNotInsertLFs); |
| 58 WTF_EXPORT String base64Encode(const CString&, |
| 59 Base64EncodePolicy = Base64DoNotInsertLFs); |
| 54 | 60 |
| 55 WTF_EXPORT bool base64Decode(const String&, Vector<char>&, CharacterMatchFunctio
nPtr shouldIgnoreCharacter = 0, Base64DecodePolicy = Base64DoNotValidatePadding)
; | 61 WTF_EXPORT bool base64Decode( |
| 56 WTF_EXPORT bool base64Decode(const Vector<char>&, Vector<char>&, CharacterMatchF
unctionPtr shouldIgnoreCharacter = 0, Base64DecodePolicy = Base64DoNotValidatePa
dding); | 62 const String&, |
| 57 WTF_EXPORT bool base64Decode(const char*, unsigned, Vector<char>&, CharacterMatc
hFunctionPtr shouldIgnoreCharacter = 0, Base64DecodePolicy = Base64DoNotValidate
Padding); | 63 Vector<char>&, |
| 58 WTF_EXPORT bool base64Decode(const UChar*, unsigned, Vector<char>&, CharacterMat
chFunctionPtr shouldIgnoreCharacter = 0, Base64DecodePolicy = Base64DoNotValidat
ePadding); | 64 CharacterMatchFunctionPtr shouldIgnoreCharacter = 0, |
| 65 Base64DecodePolicy = Base64DoNotValidatePadding); |
| 66 WTF_EXPORT bool base64Decode( |
| 67 const Vector<char>&, |
| 68 Vector<char>&, |
| 69 CharacterMatchFunctionPtr shouldIgnoreCharacter = 0, |
| 70 Base64DecodePolicy = Base64DoNotValidatePadding); |
| 71 WTF_EXPORT bool base64Decode( |
| 72 const char*, |
| 73 unsigned, |
| 74 Vector<char>&, |
| 75 CharacterMatchFunctionPtr shouldIgnoreCharacter = 0, |
| 76 Base64DecodePolicy = Base64DoNotValidatePadding); |
| 77 WTF_EXPORT bool base64Decode( |
| 78 const UChar*, |
| 79 unsigned, |
| 80 Vector<char>&, |
| 81 CharacterMatchFunctionPtr shouldIgnoreCharacter = 0, |
| 82 Base64DecodePolicy = Base64DoNotValidatePadding); |
| 59 | 83 |
| 60 // Given an encoding in either base64 or base64url, returns a normalized | 84 // Given an encoding in either base64 or base64url, returns a normalized |
| 61 // encoding in plain base64. | 85 // encoding in plain base64. |
| 62 WTF_EXPORT String normalizeToBase64(const String&); | 86 WTF_EXPORT String normalizeToBase64(const String&); |
| 63 | 87 |
| 64 WTF_EXPORT String base64URLEncode(const char*, unsigned, Base64EncodePolicy = Ba
se64DoNotInsertLFs); | 88 WTF_EXPORT String base64URLEncode(const char*, |
| 89 unsigned, |
| 90 Base64EncodePolicy = Base64DoNotInsertLFs); |
| 65 | 91 |
| 66 inline void base64Encode(const Vector<char>& in, Vector<char>& out, Base64Encode
Policy policy) | 92 inline void base64Encode(const Vector<char>& in, |
| 67 { | 93 Vector<char>& out, |
| 68 base64Encode(in.data(), in.size(), out, policy); | 94 Base64EncodePolicy policy) { |
| 95 base64Encode(in.data(), in.size(), out, policy); |
| 69 } | 96 } |
| 70 | 97 |
| 71 inline void base64Encode(const CString& in, Vector<char>& out, Base64EncodePolic
y policy) | 98 inline void base64Encode(const CString& in, |
| 72 { | 99 Vector<char>& out, |
| 73 base64Encode(in.data(), in.length(), out, policy); | 100 Base64EncodePolicy policy) { |
| 101 base64Encode(in.data(), in.length(), out, policy); |
| 74 } | 102 } |
| 75 | 103 |
| 76 inline String base64Encode(const Vector<char>& in, Base64EncodePolicy policy) | 104 inline String base64Encode(const Vector<char>& in, Base64EncodePolicy policy) { |
| 77 { | 105 return base64Encode(in.data(), in.size(), policy); |
| 78 return base64Encode(in.data(), in.size(), policy); | |
| 79 } | 106 } |
| 80 | 107 |
| 81 inline String base64Encode(const Vector<unsigned char>& in, Base64EncodePolicy p
olicy) | 108 inline String base64Encode(const Vector<unsigned char>& in, |
| 82 { | 109 Base64EncodePolicy policy) { |
| 83 return base64Encode(reinterpret_cast<const char*>(in.data()), in.size(), pol
icy); | 110 return base64Encode(reinterpret_cast<const char*>(in.data()), in.size(), |
| 111 policy); |
| 84 } | 112 } |
| 85 | 113 |
| 86 inline String base64Encode(const CString& in, Base64EncodePolicy policy) | 114 inline String base64Encode(const CString& in, Base64EncodePolicy policy) { |
| 87 { | 115 return base64Encode(in.data(), in.length(), policy); |
| 88 return base64Encode(in.data(), in.length(), policy); | |
| 89 } | 116 } |
| 90 | 117 |
| 91 } // namespace WTF | 118 } // namespace WTF |
| 92 | 119 |
| 93 using WTF::Base64EncodePolicy; | 120 using WTF::Base64EncodePolicy; |
| 94 using WTF::Base64DoNotInsertLFs; | 121 using WTF::Base64DoNotInsertLFs; |
| 95 using WTF::Base64InsertLFs; | 122 using WTF::Base64InsertLFs; |
| 96 using WTF::Base64DecodePolicy; | 123 using WTF::Base64DecodePolicy; |
| 97 using WTF::Base64DoNotValidatePadding; | 124 using WTF::Base64DoNotValidatePadding; |
| 98 using WTF::Base64ValidatePadding; | 125 using WTF::Base64ValidatePadding; |
| 99 using WTF::base64Encode; | 126 using WTF::base64Encode; |
| 100 using WTF::base64Decode; | 127 using WTF::base64Decode; |
| 101 | 128 |
| 102 #endif // Base64_h | 129 #endif // Base64_h |
| OLD | NEW |