Changeset 220954 in webkit


Ignore:
Timestamp:
Aug 19, 2017 10:28:59 AM (7 years ago)
Author:
commit-queue@webkit.org
Message:

[WebCrypto] Remove the KeyAlgorithm type hierarchy
https://bugs.webkit.org/show_bug.cgi?id=175750

Patch by Sam Weinig <sam@webkit.org> on 2017-08-19
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.

Location:
trunk/Source/WebCore
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r220953 r220954  
     12017-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
    1602017-08-19  Sam Weinig  <sam@webkit.org>
    261
  • trunk/Source/WebCore/crypto/CryptoKey.cpp

    r220876 r220954  
    3030
    3131#include "CryptoAlgorithmRegistry.h"
    32 #include "CryptoKeyAES.h"
    33 #include "CryptoKeyEC.h"
    34 #include "CryptoKeyHMAC.h"
    35 #include "CryptoKeyRSA.h"
    36 #include "CryptoKeyRaw.h"
    3732#include <wtf/CryptographicallyRandomNumber.h>
    3833
     
    4944CryptoKey::~CryptoKey()
    5045{
    51 }
    52 
    53 auto CryptoKey::algorithm() const -> AlgorithmVariant
    54 {
    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();
    7246}
    7347
  • trunk/Source/WebCore/crypto/CryptoKey.h

    r220949 r220954  
    4646namespace WebCore {
    4747
    48 class CryptoAlgorithmDescriptionBuilder;
    49 
    5048enum class CryptoKeyClass {
    5149    AES,
     
    5654};
    5755
    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 
    8756class CryptoKey : public ThreadSafeRefCounted<CryptoKey> {
    8857public:
    8958    using Type = CryptoKeyType;
    90     using AlgorithmVariant = Variant<CryptoKeyAlgorithm, CryptoAesKeyAlgorithm, CryptoEcKeyAlgorithm, CryptoHmacKeyAlgorithm, CryptoRsaHashedKeyAlgorithm, CryptoRsaKeyAlgorithm>;
     59    using KeyAlgorithm = Variant<CryptoKeyAlgorithm, CryptoAesKeyAlgorithm, CryptoEcKeyAlgorithm, CryptoHmacKeyAlgorithm, CryptoRsaHashedKeyAlgorithm, CryptoRsaKeyAlgorithm>;
    9160
    9261    CryptoKey(CryptoAlgorithmIdentifier, Type, bool extractable, CryptoKeyUsageBitmap);
     
    9564    Type type() const;
    9665    bool extractable() const { return m_extractable; }
    97     AlgorithmVariant algorithm() const;
    9866    Vector<CryptoKeyUsage> usages() const;
     67    virtual KeyAlgorithm algorithm() const = 0;
    9968
    10069    virtual CryptoKeyClass keyClass() const = 0;
    101     virtual std::unique_ptr<KeyAlgorithm> buildAlgorithm() const = 0;
    10270
    10371    CryptoAlgorithmIdentifier algorithmIdentifier() const { return m_algorithmIdentifier; }
     
    12795SPECIALIZE_TYPE_TRAITS_END()
    12896
    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 
    13497#endif // ENABLE(SUBTLE_CRYPTO)
  • trunk/Source/WebCore/crypto/gcrypt/CryptoKeyRSAGCrypt.cpp

    r220949 r220954  
    3434#include "GCryptUtilities.h"
    3535#include "ScriptExecutionContext.h"
     36#include <JavaScriptCore/GenericTypedArrayViewInlines.h>
     37#include <JavaScriptCore/JSGenericTypedArrayViewInlines.h>
     38#include <heap/HeapInlines.h>
    3639#include <pal/crypto/gcrypt/Handle.h>
    3740#include <pal/crypto/gcrypt/Utilities.h>
     
    620623}
    621624
    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));
     625auto 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;
    631644}
    632645
  • trunk/Source/WebCore/crypto/keys/CryptoKeyAES.cpp

    r220949 r220954  
    3737
    3838namespace WebCore {
    39 
    40 CryptoAesKeyAlgorithm AesKeyAlgorithm::dictionary() const
    41 {
    42     CryptoAesKeyAlgorithm result;
    43     result.name = this->name();
    44     result.length = this->length();
    45     return result;
    46 }
    4739
    4840static inline bool lengthIsValid(size_t length)
     
    131123}
    132124
    133 std::unique_ptr<KeyAlgorithm> CryptoKeyAES::buildAlgorithm() const
     125auto CryptoKeyAES::algorithm() const -> KeyAlgorithm
    134126{
    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;
    136131}
    137132
  • trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h

    r220949 r220954  
    4040struct JsonWebKey;
    4141
    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 
    6042class CryptoKeyAES final : public CryptoKey {
    6143public:
     
    8870    CryptoKeyAES(CryptoAlgorithmIdentifier, Vector<uint8_t>&& key, bool extractable, CryptoKeyUsageBitmap);
    8971
    90     std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
     72    KeyAlgorithm algorithm() const final;
    9173
    9274    Vector<uint8_t> m_key;
     
    9779SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyAES, CryptoKeyClass::AES)
    9880
    99 SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(AesKeyAlgorithm, KeyAlgorithmClass::AES)
    100 
    10181#endif // ENABLE(SUBTLE_CRYPTO)
  • trunk/Source/WebCore/crypto/keys/CryptoKeyEC.cpp

    r220949 r220954  
    3535namespace WebCore {
    3636
    37 CryptoEcKeyAlgorithm EcKeyAlgorithm::dictionary() const
    38 {
    39     CryptoEcKeyAlgorithm result;
    40     result.name = this->name();
    41     result.namedCurve = this->namedCurve();
    42     return result;
    43 }
    44 
    4537static const char* const P256 = "P-256";
    4638static const char* const P384 = "P-384";
     
    208200}
    209201
    210 std::unique_ptr<KeyAlgorithm> CryptoKeyEC::buildAlgorithm() const
    211 {
    212     String name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
     202auto CryptoKeyEC::algorithm() const -> KeyAlgorithm
     203{
     204    CryptoEcKeyAlgorithm result;
     205    result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
     206
    213207    switch (m_curve) {
    214208    case NamedCurve::P256:
    215         return std::make_unique<EcKeyAlgorithm>(name, String(P256));
     209        result.namedCurve = ASCIILiteral(P256);
     210        break;
    216211    case NamedCurve::P384:
    217         return 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;
    222217}
    223218
  • trunk/Source/WebCore/crypto/keys/CryptoKeyEC.h

    r220949 r220954  
    4848struct JsonWebKey;
    4949
    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 
    6850class CryptoKeyEC final : public CryptoKey {
    6951public:
    70     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=169231
     52    // FIXME: Add support for Elliptic Curve P-521 (https://webkit.org/b/169231)
    7153    enum class NamedCurve {
    7254        P256,
     
    10284    CryptoKeyClass keyClass() const final { return CryptoKeyClass::EC; }
    10385
    104     std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
     86    KeyAlgorithm algorithm() const final;
    10587
    10688    static std::optional<CryptoKeyPair> platformGeneratePair(CryptoAlgorithmIdentifier, NamedCurve, bool extractable, CryptoKeyUsageBitmap);
     
    123105SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyEC, CryptoKeyClass::EC)
    124106
    125 SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(EcKeyAlgorithm, KeyAlgorithmClass::EC)
    126 
    127107#endif // ENABLE(SUBTLE_CRYPTO)
  • trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp

    r220949 r220954  
    3737
    3838namespace WebCore {
    39 
    40 CryptoHmacKeyAlgorithm HmacKeyAlgorithm::dictionary() const
    41 {
    42     CryptoHmacKeyAlgorithm result;
    43     result.name = this->name();
    44     result.hash.name = this->hash();
    45     result.length = this->length();
    46     return result;
    47 }
    4839
    4940static size_t getKeyLengthFromHash(CryptoAlgorithmIdentifier hash)
     
    151142}
    152143
    153 std::unique_ptr<KeyAlgorithm> CryptoKeyHMAC::buildAlgorithm() const
     144auto CryptoKeyHMAC::algorithm() const -> KeyAlgorithm
    154145{
    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;
    157151}
    158152
  • trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h

    r220949 r220954  
    3636
    3737class CryptoAlgorithmParameters;
    38 
    3938struct 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 };
    6139
    6240class CryptoKeyHMAC final : public CryptoKey {
     
    8664    CryptoKeyHMAC(Vector<uint8_t>&& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsageBitmap);
    8765
    88     std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
     66    KeyAlgorithm algorithm() const final;
    8967
    9068    CryptoAlgorithmIdentifier m_hash;
     
    9674SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyHMAC, CryptoKeyClass::HMAC)
    9775
    98 SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(HmacKeyAlgorithm, KeyAlgorithmClass::HMAC)
    99 
    10076#endif // ENABLE(SUBTLE_CRYPTO)
  • trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.cpp

    r220949 r220954  
    2929#include "CryptoKeyRSAComponents.h"
    3030#include "JsonWebKey.h"
    31 #include <JavaScriptCore/GenericTypedArrayViewInlines.h>
    32 #include <JavaScriptCore/JSGenericTypedArrayViewInlines.h>
    33 #include <heap/HeapInlines.h>
    3431#include <wtf/text/Base64.h>
    3532
     
    3734
    3835namespace WebCore {
    39 
    40 CryptoRsaKeyAlgorithm RsaKeyAlgorithm::dictionary() const
    41 {
    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() const
    50 {
    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 }
    5836
    5937RefPtr<CryptoKeyRSA> CryptoKeyRSA::importJwk(CryptoAlgorithmIdentifier algorithm, std::optional<CryptoAlgorithmIdentifier> hash, JsonWebKey&& keyData, bool extractable, CryptoKeyUsageBitmap usages)
  • trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h

    r220949 r220954  
    5252struct JsonWebKey;
    5353
    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 
    9354class CryptoKeyRSA final : public CryptoKey {
    9455public:
     
    12586    CryptoKeyClass keyClass() const final { return CryptoKeyClass::RSA; }
    12687
    127     std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
     88    KeyAlgorithm algorithm() const final;
    12889
    12990    PlatformRSAKey m_platformKey;
     
    13798SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyRSA, CryptoKeyClass::RSA)
    13899
    139 SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(RsaKeyAlgorithm, KeyAlgorithmClass::RSA)
    140 
    141 SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(RsaHashedKeyAlgorithm, KeyAlgorithmClass::HRSA)
    142 
    143100#endif // ENABLE(SUBTLE_CRYPTO)
  • trunk/Source/WebCore/crypto/keys/CryptoKeyRaw.cpp

    r220949 r220954  
    3333namespace WebCore {
    3434
    35 CryptoKeyAlgorithm RawKeyAlgorithm::dictionary() const
    36 {
    37     CryptoKeyAlgorithm result;
    38     result.name = this->name();
    39     return result;
    40 }
    41 
    4235CryptoKeyRaw::CryptoKeyRaw(CryptoAlgorithmIdentifier identifier, Vector<uint8_t>&& keyData, CryptoKeyUsageBitmap usages)
    4336    : CryptoKey(identifier, CryptoKeyType::Secret, false, usages)
     
    4639}
    4740
    48 std::unique_ptr<KeyAlgorithm> CryptoKeyRaw::buildAlgorithm() const
     41auto CryptoKeyRaw::algorithm() const -> KeyAlgorithm
    4942{
    50     return std::make_unique<RawKeyAlgorithm>(CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier()));
     43    CryptoKeyAlgorithm result;
     44    result.name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
     45    return result;
    5146}
    5247
  • trunk/Source/WebCore/crypto/keys/CryptoKeyRaw.h

    r220949 r220954  
    3232namespace WebCore {
    3333
    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 
    4634class CryptoKeyRaw final : public CryptoKey {
    4735public:
     
    5846    CryptoKeyClass keyClass() const final { return CryptoKeyClass::Raw; }
    5947
    60     std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
     48    KeyAlgorithm algorithm() const final;
    6149
    6250    Vector<uint8_t> m_key;
     
    6755SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyRaw, CryptoKeyClass::Raw)
    6856
    69 SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(RawKeyAlgorithm, KeyAlgorithmClass::Raw)
    70 
    7157#endif // ENABLE(SUBTLE_CRYPTO)
  • trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp

    r220949 r220954  
    3535#include "CryptoKeyRSAComponents.h"
    3636#include "ScriptExecutionContext.h"
     37#include <JavaScriptCore/GenericTypedArrayViewInlines.h>
     38#include <JavaScriptCore/JSGenericTypedArrayViewInlines.h>
     39#include <heap/HeapInlines.h>
    3740#include <wtf/MainThread.h>
    3841
     
    175178}
    176179
    177 std::unique_ptr<KeyAlgorithm> CryptoKeyRSA::buildAlgorithm() const
    178 {
    179     String name = CryptoAlgorithmRegistry::singleton().name(algorithmIdentifier());
     180auto 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
    180185    Vector<uint8_t> modulus;
    181186    Vector<uint8_t> publicExponent;
     
    184189        WTFLogAlways("Couldn't get RSA key components, status %d", status);
    185190        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;
    187197    }
    188198
    189199    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;
    193215}
    194216
Note: See TracChangeset for help on using the changeset viewer.