From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WTF/wtf/text/Base64.cpp | 76 +++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 26 deletions(-) (limited to 'Source/WTF/wtf/text/Base64.cpp') diff --git a/Source/WTF/wtf/text/Base64.cpp b/Source/WTF/wtf/text/Base64.cpp index 2323f3fa3..714a7ead4 100644 --- a/Source/WTF/wtf/text/Base64.cpp +++ b/Source/WTF/wtf/text/Base64.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2000-2001 Dawit Alemayehu Copyright (C) 2006 Alexey Proskuryakov - Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. + Copyright (C) 2007, 2008, 2013, 2016 Apple Inc. All rights reserved. Copyright (C) 2010 Patrick Gansterer This program is free software; you can redistribute it and/or modify @@ -92,7 +92,7 @@ static const char base64URLDecMap[128] = { 0x31, 0x32, 0x33, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet }; -static inline void base64EncodeInternal(const char* data, unsigned len, Vector& out, Base64EncodePolicy policy, const char (&encodeMap)[64]) +static inline void base64EncodeInternal(const unsigned char* data, unsigned len, Vector& out, Base64EncodePolicy policy, const char (&encodeMap)[64]) { out.clear(); if (!len) @@ -160,29 +160,29 @@ static inline void base64EncodeInternal(const char* data, unsigned len, Vector result; - base64EncodeInternal(static_cast(data), length, result, policy, base64EncMap); + base64EncodeInternal(static_cast(data), length, result, policy, base64EncMap); return String(result.data(), result.size()); } void base64Encode(const void* data, unsigned len, Vector& out, Base64EncodePolicy policy) { - base64EncodeInternal(static_cast(data), len, out, policy, base64EncMap); + base64EncodeInternal(static_cast(data), len, out, policy, base64EncMap); } String base64URLEncode(const void* data, unsigned length) { Vector result; - base64EncodeInternal(static_cast(data), length, result, Base64URLPolicy, base64URLEncMap); + base64EncodeInternal(static_cast(data), length, result, Base64URLPolicy, base64URLEncMap); return String(result.data(), result.size()); } void base64URLEncode(const void* data, unsigned len, Vector& out) { - base64EncodeInternal(static_cast(data), len, out, Base64URLPolicy, base64URLEncMap); + base64EncodeInternal(static_cast(data), len, out, Base64URLPolicy, base64URLEncMap); } template -static inline bool base64DecodeInternal(const T* data, unsigned length, Vector& out, Base64DecodePolicy policy, const char (&decodeMap)[128]) +static inline bool base64DecodeInternal(const T* data, unsigned length, SignedOrUnsignedCharVectorAdapter& out, unsigned options, const char (&decodeMap)[128]) { out.clear(); if (!length) @@ -192,29 +192,47 @@ static inline bool base64DecodeInternal(const T* data, unsigned length, Vector(in.deprecatedCharacters(), in.length(), out, policy, base64DecMap); + unsigned length = in.length(); + if (!length || in.is8Bit()) + return base64DecodeInternal(in.characters8(), length, out, options, base64DecMap); + return base64DecodeInternal(in.characters16(), length, out, options, base64DecMap); } -bool base64Decode(const Vector& in, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy) +bool base64Decode(const Vector& in, SignedOrUnsignedCharVectorAdapter out, unsigned options) { out.clear(); @@ -261,17 +282,20 @@ bool base64Decode(const Vector& in, SignedOrUnsignedCharVectorAdapter out, if (in.size() > UINT_MAX) return false; - return base64DecodeInternal(in.data(), in.size(), out, policy, base64DecMap); + return base64DecodeInternal(reinterpret_cast(in.data()), in.size(), out, options, base64DecMap); } -bool base64Decode(const char* data, unsigned len, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy) +bool base64Decode(const char* data, unsigned len, SignedOrUnsignedCharVectorAdapter out, unsigned options) { - return base64DecodeInternal(data, len, out, policy, base64DecMap); + return base64DecodeInternal(reinterpret_cast(data), len, out, options, base64DecMap); } bool base64URLDecode(const String& in, SignedOrUnsignedCharVectorAdapter out) { - return base64DecodeInternal(in.deprecatedCharacters(), in.length(), out, Base64FailOnInvalidCharacter, base64URLDecMap); + unsigned length = in.length(); + if (!length || in.is8Bit()) + return base64DecodeInternal(in.characters8(), length, out, Base64Default, base64URLDecMap); + return base64DecodeInternal(in.characters16(), length, out, Base64Default, base64URLDecMap); } bool base64URLDecode(const Vector& in, SignedOrUnsignedCharVectorAdapter out) @@ -282,12 +306,12 @@ bool base64URLDecode(const Vector& in, SignedOrUnsignedCharVectorAdapter o if (in.size() > UINT_MAX) return false; - return base64DecodeInternal(in.data(), in.size(), out, Base64FailOnInvalidCharacter, base64URLDecMap); + return base64DecodeInternal(reinterpret_cast(in.data()), in.size(), out, Base64Default, base64URLDecMap); } bool base64URLDecode(const char* data, unsigned len, SignedOrUnsignedCharVectorAdapter out) { - return base64DecodeInternal(data, len, out, Base64FailOnInvalidCharacter, base64URLDecMap); + return base64DecodeInternal(reinterpret_cast(data), len, out, Base64Default, base64URLDecMap); } } // namespace WTF -- cgit v1.2.1