Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: Source/wtf/text/Base64.h

Issue 19623002: Make atob() throw an InvalidCharacterError on excess padding characters (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/page/DOMWindowBase64.cpp ('k') | Source/wtf/text/Base64.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 21 matching lines...) Expand all
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 {
38 Base64DoNotInsertLFs, 38 Base64DoNotInsertLFs,
39 Base64InsertLFs 39 Base64InsertLFs
40 }; 40 };
41 41
42 enum Base64DecodePolicy { 42 enum Base64InvalidCharactersPolicy {
43 Base64FailOnInvalidCharacter, 43 Base64FailOnInvalidCharacter,
44 Base64IgnoreWhitespace, 44 Base64IgnoreWhitespace,
45 Base64IgnoreInvalidCharacters 45 Base64IgnoreInvalidCharacters
46 }; 46 };
47 47
48 enum Base64PaddingValidationPolicy {
49 Base64NoPaddingValidation,
50 Base64StrictPaddingValidation
51 };
52
48 WTF_EXPORT void base64Encode(const char*, unsigned, Vector<char>&, Base64EncodeP olicy = Base64DoNotInsertLFs); 53 WTF_EXPORT void base64Encode(const char*, unsigned, Vector<char>&, Base64EncodeP olicy = Base64DoNotInsertLFs);
49 WTF_EXPORT void base64Encode(const Vector<char>&, Vector<char>&, Base64EncodePol icy = Base64DoNotInsertLFs); 54 WTF_EXPORT void base64Encode(const Vector<char>&, Vector<char>&, Base64EncodePol icy = Base64DoNotInsertLFs);
50 WTF_EXPORT void base64Encode(const CString&, Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs); 55 WTF_EXPORT void base64Encode(const CString&, Vector<char>&, Base64EncodePolicy = Base64DoNotInsertLFs);
51 WTF_EXPORT String base64Encode(const char*, unsigned, Base64EncodePolicy = Base6 4DoNotInsertLFs); 56 WTF_EXPORT String base64Encode(const char*, unsigned, Base64EncodePolicy = Base6 4DoNotInsertLFs);
52 WTF_EXPORT String base64Encode(const Vector<char>&, Base64EncodePolicy = Base64D oNotInsertLFs); 57 WTF_EXPORT String base64Encode(const Vector<char>&, Base64EncodePolicy = Base64D oNotInsertLFs);
53 WTF_EXPORT String base64Encode(const CString&, Base64EncodePolicy = Base64DoNotI nsertLFs); 58 WTF_EXPORT String base64Encode(const CString&, Base64EncodePolicy = Base64DoNotI nsertLFs);
54 59
55 WTF_EXPORT bool base64Decode(const String&, Vector<char>&, Base64DecodePolicy = Base64FailOnInvalidCharacter); 60 WTF_EXPORT bool base64Decode(const String&, Vector<char>&, Base64InvalidCharacte rsPolicy = Base64FailOnInvalidCharacter, Base64PaddingValidationPolicy = Base64N oPaddingValidation);
56 WTF_EXPORT bool base64Decode(const Vector<char>&, Vector<char>&, Base64DecodePol icy = Base64FailOnInvalidCharacter); 61 WTF_EXPORT bool base64Decode(const Vector<char>&, Vector<char>&, Base64InvalidCh aractersPolicy = Base64FailOnInvalidCharacter, Base64PaddingValidationPolicy = B ase64NoPaddingValidation);
57 WTF_EXPORT bool base64Decode(const char*, unsigned, Vector<char>&, Base64DecodeP olicy = Base64FailOnInvalidCharacter); 62 WTF_EXPORT bool base64Decode(const char*, unsigned, Vector<char>&, Base64Invalid CharactersPolicy = Base64FailOnInvalidCharacter, Base64PaddingValidationPolicy = Base64NoPaddingValidation);
58 63
59 inline void base64Encode(const Vector<char>& in, Vector<char>& out, Base64Encode Policy policy) 64 inline void base64Encode(const Vector<char>& in, Vector<char>& out, Base64Encode Policy policy)
60 { 65 {
61 base64Encode(in.data(), in.size(), out, policy); 66 base64Encode(in.data(), in.size(), out, policy);
62 } 67 }
63 68
64 inline void base64Encode(const CString& in, Vector<char>& out, Base64EncodePolic y policy) 69 inline void base64Encode(const CString& in, Vector<char>& out, Base64EncodePolic y policy)
65 { 70 {
66 base64Encode(in.data(), in.length(), out, policy); 71 base64Encode(in.data(), in.length(), out, policy);
67 } 72 }
68 73
69 inline String base64Encode(const Vector<char>& in, Base64EncodePolicy policy) 74 inline String base64Encode(const Vector<char>& in, Base64EncodePolicy policy)
70 { 75 {
71 return base64Encode(in.data(), in.size(), policy); 76 return base64Encode(in.data(), in.size(), policy);
72 } 77 }
73 78
74 inline String base64Encode(const CString& in, Base64EncodePolicy policy) 79 inline String base64Encode(const CString& in, Base64EncodePolicy policy)
75 { 80 {
76 return base64Encode(in.data(), in.length(), policy); 81 return base64Encode(in.data(), in.length(), policy);
77 } 82 }
78 83
79 } // namespace WTF 84 } // namespace WTF
80 85
81 using WTF::Base64EncodePolicy; 86 using WTF::Base64EncodePolicy;
82 using WTF::Base64DoNotInsertLFs; 87 using WTF::Base64DoNotInsertLFs;
83 using WTF::Base64InsertLFs; 88 using WTF::Base64InsertLFs;
84 using WTF::Base64DecodePolicy; 89 using WTF::Base64InvalidCharactersPolicy;
85 using WTF::Base64FailOnInvalidCharacter; 90 using WTF::Base64FailOnInvalidCharacter;
86 using WTF::Base64IgnoreWhitespace; 91 using WTF::Base64IgnoreWhitespace;
87 using WTF::Base64IgnoreInvalidCharacters; 92 using WTF::Base64IgnoreInvalidCharacters;
93 using WTF::Base64PaddingValidationPolicy;
94 using WTF::Base64NoPaddingValidation;
95 using WTF::Base64StrictPaddingValidation;
88 using WTF::base64Encode; 96 using WTF::base64Encode;
89 using WTF::base64Decode; 97 using WTF::base64Decode;
90 98
91 #endif // Base64_h 99 #endif // Base64_h
OLDNEW
« no previous file with comments | « Source/core/page/DOMWindowBase64.cpp ('k') | Source/wtf/text/Base64.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698