Diff
Modified: trunk/Source/WebCore/ChangeLog (220953 => 220954)
--- trunk/Source/WebCore/ChangeLog 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/ChangeLog 2017-08-19 17:28:59 UTC (rev 220954)
@@ -1,5 +1,64 @@
2017-08-19 Sam Weinig <[email protected]>
+ [WebCrypto] Remove the KeyAlgorithm type hierarchy
+ https://bugs.webkit.org/show_bug.cgi?id=175750
+
+ Reviewed by Chris Dumez.
+
+ Removes the unnecessary indirection that existed to generate a
+ KeyAlgorithm dictionary (or rather, one of its derived dictionaries)
+ for a CryptoKey. We were calling the virtual buildAlgorithm(), which
+ return a std::unique_ptr<KeyAlgorithm>, which we then casted to the
+ correct derived class and called dictionary() on. This can now be
+ simplified by making each CryptoKey derived class override a function
+ that returns the KeyAlgorithm variant.
+
+ * crypto/CryptoKey.cpp:
+ (WebCore::CryptoKey::algorithm const): Deleted.
+ * crypto/CryptoKey.h:
+ (WebCore::CryptoKey::extractable const):
+ (WebCore::KeyAlgorithm::~KeyAlgorithm): Deleted.
+ (WebCore::KeyAlgorithm::name const): Deleted.
+ (WebCore::KeyAlgorithm::KeyAlgorithm): Deleted.
+ * crypto/gcrypt/CryptoKeyRSAGCrypt.cpp:
+ (WebCore::CryptoKeyRSA::algorithm const):
+ (WebCore::CryptoKeyRSA::buildAlgorithm const): Deleted.
+ * crypto/keys/CryptoKeyAES.cpp:
+ (WebCore::CryptoKeyAES::algorithm const):
+ (WebCore::AesKeyAlgorithm::dictionary const): Deleted.
+ (WebCore::CryptoKeyAES::buildAlgorithm const): Deleted.
+ * crypto/keys/CryptoKeyAES.h:
+ * crypto/keys/CryptoKeyEC.cpp:
+ (WebCore::CryptoKeyEC::algorithm const):
+ (WebCore::EcKeyAlgorithm::dictionary const): Deleted.
+ (WebCore::CryptoKeyEC::buildAlgorithm const): Deleted.
+ * crypto/keys/CryptoKeyEC.h:
+ (WebCore::EcKeyAlgorithm::EcKeyAlgorithm): Deleted.
+ (WebCore::EcKeyAlgorithm::namedCurve const): Deleted.
+ * crypto/keys/CryptoKeyHMAC.cpp:
+ (WebCore::CryptoKeyHMAC::algorithm const):
+ (WebCore::HmacKeyAlgorithm::dictionary const): Deleted.
+ (WebCore::CryptoKeyHMAC::buildAlgorithm const): Deleted.
+ * crypto/keys/CryptoKeyHMAC.h:
+ * crypto/keys/CryptoKeyRSA.cpp:
+ (WebCore::RsaKeyAlgorithm::dictionary const): Deleted.
+ (WebCore::RsaHashedKeyAlgorithm::dictionary const): Deleted.
+ * crypto/keys/CryptoKeyRSA.h:
+ (WebCore::RsaKeyAlgorithm::RsaKeyAlgorithm): Deleted.
+ (WebCore::RsaKeyAlgorithm::modulusLength const): Deleted.
+ (WebCore::RsaKeyAlgorithm::publicExponent const): Deleted.
+ * crypto/keys/CryptoKeyRaw.cpp:
+ (WebCore::CryptoKeyRaw::algorithm const):
+ (WebCore::RawKeyAlgorithm::dictionary const): Deleted.
+ (WebCore::CryptoKeyRaw::buildAlgorithm const): Deleted.
+ * crypto/keys/CryptoKeyRaw.h:
+ (WebCore::RawKeyAlgorithm::RawKeyAlgorithm): Deleted.
+ * crypto/mac/CryptoKeyRSAMac.cpp:
+ (WebCore::CryptoKeyRSA::algorithm const):
+ (WebCore::CryptoKeyRSA::buildAlgorithm const): Deleted.
+
+2017-08-19 Sam Weinig <[email protected]>
+
[Mac] Change uint8_t* to Vector<uint8_t> type in all crypto algorithm implementation
https://bugs.webkit.org/show_bug.cgi?id=164939
Modified: trunk/Source/WebCore/crypto/CryptoKey.cpp (220953 => 220954)
--- trunk/Source/WebCore/crypto/CryptoKey.cpp 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/CryptoKey.cpp 2017-08-19 17:28:59 UTC (rev 220954)
@@ -29,11 +29,6 @@
#if ENABLE(SUBTLE_CRYPTO)
#include "CryptoAlgorithmRegistry.h"
-#include "CryptoKeyAES.h"
-#include "CryptoKeyEC.h"
-#include "CryptoKeyHMAC.h"
-#include "CryptoKeyRSA.h"
-#include "CryptoKeyRaw.h"
#include <wtf/CryptographicallyRandomNumber.h>
namespace WebCore {
@@ -50,27 +45,6 @@
{
}
-auto CryptoKey::algorithm() const -> AlgorithmVariant
-{
- std::unique_ptr<KeyAlgorithm> algorithm = buildAlgorithm();
- switch (algorithm->keyAlgorithmClass()) {
- case KeyAlgorithmClass::AES:
- return downcast<AesKeyAlgorithm>(*algorithm).dictionary();
- case KeyAlgorithmClass::EC:
- return downcast<EcKeyAlgorithm>(*algorithm).dictionary();
- case KeyAlgorithmClass::HMAC:
- return downcast<HmacKeyAlgorithm>(*algorithm).dictionary();
- case KeyAlgorithmClass::HRSA:
- return downcast<RsaHashedKeyAlgorithm>(*algorithm).dictionary();
- case KeyAlgorithmClass::RSA:
- return downcast<RsaKeyAlgorithm>(*algorithm).dictionary();
- case KeyAlgorithmClass::Raw:
- return downcast<RawKeyAlgorithm>(*algorithm).dictionary();
- }
-
- RELEASE_ASSERT_NOT_REACHED();
-}
-
auto CryptoKey::usages() const -> Vector<CryptoKeyUsage>
{
// The result is ordered alphabetically.
Modified: trunk/Source/WebCore/crypto/CryptoKey.h (220953 => 220954)
--- trunk/Source/WebCore/crypto/CryptoKey.h 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/CryptoKey.h 2017-08-19 17:28:59 UTC (rev 220954)
@@ -45,8 +45,6 @@
namespace WebCore {
-class CryptoAlgorithmDescriptionBuilder;
-
enum class CryptoKeyClass {
AES,
EC,
@@ -55,39 +53,10 @@
Raw,
};
-enum class KeyAlgorithmClass {
- AES,
- EC,
- HMAC,
- HRSA,
- RSA,
- Raw,
-};
-
-class KeyAlgorithm {
-public:
- virtual ~KeyAlgorithm()
- {
- }
-
- virtual KeyAlgorithmClass keyAlgorithmClass() const = 0;
-
- const String& name() const { return m_name; }
-
-protected:
- explicit KeyAlgorithm(const String& name)
- : m_name(name)
- {
- }
-
-private:
- String m_name;
-};
-
class CryptoKey : public ThreadSafeRefCounted<CryptoKey> {
public:
using Type = CryptoKeyType;
- using AlgorithmVariant = Variant<CryptoKeyAlgorithm, CryptoAesKeyAlgorithm, CryptoEcKeyAlgorithm, CryptoHmacKeyAlgorithm, CryptoRsaHashedKeyAlgorithm, CryptoRsaKeyAlgorithm>;
+ using KeyAlgorithm = Variant<CryptoKeyAlgorithm, CryptoAesKeyAlgorithm, CryptoEcKeyAlgorithm, CryptoHmacKeyAlgorithm, CryptoRsaHashedKeyAlgorithm, CryptoRsaKeyAlgorithm>;
CryptoKey(CryptoAlgorithmIdentifier, Type, bool extractable, CryptoKeyUsageBitmap);
virtual ~CryptoKey();
@@ -94,11 +63,10 @@
Type type() const;
bool extractable() const { return m_extractable; }
- AlgorithmVariant algorithm() const;
Vector<CryptoKeyUsage> usages() const;
+ virtual KeyAlgorithm algorithm() const = 0;
virtual CryptoKeyClass keyClass() const = 0;
- virtual std::unique_ptr<KeyAlgorithm> buildAlgorithm() const = 0;
CryptoAlgorithmIdentifier algorithmIdentifier() const { return m_algorithmIdentifier; }
CryptoKeyUsageBitmap usagesBitmap() const { return m_usages; }
@@ -126,9 +94,4 @@
static bool isType(const WebCore::CryptoKey& key) { return key.keyClass() == WebCore::KeyClass; } \
SPECIALIZE_TYPE_TRAITS_END()
-#define SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(ToClassName, KeyAlgorithmClass) \
-SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToClassName) \
- static bool isType(const WebCore::KeyAlgorithm& algorithm) { return algorithm.keyAlgorithmClass() == WebCore::KeyAlgorithmClass; } \
-SPECIALIZE_TYPE_TRAITS_END()
-
#endif // ENABLE(SUBTLE_CRYPTO)
Modified: trunk/Source/WebCore/crypto/gcrypt/CryptoKeyRSAGCrypt.cpp (220953 => 220954)
--- trunk/Source/WebCore/crypto/gcrypt/CryptoKeyRSAGCrypt.cpp 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/gcrypt/CryptoKeyRSAGCrypt.cpp 2017-08-19 17:28:59 UTC (rev 220954)
@@ -33,6 +33,9 @@
#include "CryptoKeyRSAComponents.h"
#include "GCryptUtilities.h"
#include "ScriptExecutionContext.h"
+#include <_javascript_Core/GenericTypedArrayViewInlines.h>
+#include <_javascript_Core/JSGenericTypedArrayViewInlines.h>
+#include <heap/HeapInlines.h>
#include <pal/crypto/gcrypt/Handle.h>
#include <pal/crypto/gcrypt/Utilities.h>
#include <pal/crypto/tasn1/Utilities.h>
@@ -619,15 +622,25 @@
return WTFMove(result.value());
}
-std::unique_ptr<KeyAlgorithm> CryptoKeyRSA::buildAlgorithm() const
+auto CryptoKeyRSA::algorithm() const -> KeyAlgorithm
{
- String name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
- size_t modulusLength = getRSAModulusLength(m_platformKey);
- Vector<uint8_t> publicExponent = getRSAKeyParameter(m_platformKey, "e");
+ auto modulusLength = getRSAModulusLength(m_platformKey);
+ auto publicExponent = getRSAKeyParameter(m_platformKey, "e");
- if (m_restrictedToSpecificHash)
- return std::make_unique<RsaHashedKeyAlgorithm>(name, modulusLength, WTFMove(publicExponent), CryptoAlgorithmRegistry::singleton().name(m_hash));
- return std::make_unique<RsaKeyAlgorithm>(name, modulusLength, WTFMove(publicExponent));
+ if (m_restrictedToSpecificHash) {
+ CryptoRsaHashedKeyAlgorithm result;
+ result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
+ result.modulusLength = modulusLength;
+ result.publicExponent = Uint8Array::create(publicExponent.data(), publicExponent.size());
+ result.hash.name = CryptoAlgorithmRegistry::singleton().name(m_hash);
+ return result;
+ }
+
+ CryptoRsaKeyAlgorithm result;
+ result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
+ result.modulusLength = modulusLength;
+ result.publicExponent = Uint8Array::create(publicExponent.data(), publicExponent.size());
+ return result;
}
std::unique_ptr<CryptoKeyRSAComponents> CryptoKeyRSA::exportData() const
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyAES.cpp (220953 => 220954)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyAES.cpp 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyAES.cpp 2017-08-19 17:28:59 UTC (rev 220954)
@@ -37,14 +37,6 @@
namespace WebCore {
-CryptoAesKeyAlgorithm AesKeyAlgorithm::dictionary() const
-{
- CryptoAesKeyAlgorithm result;
- result.name = this->name();
- result.length = this->length();
- return result;
-}
-
static inline bool lengthIsValid(size_t length)
{
return (length == CryptoKeyAES::s_length128) || (length == CryptoKeyAES::s_length192) || (length == CryptoKeyAES::s_length256);
@@ -130,9 +122,12 @@
return aesParameters.length;
}
-std::unique_ptr<KeyAlgorithm> CryptoKeyAES::buildAlgorithm() const
+auto CryptoKeyAES::algorithm() const -> KeyAlgorithm
{
- return std::make_unique<AesKeyAlgorithm>(CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()), m_key.size() * 8);
+ CryptoAesKeyAlgorithm result;
+ result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
+ result.length = m_key.size() * 8;
+ return result;
}
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h (220953 => 220954)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h 2017-08-19 17:28:59 UTC (rev 220954)
@@ -39,24 +39,6 @@
struct JsonWebKey;
-class AesKeyAlgorithm final : public KeyAlgorithm {
-public:
- AesKeyAlgorithm(const String& name, size_t length)
- : KeyAlgorithm(name)
- , m_length(length)
- {
- }
-
- KeyAlgorithmClass keyAlgorithmClass() const final { return KeyAlgorithmClass::AES; }
-
- CryptoAesKeyAlgorithm dictionary() const;
-
- size_t length() const { return m_length; }
-
-private:
- size_t m_length;
-};
-
class CryptoKeyAES final : public CryptoKey {
public:
static const int s_length128 = 128;
@@ -87,7 +69,7 @@
CryptoKeyAES(CryptoAlgorithmIdentifier, const Vector<uint8_t>& key, bool extractable, CryptoKeyUsageBitmap);
CryptoKeyAES(CryptoAlgorithmIdentifier, Vector<uint8_t>&& key, bool extractable, CryptoKeyUsageBitmap);
- std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
+ KeyAlgorithm algorithm() const final;
Vector<uint8_t> m_key;
};
@@ -96,6 +78,4 @@
SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyAES, CryptoKeyClass::AES)
-SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(AesKeyAlgorithm, KeyAlgorithmClass::AES)
-
#endif // ENABLE(SUBTLE_CRYPTO)
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyEC.cpp (220953 => 220954)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyEC.cpp 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyEC.cpp 2017-08-19 17:28:59 UTC (rev 220954)
@@ -34,14 +34,6 @@
namespace WebCore {
-CryptoEcKeyAlgorithm EcKeyAlgorithm::dictionary() const
-{
- CryptoEcKeyAlgorithm result;
- result.name = this->name();
- result.namedCurve = this->namedCurve();
- return result;
-}
-
static const char* const P256 = "P-256";
static const char* const P384 = "P-384";
@@ -207,18 +199,21 @@
return algorithm == CryptoAlgorithmIdentifier::ECDSA || algorithm == CryptoAlgorithmIdentifier::ECDH;
}
-std::unique_ptr<KeyAlgorithm> CryptoKeyEC::buildAlgorithm() const
+auto CryptoKeyEC::algorithm() const -> KeyAlgorithm
{
- String name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
+ CryptoEcKeyAlgorithm result;
+ result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
+
switch (m_curve) {
case NamedCurve::P256:
- return std::make_unique<EcKeyAlgorithm>(name, String(P256));
+ result.namedCurve = ASCIILiteral(P256);
+ break;
case NamedCurve::P384:
- return std::make_unique<EcKeyAlgorithm>(name, String(P384));
+ result.namedCurve = ASCIILiteral(P384);
+ break;
}
- ASSERT_NOT_REACHED();
- return nullptr;
+ return result;
}
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyEC.h (220953 => 220954)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyEC.h 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyEC.h 2017-08-19 17:28:59 UTC (rev 220954)
@@ -47,27 +47,9 @@
struct JsonWebKey;
-class EcKeyAlgorithm : public KeyAlgorithm {
-public:
- EcKeyAlgorithm(const String& name, const String& curve)
- : KeyAlgorithm(name)
- , m_curve(curve)
- {
- }
-
- KeyAlgorithmClass keyAlgorithmClass() const override { return KeyAlgorithmClass::EC; }
-
- const String& namedCurve() const { return m_curve; }
-
- CryptoEcKeyAlgorithm dictionary() const;
-
-private:
- String m_curve;
-};
-
class CryptoKeyEC final : public CryptoKey {
public:
- // FIXME: https://bugs.webkit.org/show_bug.cgi?id=169231
+ // FIXME: Add support for Elliptic Curve P-521 (https://webkit.org/b/169231)
enum class NamedCurve {
P256,
P384,
@@ -101,7 +83,7 @@
CryptoKeyClass keyClass() const final { return CryptoKeyClass::EC; }
- std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
+ KeyAlgorithm algorithm() const final;
static std::optional<CryptoKeyPair> platformGeneratePair(CryptoAlgorithmIdentifier, NamedCurve, bool extractable, CryptoKeyUsageBitmap);
static RefPtr<CryptoKeyEC> platformImportRaw(CryptoAlgorithmIdentifier, NamedCurve, Vector<uint8_t>&& keyData, bool extractable, CryptoKeyUsageBitmap);
@@ -122,6 +104,4 @@
SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyEC, CryptoKeyClass::EC)
-SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(EcKeyAlgorithm, KeyAlgorithmClass::EC)
-
#endif // ENABLE(SUBTLE_CRYPTO)
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp (220953 => 220954)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp 2017-08-19 17:28:59 UTC (rev 220954)
@@ -37,15 +37,6 @@
namespace WebCore {
-CryptoHmacKeyAlgorithm HmacKeyAlgorithm::dictionary() const
-{
- CryptoHmacKeyAlgorithm result;
- result.name = this->name();
- result.hash.name = this->hash();
- result.length = this->length();
- return result;
-}
-
static size_t getKeyLengthFromHash(CryptoAlgorithmIdentifier hash)
{
switch (hash) {
@@ -150,10 +141,13 @@
return Exception { TypeError };
}
-std::unique_ptr<KeyAlgorithm> CryptoKeyHMAC::buildAlgorithm() const
+auto CryptoKeyHMAC::algorithm() const -> KeyAlgorithm
{
- return std::make_unique<HmacKeyAlgorithm>(CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()),
- CryptoAlgorithmRegistry::singleton().name(m_hash), m_key.size() * 8);
+ CryptoHmacKeyAlgorithm result;
+ result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
+ result.hash.name = CryptoAlgorithmRegistry::singleton().name(m_hash);
+ result.length = m_key.size() * 8;
+ return result;
}
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h (220953 => 220954)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h 2017-08-19 17:28:59 UTC (rev 220954)
@@ -35,30 +35,8 @@
namespace WebCore {
class CryptoAlgorithmParameters;
-
struct JsonWebKey;
-class HmacKeyAlgorithm final : public KeyAlgorithm {
-public:
- HmacKeyAlgorithm(const String& name, const String& hash, size_t length)
- : KeyAlgorithm(name)
- , m_hash(hash)
- , m_length(length)
- {
- }
-
- KeyAlgorithmClass keyAlgorithmClass() const final { return KeyAlgorithmClass::HMAC; }
-
- const String& hash() const { return m_hash; }
- size_t length() const { return m_length; }
-
- CryptoHmacKeyAlgorithm dictionary() const;
-
-private:
- String m_hash;
- size_t m_length;
-};
-
class CryptoKeyHMAC final : public CryptoKey {
public:
static Ref<CryptoKeyHMAC> create(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsageBitmap usage)
@@ -85,7 +63,7 @@
CryptoKeyHMAC(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsageBitmap);
CryptoKeyHMAC(Vector<uint8_t>&& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsageBitmap);
- std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
+ KeyAlgorithm algorithm() const final;
CryptoAlgorithmIdentifier m_hash;
Vector<uint8_t> m_key;
@@ -95,6 +73,4 @@
SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyHMAC, CryptoKeyClass::HMAC)
-SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(HmacKeyAlgorithm, KeyAlgorithmClass::HMAC)
-
#endif // ENABLE(SUBTLE_CRYPTO)
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.cpp (220953 => 220954)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.cpp 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.cpp 2017-08-19 17:28:59 UTC (rev 220954)
@@ -28,9 +28,6 @@
#include "CryptoKeyRSAComponents.h"
#include "JsonWebKey.h"
-#include <_javascript_Core/GenericTypedArrayViewInlines.h>
-#include <_javascript_Core/JSGenericTypedArrayViewInlines.h>
-#include <heap/HeapInlines.h>
#include <wtf/text/Base64.h>
#if ENABLE(SUBTLE_CRYPTO)
@@ -37,25 +34,6 @@
namespace WebCore {
-CryptoRsaKeyAlgorithm RsaKeyAlgorithm::dictionary() const
-{
- CryptoRsaKeyAlgorithm result;
- result.name = this->name();
- result.modulusLength = this->modulusLength();
- result.publicExponent = Uint8Array::create(this->publicExponent().data(), this->publicExponent().size());
- return result;
-}
-
-CryptoRsaHashedKeyAlgorithm RsaHashedKeyAlgorithm::dictionary() const
-{
- CryptoRsaHashedKeyAlgorithm result;
- result.name = this->name();
- result.modulusLength = this->modulusLength();
- result.publicExponent = Uint8Array::create(this->publicExponent().data(), this->publicExponent().size());
- result.hash.name = this->hash();
- return result;
-}
-
RefPtr<CryptoKeyRSA> CryptoKeyRSA::importJwk(CryptoAlgorithmIdentifier algorithm, std::optional<CryptoAlgorithmIdentifier> hash, JsonWebKey&& keyData, bool extractable, CryptoKeyUsageBitmap usages)
{
if (keyData.kty != "RSA")
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h (220953 => 220954)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h 2017-08-19 17:28:59 UTC (rev 220954)
@@ -51,45 +51,6 @@
struct CryptoKeyPair;
struct JsonWebKey;
-class RsaKeyAlgorithm : public KeyAlgorithm {
-public:
- RsaKeyAlgorithm(const String& name, size_t modulusLength, Vector<uint8_t>&& publicExponent)
- : KeyAlgorithm(name)
- , m_modulusLength(modulusLength)
- , m_publicExponent(WTFMove(publicExponent))
- {
- }
-
- KeyAlgorithmClass keyAlgorithmClass() const override { return KeyAlgorithmClass::RSA; }
-
- size_t modulusLength() const { return m_modulusLength; }
- const Vector<uint8_t>& publicExponent() const { return m_publicExponent; }
-
- CryptoRsaKeyAlgorithm dictionary() const;
-
-private:
- size_t m_modulusLength;
- Vector<uint8_t> m_publicExponent;
-};
-
-class RsaHashedKeyAlgorithm final : public RsaKeyAlgorithm {
-public:
- RsaHashedKeyAlgorithm(const String& name, size_t modulusLength, Vector<uint8_t>&& publicExponent, const String& hash)
- : RsaKeyAlgorithm(name, modulusLength, WTFMove(publicExponent))
- , m_hash(hash)
- {
- }
-
- KeyAlgorithmClass keyAlgorithmClass() const final { return KeyAlgorithmClass::HRSA; }
-
- const String& hash() const { return m_hash; }
-
- CryptoRsaHashedKeyAlgorithm dictionary() const;
-
-private:
- String m_hash;
-};
-
class CryptoKeyRSA final : public CryptoKey {
public:
static Ref<CryptoKeyRSA> create(CryptoAlgorithmIdentifier identifier, CryptoAlgorithmIdentifier hash, bool hasHash, CryptoKeyType type, PlatformRSAKey platformKey, bool extractable, CryptoKeyUsageBitmap usage)
@@ -124,7 +85,7 @@
CryptoKeyClass keyClass() const final { return CryptoKeyClass::RSA; }
- std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
+ KeyAlgorithm algorithm() const final;
PlatformRSAKey m_platformKey;
@@ -136,8 +97,4 @@
SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyRSA, CryptoKeyClass::RSA)
-SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(RsaKeyAlgorithm, KeyAlgorithmClass::RSA)
-
-SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(RsaHashedKeyAlgorithm, KeyAlgorithmClass::HRSA)
-
#endif // ENABLE(SUBTLE_CRYPTO)
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyRaw.cpp (220953 => 220954)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyRaw.cpp 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyRaw.cpp 2017-08-19 17:28:59 UTC (rev 220954)
@@ -32,13 +32,6 @@
namespace WebCore {
-CryptoKeyAlgorithm RawKeyAlgorithm::dictionary() const
-{
- CryptoKeyAlgorithm result;
- result.name = this->name();
- return result;
-}
-
CryptoKeyRaw::CryptoKeyRaw(CryptoAlgorithmIdentifier identifier, Vector<uint8_t>&& keyData, CryptoKeyUsageBitmap usages)
: CryptoKey(identifier, CryptoKeyType::Secret, false, usages)
, m_key(WTFMove(keyData))
@@ -45,9 +38,11 @@
{
}
-std::unique_ptr<KeyAlgorithm> CryptoKeyRaw::buildAlgorithm() const
+auto CryptoKeyRaw::algorithm() const -> KeyAlgorithm
{
- return std::make_unique<RawKeyAlgorithm>(CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()));
+ CryptoKeyAlgorithm result;
+ result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
+ return result;
}
} // namespace WebCore
Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyRaw.h (220953 => 220954)
--- trunk/Source/WebCore/crypto/keys/CryptoKeyRaw.h 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyRaw.h 2017-08-19 17:28:59 UTC (rev 220954)
@@ -31,18 +31,6 @@
namespace WebCore {
-class RawKeyAlgorithm : public KeyAlgorithm {
-public:
- RawKeyAlgorithm(const String& name)
- : KeyAlgorithm(name)
- {
- }
-
- KeyAlgorithmClass keyAlgorithmClass() const override { return KeyAlgorithmClass::Raw; }
-
- CryptoKeyAlgorithm dictionary() const;
-};
-
class CryptoKeyRaw final : public CryptoKey {
public:
static Ref<CryptoKeyRaw> create(CryptoAlgorithmIdentifier identifier, Vector<uint8_t>&& keyData, CryptoKeyUsageBitmap usages)
@@ -57,7 +45,7 @@
CryptoKeyClass keyClass() const final { return CryptoKeyClass::Raw; }
- std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
+ KeyAlgorithm algorithm() const final;
Vector<uint8_t> m_key;
};
@@ -66,6 +54,4 @@
SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyRaw, CryptoKeyClass::Raw)
-SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(RawKeyAlgorithm, KeyAlgorithmClass::Raw)
-
#endif // ENABLE(SUBTLE_CRYPTO)
Modified: trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp (220953 => 220954)
--- trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp 2017-08-19 16:41:47 UTC (rev 220953)
+++ trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp 2017-08-19 17:28:59 UTC (rev 220954)
@@ -34,6 +34,9 @@
#include "CryptoKeyPair.h"
#include "CryptoKeyRSAComponents.h"
#include "ScriptExecutionContext.h"
+#include <_javascript_Core/GenericTypedArrayViewInlines.h>
+#include <_javascript_Core/JSGenericTypedArrayViewInlines.h>
+#include <heap/HeapInlines.h>
#include <wtf/MainThread.h>
namespace WebCore {
@@ -174,9 +177,11 @@
return modulus.size() * 8;
}
-std::unique_ptr<KeyAlgorithm> CryptoKeyRSA::buildAlgorithm() const
+auto CryptoKeyRSA::algorithm() const -> KeyAlgorithm
{
- String name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
+ // FIXME: Add a version of getPublicKeyComponents that returns Uint8Array, rather
+ // than Vector<uint8_t>, to avoid a copy of the data.
+
Vector<uint8_t> modulus;
Vector<uint8_t> publicExponent;
CCCryptorStatus status = getPublicKeyComponents(m_platformKey, modulus, publicExponent);
@@ -183,13 +188,30 @@
if (status) {
WTFLogAlways("Couldn't get RSA key components, status %d", status);
publicExponent.clear();
- return std::make_unique<RsaKeyAlgorithm>(name, 0, WTFMove(publicExponent));
+
+ CryptoRsaKeyAlgorithm result;
+ result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
+ result.modulusLength = 0;
+ result.publicExponent = Uint8Array::create(0);
+ return result;
}
size_t modulusLength = modulus.size() * 8;
- if (m_restrictedToSpecificHash)
- return std::make_unique<RsaHashedKeyAlgorithm>(name, modulusLength, WTFMove(publicExponent), CryptoAlgorithmRegistry::singleton().name(m_hash));
- return std::make_unique<RsaKeyAlgorithm>(name, modulusLength, WTFMove(publicExponent));
+
+ if (m_restrictedToSpecificHash) {
+ CryptoRsaHashedKeyAlgorithm result;
+ result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
+ result.modulusLength = modulusLength;
+ result.publicExponent = Uint8Array::create(publicExponent.data(), publicExponent.size());
+ result.hash.name = CryptoAlgorithmRegistry::singleton().name(m_hash);
+ return result;
+ }
+
+ CryptoRsaKeyAlgorithm result;
+ result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
+ result.modulusLength = modulusLength;
+ result.publicExponent = Uint8Array::create(publicExponent.data(), publicExponent.size());
+ return result;
}
std::unique_ptr<CryptoKeyRSAComponents> CryptoKeyRSA::exportData() const