Changeset 220954 in webkit
- Timestamp:
- Aug 19, 2017 10:28:59 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r220953 r220954 1 2017-08-19 Sam Weinig <sam@webkit.org> 2 3 [WebCrypto] Remove the KeyAlgorithm type hierarchy 4 https://bugs.webkit.org/show_bug.cgi?id=175750 5 6 Reviewed by Chris Dumez. 7 8 Removes the unnecessary indirection that existed to generate a 9 KeyAlgorithm dictionary (or rather, one of its derived dictionaries) 10 for a CryptoKey. We were calling the virtual buildAlgorithm(), which 11 return a std::unique_ptr<KeyAlgorithm>, which we then casted to the 12 correct derived class and called dictionary() on. This can now be 13 simplified by making each CryptoKey derived class override a function 14 that returns the KeyAlgorithm variant. 15 16 * crypto/CryptoKey.cpp: 17 (WebCore::CryptoKey::algorithm const): Deleted. 18 * crypto/CryptoKey.h: 19 (WebCore::CryptoKey::extractable const): 20 (WebCore::KeyAlgorithm::~KeyAlgorithm): Deleted. 21 (WebCore::KeyAlgorithm::name const): Deleted. 22 (WebCore::KeyAlgorithm::KeyAlgorithm): Deleted. 23 * crypto/gcrypt/CryptoKeyRSAGCrypt.cpp: 24 (WebCore::CryptoKeyRSA::algorithm const): 25 (WebCore::CryptoKeyRSA::buildAlgorithm const): Deleted. 26 * crypto/keys/CryptoKeyAES.cpp: 27 (WebCore::CryptoKeyAES::algorithm const): 28 (WebCore::AesKeyAlgorithm::dictionary const): Deleted. 29 (WebCore::CryptoKeyAES::buildAlgorithm const): Deleted. 30 * crypto/keys/CryptoKeyAES.h: 31 * crypto/keys/CryptoKeyEC.cpp: 32 (WebCore::CryptoKeyEC::algorithm const): 33 (WebCore::EcKeyAlgorithm::dictionary const): Deleted. 34 (WebCore::CryptoKeyEC::buildAlgorithm const): Deleted. 35 * crypto/keys/CryptoKeyEC.h: 36 (WebCore::EcKeyAlgorithm::EcKeyAlgorithm): Deleted. 37 (WebCore::EcKeyAlgorithm::namedCurve const): Deleted. 38 * crypto/keys/CryptoKeyHMAC.cpp: 39 (WebCore::CryptoKeyHMAC::algorithm const): 40 (WebCore::HmacKeyAlgorithm::dictionary const): Deleted. 41 (WebCore::CryptoKeyHMAC::buildAlgorithm const): Deleted. 42 * crypto/keys/CryptoKeyHMAC.h: 43 * crypto/keys/CryptoKeyRSA.cpp: 44 (WebCore::RsaKeyAlgorithm::dictionary const): Deleted. 45 (WebCore::RsaHashedKeyAlgorithm::dictionary const): Deleted. 46 * crypto/keys/CryptoKeyRSA.h: 47 (WebCore::RsaKeyAlgorithm::RsaKeyAlgorithm): Deleted. 48 (WebCore::RsaKeyAlgorithm::modulusLength const): Deleted. 49 (WebCore::RsaKeyAlgorithm::publicExponent const): Deleted. 50 * crypto/keys/CryptoKeyRaw.cpp: 51 (WebCore::CryptoKeyRaw::algorithm const): 52 (WebCore::RawKeyAlgorithm::dictionary const): Deleted. 53 (WebCore::CryptoKeyRaw::buildAlgorithm const): Deleted. 54 * crypto/keys/CryptoKeyRaw.h: 55 (WebCore::RawKeyAlgorithm::RawKeyAlgorithm): Deleted. 56 * crypto/mac/CryptoKeyRSAMac.cpp: 57 (WebCore::CryptoKeyRSA::algorithm const): 58 (WebCore::CryptoKeyRSA::buildAlgorithm const): Deleted. 59 1 60 2017-08-19 Sam Weinig <sam@webkit.org> 2 61 -
trunk/Source/WebCore/crypto/CryptoKey.cpp
r220876 r220954 30 30 31 31 #include "CryptoAlgorithmRegistry.h" 32 #include "CryptoKeyAES.h"33 #include "CryptoKeyEC.h"34 #include "CryptoKeyHMAC.h"35 #include "CryptoKeyRSA.h"36 #include "CryptoKeyRaw.h"37 32 #include <wtf/CryptographicallyRandomNumber.h> 38 33 … … 49 44 CryptoKey::~CryptoKey() 50 45 { 51 }52 53 auto CryptoKey::algorithm() const -> AlgorithmVariant54 {55 std::unique_ptr<KeyAlgorithm> algorithm = buildAlgorithm();56 switch (algorithm->keyAlgorithmClass()) {57 case KeyAlgorithmClass::AES:58 return downcast<AesKeyAlgorithm>(*algorithm).dictionary();59 case KeyAlgorithmClass::EC:60 return downcast<EcKeyAlgorithm>(*algorithm).dictionary();61 case KeyAlgorithmClass::HMAC:62 return downcast<HmacKeyAlgorithm>(*algorithm).dictionary();63 case KeyAlgorithmClass::HRSA:64 return downcast<RsaHashedKeyAlgorithm>(*algorithm).dictionary();65 case KeyAlgorithmClass::RSA:66 return downcast<RsaKeyAlgorithm>(*algorithm).dictionary();67 case KeyAlgorithmClass::Raw:68 return downcast<RawKeyAlgorithm>(*algorithm).dictionary();69 }70 71 RELEASE_ASSERT_NOT_REACHED();72 46 } 73 47 -
trunk/Source/WebCore/crypto/CryptoKey.h
r220949 r220954 46 46 namespace WebCore { 47 47 48 class CryptoAlgorithmDescriptionBuilder;49 50 48 enum class CryptoKeyClass { 51 49 AES, … … 56 54 }; 57 55 58 enum class KeyAlgorithmClass {59 AES,60 EC,61 HMAC,62 HRSA,63 RSA,64 Raw,65 };66 67 class KeyAlgorithm {68 public:69 virtual ~KeyAlgorithm()70 {71 }72 73 virtual KeyAlgorithmClass keyAlgorithmClass() const = 0;74 75 const String& name() const { return m_name; }76 77 protected:78 explicit KeyAlgorithm(const String& name)79 : m_name(name)80 {81 }82 83 private:84 String m_name;85 };86 87 56 class CryptoKey : public ThreadSafeRefCounted<CryptoKey> { 88 57 public: 89 58 using Type = CryptoKeyType; 90 using AlgorithmVariant= Variant<CryptoKeyAlgorithm, CryptoAesKeyAlgorithm, CryptoEcKeyAlgorithm, CryptoHmacKeyAlgorithm, CryptoRsaHashedKeyAlgorithm, CryptoRsaKeyAlgorithm>;59 using KeyAlgorithm = Variant<CryptoKeyAlgorithm, CryptoAesKeyAlgorithm, CryptoEcKeyAlgorithm, CryptoHmacKeyAlgorithm, CryptoRsaHashedKeyAlgorithm, CryptoRsaKeyAlgorithm>; 91 60 92 61 CryptoKey(CryptoAlgorithmIdentifier, Type, bool extractable, CryptoKeyUsageBitmap); … … 95 64 Type type() const; 96 65 bool extractable() const { return m_extractable; } 97 AlgorithmVariant algorithm() const;98 66 Vector<CryptoKeyUsage> usages() const; 67 virtual KeyAlgorithm algorithm() const = 0; 99 68 100 69 virtual CryptoKeyClass keyClass() const = 0; 101 virtual std::unique_ptr<KeyAlgorithm> buildAlgorithm() const = 0;102 70 103 71 CryptoAlgorithmIdentifier algorithmIdentifier() const { return m_algorithmIdentifier; } … … 127 95 SPECIALIZE_TYPE_TRAITS_END() 128 96 129 #define SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(ToClassName, KeyAlgorithmClass) \130 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToClassName) \131 static bool isType(const WebCore::KeyAlgorithm& algorithm) { return algorithm.keyAlgorithmClass() == WebCore::KeyAlgorithmClass; } \132 SPECIALIZE_TYPE_TRAITS_END()133 134 97 #endif // ENABLE(SUBTLE_CRYPTO) -
trunk/Source/WebCore/crypto/gcrypt/CryptoKeyRSAGCrypt.cpp
r220949 r220954 34 34 #include "GCryptUtilities.h" 35 35 #include "ScriptExecutionContext.h" 36 #include <JavaScriptCore/GenericTypedArrayViewInlines.h> 37 #include <JavaScriptCore/JSGenericTypedArrayViewInlines.h> 38 #include <heap/HeapInlines.h> 36 39 #include <pal/crypto/gcrypt/Handle.h> 37 40 #include <pal/crypto/gcrypt/Utilities.h> … … 620 623 } 621 624 622 std::unique_ptr<KeyAlgorithm> CryptoKeyRSA::buildAlgorithm() const 623 { 624 String name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()); 625 size_t modulusLength = getRSAModulusLength(m_platformKey); 626 Vector<uint8_t> publicExponent = getRSAKeyParameter(m_platformKey, "e"); 627 628 if (m_restrictedToSpecificHash) 629 return std::make_unique<RsaHashedKeyAlgorithm>(name, modulusLength, WTFMove(publicExponent), CryptoAlgorithmRegistry::singleton().name(m_hash)); 630 return std::make_unique<RsaKeyAlgorithm>(name, modulusLength, WTFMove(publicExponent)); 625 auto CryptoKeyRSA::algorithm() const -> KeyAlgorithm 626 { 627 auto modulusLength = getRSAModulusLength(m_platformKey); 628 auto publicExponent = getRSAKeyParameter(m_platformKey, "e"); 629 630 if (m_restrictedToSpecificHash) { 631 CryptoRsaHashedKeyAlgorithm result; 632 result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()); 633 result.modulusLength = modulusLength; 634 result.publicExponent = Uint8Array::create(publicExponent.data(), publicExponent.size()); 635 result.hash.name = CryptoAlgorithmRegistry::singleton().name(m_hash); 636 return result; 637 } 638 639 CryptoRsaKeyAlgorithm result; 640 result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()); 641 result.modulusLength = modulusLength; 642 result.publicExponent = Uint8Array::create(publicExponent.data(), publicExponent.size()); 643 return result; 631 644 } 632 645 -
trunk/Source/WebCore/crypto/keys/CryptoKeyAES.cpp
r220949 r220954 37 37 38 38 namespace WebCore { 39 40 CryptoAesKeyAlgorithm AesKeyAlgorithm::dictionary() const41 {42 CryptoAesKeyAlgorithm result;43 result.name = this->name();44 result.length = this->length();45 return result;46 }47 39 48 40 static inline bool lengthIsValid(size_t length) … … 131 123 } 132 124 133 std::unique_ptr<KeyAlgorithm> CryptoKeyAES::buildAlgorithm() const 125 auto CryptoKeyAES::algorithm() const -> KeyAlgorithm 134 126 { 135 return std::make_unique<AesKeyAlgorithm>(CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()), m_key.size() * 8); 127 CryptoAesKeyAlgorithm result; 128 result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()); 129 result.length = m_key.size() * 8; 130 return result; 136 131 } 137 132 -
trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h
r220949 r220954 40 40 struct JsonWebKey; 41 41 42 class AesKeyAlgorithm final : public KeyAlgorithm {43 public:44 AesKeyAlgorithm(const String& name, size_t length)45 : KeyAlgorithm(name)46 , m_length(length)47 {48 }49 50 KeyAlgorithmClass keyAlgorithmClass() const final { return KeyAlgorithmClass::AES; }51 52 CryptoAesKeyAlgorithm dictionary() const;53 54 size_t length() const { return m_length; }55 56 private:57 size_t m_length;58 };59 60 42 class CryptoKeyAES final : public CryptoKey { 61 43 public: … … 88 70 CryptoKeyAES(CryptoAlgorithmIdentifier, Vector<uint8_t>&& key, bool extractable, CryptoKeyUsageBitmap); 89 71 90 std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;72 KeyAlgorithm algorithm() const final; 91 73 92 74 Vector<uint8_t> m_key; … … 97 79 SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyAES, CryptoKeyClass::AES) 98 80 99 SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(AesKeyAlgorithm, KeyAlgorithmClass::AES)100 101 81 #endif // ENABLE(SUBTLE_CRYPTO) -
trunk/Source/WebCore/crypto/keys/CryptoKeyEC.cpp
r220949 r220954 35 35 namespace WebCore { 36 36 37 CryptoEcKeyAlgorithm EcKeyAlgorithm::dictionary() const38 {39 CryptoEcKeyAlgorithm result;40 result.name = this->name();41 result.namedCurve = this->namedCurve();42 return result;43 }44 45 37 static const char* const P256 = "P-256"; 46 38 static const char* const P384 = "P-384"; … … 208 200 } 209 201 210 std::unique_ptr<KeyAlgorithm> CryptoKeyEC::buildAlgorithm() const 211 { 212 String name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()); 202 auto CryptoKeyEC::algorithm() const -> KeyAlgorithm 203 { 204 CryptoEcKeyAlgorithm result; 205 result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()); 206 213 207 switch (m_curve) { 214 208 case NamedCurve::P256: 215 return std::make_unique<EcKeyAlgorithm>(name, String(P256)); 209 result.namedCurve = ASCIILiteral(P256); 210 break; 216 211 case NamedCurve::P384: 217 re turn std::make_unique<EcKeyAlgorithm>(name, String(P384));218 }219 220 ASSERT_NOT_REACHED(); 221 return nullptr;212 result.namedCurve = ASCIILiteral(P384); 213 break; 214 } 215 216 return result; 222 217 } 223 218 -
trunk/Source/WebCore/crypto/keys/CryptoKeyEC.h
r220949 r220954 48 48 struct JsonWebKey; 49 49 50 class EcKeyAlgorithm : public KeyAlgorithm {51 public:52 EcKeyAlgorithm(const String& name, const String& curve)53 : KeyAlgorithm(name)54 , m_curve(curve)55 {56 }57 58 KeyAlgorithmClass keyAlgorithmClass() const override { return KeyAlgorithmClass::EC; }59 60 const String& namedCurve() const { return m_curve; }61 62 CryptoEcKeyAlgorithm dictionary() const;63 64 private:65 String m_curve;66 };67 68 50 class CryptoKeyEC final : public CryptoKey { 69 51 public: 70 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=16923152 // FIXME: Add support for Elliptic Curve P-521 (https://webkit.org/b/169231) 71 53 enum class NamedCurve { 72 54 P256, … … 102 84 CryptoKeyClass keyClass() const final { return CryptoKeyClass::EC; } 103 85 104 std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;86 KeyAlgorithm algorithm() const final; 105 87 106 88 static std::optional<CryptoKeyPair> platformGeneratePair(CryptoAlgorithmIdentifier, NamedCurve, bool extractable, CryptoKeyUsageBitmap); … … 123 105 SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyEC, CryptoKeyClass::EC) 124 106 125 SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(EcKeyAlgorithm, KeyAlgorithmClass::EC)126 127 107 #endif // ENABLE(SUBTLE_CRYPTO) -
trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp
r220949 r220954 37 37 38 38 namespace WebCore { 39 40 CryptoHmacKeyAlgorithm HmacKeyAlgorithm::dictionary() const41 {42 CryptoHmacKeyAlgorithm result;43 result.name = this->name();44 result.hash.name = this->hash();45 result.length = this->length();46 return result;47 }48 39 49 40 static size_t getKeyLengthFromHash(CryptoAlgorithmIdentifier hash) … … 151 142 } 152 143 153 std::unique_ptr<KeyAlgorithm> CryptoKeyHMAC::buildAlgorithm() const 144 auto CryptoKeyHMAC::algorithm() const -> KeyAlgorithm 154 145 { 155 return std::make_unique<HmacKeyAlgorithm>(CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()), 156 CryptoAlgorithmRegistry::singleton().name(m_hash), m_key.size() * 8); 146 CryptoHmacKeyAlgorithm result; 147 result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()); 148 result.hash.name = CryptoAlgorithmRegistry::singleton().name(m_hash); 149 result.length = m_key.size() * 8; 150 return result; 157 151 } 158 152 -
trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h
r220949 r220954 36 36 37 37 class CryptoAlgorithmParameters; 38 39 38 struct JsonWebKey; 40 41 class HmacKeyAlgorithm final : public KeyAlgorithm {42 public:43 HmacKeyAlgorithm(const String& name, const String& hash, size_t length)44 : KeyAlgorithm(name)45 , m_hash(hash)46 , m_length(length)47 {48 }49 50 KeyAlgorithmClass keyAlgorithmClass() const final { return KeyAlgorithmClass::HMAC; }51 52 const String& hash() const { return m_hash; }53 size_t length() const { return m_length; }54 55 CryptoHmacKeyAlgorithm dictionary() const;56 57 private:58 String m_hash;59 size_t m_length;60 };61 39 62 40 class CryptoKeyHMAC final : public CryptoKey { … … 86 64 CryptoKeyHMAC(Vector<uint8_t>&& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsageBitmap); 87 65 88 std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;66 KeyAlgorithm algorithm() const final; 89 67 90 68 CryptoAlgorithmIdentifier m_hash; … … 96 74 SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyHMAC, CryptoKeyClass::HMAC) 97 75 98 SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(HmacKeyAlgorithm, KeyAlgorithmClass::HMAC)99 100 76 #endif // ENABLE(SUBTLE_CRYPTO) -
trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.cpp
r220949 r220954 29 29 #include "CryptoKeyRSAComponents.h" 30 30 #include "JsonWebKey.h" 31 #include <JavaScriptCore/GenericTypedArrayViewInlines.h>32 #include <JavaScriptCore/JSGenericTypedArrayViewInlines.h>33 #include <heap/HeapInlines.h>34 31 #include <wtf/text/Base64.h> 35 32 … … 37 34 38 35 namespace WebCore { 39 40 CryptoRsaKeyAlgorithm RsaKeyAlgorithm::dictionary() const41 {42 CryptoRsaKeyAlgorithm result;43 result.name = this->name();44 result.modulusLength = this->modulusLength();45 result.publicExponent = Uint8Array::create(this->publicExponent().data(), this->publicExponent().size());46 return result;47 }48 49 CryptoRsaHashedKeyAlgorithm RsaHashedKeyAlgorithm::dictionary() const50 {51 CryptoRsaHashedKeyAlgorithm result;52 result.name = this->name();53 result.modulusLength = this->modulusLength();54 result.publicExponent = Uint8Array::create(this->publicExponent().data(), this->publicExponent().size());55 result.hash.name = this->hash();56 return result;57 }58 36 59 37 RefPtr<CryptoKeyRSA> CryptoKeyRSA::importJwk(CryptoAlgorithmIdentifier algorithm, std::optional<CryptoAlgorithmIdentifier> hash, JsonWebKey&& keyData, bool extractable, CryptoKeyUsageBitmap usages) -
trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h
r220949 r220954 52 52 struct JsonWebKey; 53 53 54 class RsaKeyAlgorithm : public KeyAlgorithm {55 public:56 RsaKeyAlgorithm(const String& name, size_t modulusLength, Vector<uint8_t>&& publicExponent)57 : KeyAlgorithm(name)58 , m_modulusLength(modulusLength)59 , m_publicExponent(WTFMove(publicExponent))60 {61 }62 63 KeyAlgorithmClass keyAlgorithmClass() const override { return KeyAlgorithmClass::RSA; }64 65 size_t modulusLength() const { return m_modulusLength; }66 const Vector<uint8_t>& publicExponent() const { return m_publicExponent; }67 68 CryptoRsaKeyAlgorithm dictionary() const;69 70 private:71 size_t m_modulusLength;72 Vector<uint8_t> m_publicExponent;73 };74 75 class RsaHashedKeyAlgorithm final : public RsaKeyAlgorithm {76 public:77 RsaHashedKeyAlgorithm(const String& name, size_t modulusLength, Vector<uint8_t>&& publicExponent, const String& hash)78 : RsaKeyAlgorithm(name, modulusLength, WTFMove(publicExponent))79 , m_hash(hash)80 {81 }82 83 KeyAlgorithmClass keyAlgorithmClass() const final { return KeyAlgorithmClass::HRSA; }84 85 const String& hash() const { return m_hash; }86 87 CryptoRsaHashedKeyAlgorithm dictionary() const;88 89 private:90 String m_hash;91 };92 93 54 class CryptoKeyRSA final : public CryptoKey { 94 55 public: … … 125 86 CryptoKeyClass keyClass() const final { return CryptoKeyClass::RSA; } 126 87 127 std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;88 KeyAlgorithm algorithm() const final; 128 89 129 90 PlatformRSAKey m_platformKey; … … 137 98 SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyRSA, CryptoKeyClass::RSA) 138 99 139 SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(RsaKeyAlgorithm, KeyAlgorithmClass::RSA)140 141 SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(RsaHashedKeyAlgorithm, KeyAlgorithmClass::HRSA)142 143 100 #endif // ENABLE(SUBTLE_CRYPTO) -
trunk/Source/WebCore/crypto/keys/CryptoKeyRaw.cpp
r220949 r220954 33 33 namespace WebCore { 34 34 35 CryptoKeyAlgorithm RawKeyAlgorithm::dictionary() const36 {37 CryptoKeyAlgorithm result;38 result.name = this->name();39 return result;40 }41 42 35 CryptoKeyRaw::CryptoKeyRaw(CryptoAlgorithmIdentifier identifier, Vector<uint8_t>&& keyData, CryptoKeyUsageBitmap usages) 43 36 : CryptoKey(identifier, CryptoKeyType::Secret, false, usages) … … 46 39 } 47 40 48 std::unique_ptr<KeyAlgorithm> CryptoKeyRaw::buildAlgorithm() const 41 auto CryptoKeyRaw::algorithm() const -> KeyAlgorithm 49 42 { 50 return std::make_unique<RawKeyAlgorithm>(CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier())); 43 CryptoKeyAlgorithm result; 44 result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()); 45 return result; 51 46 } 52 47 -
trunk/Source/WebCore/crypto/keys/CryptoKeyRaw.h
r220949 r220954 32 32 namespace WebCore { 33 33 34 class RawKeyAlgorithm : public KeyAlgorithm {35 public:36 RawKeyAlgorithm(const String& name)37 : KeyAlgorithm(name)38 {39 }40 41 KeyAlgorithmClass keyAlgorithmClass() const override { return KeyAlgorithmClass::Raw; }42 43 CryptoKeyAlgorithm dictionary() const;44 };45 46 34 class CryptoKeyRaw final : public CryptoKey { 47 35 public: … … 58 46 CryptoKeyClass keyClass() const final { return CryptoKeyClass::Raw; } 59 47 60 std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;48 KeyAlgorithm algorithm() const final; 61 49 62 50 Vector<uint8_t> m_key; … … 67 55 SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyRaw, CryptoKeyClass::Raw) 68 56 69 SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(RawKeyAlgorithm, KeyAlgorithmClass::Raw)70 71 57 #endif // ENABLE(SUBTLE_CRYPTO) -
trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp
r220949 r220954 35 35 #include "CryptoKeyRSAComponents.h" 36 36 #include "ScriptExecutionContext.h" 37 #include <JavaScriptCore/GenericTypedArrayViewInlines.h> 38 #include <JavaScriptCore/JSGenericTypedArrayViewInlines.h> 39 #include <heap/HeapInlines.h> 37 40 #include <wtf/MainThread.h> 38 41 … … 175 178 } 176 179 177 std::unique_ptr<KeyAlgorithm> CryptoKeyRSA::buildAlgorithm() const 178 { 179 String name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()); 180 auto CryptoKeyRSA::algorithm() const -> KeyAlgorithm 181 { 182 // FIXME: Add a version of getPublicKeyComponents that returns Uint8Array, rather 183 // than Vector<uint8_t>, to avoid a copy of the data. 184 180 185 Vector<uint8_t> modulus; 181 186 Vector<uint8_t> publicExponent; … … 184 189 WTFLogAlways("Couldn't get RSA key components, status %d", status); 185 190 publicExponent.clear(); 186 return std::make_unique<RsaKeyAlgorithm>(name, 0, WTFMove(publicExponent)); 191 192 CryptoRsaKeyAlgorithm result; 193 result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()); 194 result.modulusLength = 0; 195 result.publicExponent = Uint8Array::create(0); 196 return result; 187 197 } 188 198 189 199 size_t modulusLength = modulus.size() * 8; 190 if (m_restrictedToSpecificHash) 191 return std::make_unique<RsaHashedKeyAlgorithm>(name, modulusLength, WTFMove(publicExponent), CryptoAlgorithmRegistry::singleton().name(m_hash)); 192 return std::make_unique<RsaKeyAlgorithm>(name, modulusLength, WTFMove(publicExponent)); 200 201 if (m_restrictedToSpecificHash) { 202 CryptoRsaHashedKeyAlgorithm result; 203 result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()); 204 result.modulusLength = modulusLength; 205 result.publicExponent = Uint8Array::create(publicExponent.data(), publicExponent.size()); 206 result.hash.name = CryptoAlgorithmRegistry::singleton().name(m_hash); 207 return result; 208 } 209 210 CryptoRsaKeyAlgorithm result; 211 result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()); 212 result.modulusLength = modulusLength; 213 result.publicExponent = Uint8Array::create(publicExponent.data(), publicExponent.size()); 214 return result; 193 215 } 194 216
Note: See TracChangeset
for help on using the changeset viewer.