Skip to content

Commit

Permalink
Merge r220619 - [WebIDL] Replace JSCryptoKeyCustom and JSCryptoAlgori…
Browse files Browse the repository at this point in the history
…thmBuilder with generated code

https://bugs.webkit.org/show_bug.cgi?id=175457

Patch by Sam Weinig <sam@webkit.org> on 2017-08-11
Reviewed by Chris Dumez.

* CMakeLists.txt:
* DerivedSources.make:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSCryptoAlgorithmBuilder.cpp: Removed.
* bindings/js/JSCryptoAlgorithmBuilder.h: Removed.
* bindings/js/JSCryptoKeyCustom.cpp: Removed.

    Remove JSCryptoAlgorithmBuilder and JSCryptoKeyCustom, add KeyAlgorithm
    IDLs and headers.

* crypto/CryptoKey.cpp:
* crypto/CryptoKey.h:
* crypto/CryptoKey.idl:

    Replace custom algorithm attribute with a union of the supported key algorithms.

* crypto/keys/CryptoAesKeyAlgorithm.h: Added.
* crypto/keys/CryptoAesKeyAlgorithm.idl: Added.
* crypto/keys/CryptoEcKeyAlgorithm.h: Added.
* crypto/keys/CryptoEcKeyAlgorithm.idl: Added.
* crypto/keys/CryptoHmacKeyAlgorithm.h: Added.
* crypto/keys/CryptoHmacKeyAlgorithm.idl: Added.
* crypto/keys/CryptoKeyAlgorithm.h: Added.
* crypto/keys/CryptoKeyAlgorithm.idl: Added.
* crypto/keys/CryptoRsaHashedKeyAlgorithm.h: Added.
* crypto/keys/CryptoRsaHashedKeyAlgorithm.idl: Added.
* crypto/keys/CryptoRsaKeyAlgorithm.h: Added.
* crypto/keys/CryptoRsaKeyAlgorithm.idl: Added.

    Add IDLs and headers fo the supported key algorithms.

* crypto/keys/CryptoKeyAES.h:
* crypto/keys/CryptoKeyEC.h:
* crypto/keys/CryptoKeyHMAC.h:
* crypto/keys/CryptoKeyRSA.h:
* crypto/keys/CryptoKeyRaw.h:

    Give each of the existing KeyAlgorithm subclasses a dictionary() function
    that returns the populated corresponding spec'd dictionary.
  • Loading branch information
Sam Weinig authored and carlosgcampos committed Aug 14, 2017
1 parent ecf205c commit 30ef731
Show file tree
Hide file tree
Showing 31 changed files with 657 additions and 244 deletions.
9 changes: 7 additions & 2 deletions Source/WebCore/CMakeLists.txt
Expand Up @@ -378,6 +378,13 @@ set(WebCore_NON_SVG_IDL_FILES
crypto/SubtleCrypto.idl
crypto/WebKitSubtleCrypto.idl

crypto/keys/CryptoAesKeyAlgorithm.idl
crypto/keys/CryptoEcKeyAlgorithm.idl
crypto/keys/CryptoHmacKeyAlgorithm.idl
crypto/keys/CryptoKeyAlgorithm.idl
crypto/keys/CryptoRsaHashedKeyAlgorithm.idl
crypto/keys/CryptoRsaKeyAlgorithm.idl

crypto/parameters/AesCbcCfbParams.idl
crypto/parameters/AesCtrParams.idl
crypto/parameters/AesGcmParams.idl
Expand Down Expand Up @@ -1183,9 +1190,7 @@ set(WebCore_SOURCES
bindings/js/JSDeprecatedCSSOMValueCustom.cpp
bindings/js/JSCallbackData.cpp
bindings/js/JSCanvasRenderingContext2DCustom.cpp
bindings/js/JSCryptoAlgorithmBuilder.cpp
bindings/js/JSCryptoAlgorithmDictionary.cpp
bindings/js/JSCryptoKeyCustom.cpp
bindings/js/JSCryptoKeySerializationJWK.cpp
bindings/js/JSCryptoOperationData.cpp
bindings/js/JSCustomElementInterface.cpp
Expand Down
47 changes: 47 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,50 @@
2017-08-11 Sam Weinig <sam@webkit.org>

[WebIDL] Replace JSCryptoKeyCustom and JSCryptoAlgorithmBuilder with generated code
https://bugs.webkit.org/show_bug.cgi?id=175457

Reviewed by Chris Dumez.

* CMakeLists.txt:
* DerivedSources.make:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSCryptoAlgorithmBuilder.cpp: Removed.
* bindings/js/JSCryptoAlgorithmBuilder.h: Removed.
* bindings/js/JSCryptoKeyCustom.cpp: Removed.

Remove JSCryptoAlgorithmBuilder and JSCryptoKeyCustom, add KeyAlgorithm
IDLs and headers.

* crypto/CryptoKey.cpp:
* crypto/CryptoKey.h:
* crypto/CryptoKey.idl:

Replace custom algorithm attribute with a union of the supported key algorithms.

* crypto/keys/CryptoAesKeyAlgorithm.h: Added.
* crypto/keys/CryptoAesKeyAlgorithm.idl: Added.
* crypto/keys/CryptoEcKeyAlgorithm.h: Added.
* crypto/keys/CryptoEcKeyAlgorithm.idl: Added.
* crypto/keys/CryptoHmacKeyAlgorithm.h: Added.
* crypto/keys/CryptoHmacKeyAlgorithm.idl: Added.
* crypto/keys/CryptoKeyAlgorithm.h: Added.
* crypto/keys/CryptoKeyAlgorithm.idl: Added.
* crypto/keys/CryptoRsaHashedKeyAlgorithm.h: Added.
* crypto/keys/CryptoRsaHashedKeyAlgorithm.idl: Added.
* crypto/keys/CryptoRsaKeyAlgorithm.h: Added.
* crypto/keys/CryptoRsaKeyAlgorithm.idl: Added.

Add IDLs and headers fo the supported key algorithms.

* crypto/keys/CryptoKeyAES.h:
* crypto/keys/CryptoKeyEC.h:
* crypto/keys/CryptoKeyHMAC.h:
* crypto/keys/CryptoKeyRSA.h:
* crypto/keys/CryptoKeyRaw.h:

Give each of the existing KeyAlgorithm subclasses a dictionary() function
that returns the populated corresponding spec'd dictionary.

2017-08-11 Simon Fraser <simon.fraser@apple.com>

Some RenderSVGResource cleanup
Expand Down
7 changes: 7 additions & 0 deletions Source/WebCore/DerivedSources.make
Expand Up @@ -56,6 +56,7 @@ VPATH = \
$(WebCore)/animation \
$(WebCore)/bindings/js \
$(WebCore)/crypto \
$(WebCore)/crypto/keys \
$(WebCore)/crypto/parameters \
$(WebCore)/css \
$(WebCore)/dom \
Expand Down Expand Up @@ -305,6 +306,12 @@ JS_BINDING_IDLS = \
$(WebCore)/crypto/RsaOtherPrimesInfo.idl \
$(WebCore)/crypto/SubtleCrypto.idl \
$(WebCore)/crypto/WebKitSubtleCrypto.idl \
$(WebCore)/crypto/keys/CryptoAesKeyAlgorithm.idl \
$(WebCore)/crypto/keys/CryptoEcKeyAlgorithm.idl \
$(WebCore)/crypto/keys/CryptoHmacKeyAlgorithm.idl \
$(WebCore)/crypto/keys/CryptoKeyAlgorithm.idl \
$(WebCore)/crypto/keys/CryptoRsaHashedKeyAlgorithm.idl \
$(WebCore)/crypto/keys/CryptoRsaKeyAlgorithm.idl \
$(WebCore)/crypto/parameters/AesCbcCfbParams.idl \
$(WebCore)/crypto/parameters/AesCtrParams.idl \
$(WebCore)/crypto/parameters/AesGcmParams.idl \
Expand Down
112 changes: 92 additions & 20 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

82 changes: 0 additions & 82 deletions Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.cpp

This file was deleted.

104 changes: 0 additions & 104 deletions Source/WebCore/bindings/js/JSCryptoKeyCustom.cpp

This file was deleted.

24 changes: 24 additions & 0 deletions Source/WebCore/crypto/CryptoKey.cpp
Expand Up @@ -29,6 +29,11 @@
#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 {
Expand All @@ -45,6 +50,25 @@ CryptoKey::~CryptoKey()
{
}

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();
}
}

auto CryptoKey::usages() const -> Vector<CryptoKeyUsage>
{
// The result is ordered alphabetically.
Expand Down
18 changes: 13 additions & 5 deletions Source/WebCore/crypto/CryptoKey.h
Expand Up @@ -27,12 +27,19 @@

#if ENABLE(SUBTLE_CRYPTO)

#include "CryptoAesKeyAlgorithm.h"
#include "CryptoAlgorithmIdentifier.h"
#include "CryptoEcKeyAlgorithm.h"
#include "CryptoHmacKeyAlgorithm.h"
#include "CryptoKeyAlgorithm.h"
#include "CryptoKeyType.h"
#include "CryptoKeyUsage.h"
#include "CryptoRsaHashedKeyAlgorithm.h"
#include "CryptoRsaKeyAlgorithm.h"
#include <wtf/Forward.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/TypeCasts.h>
#include <wtf/Variant.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>

Expand Down Expand Up @@ -81,18 +88,19 @@ class KeyAlgorithm {
class CryptoKey : public ThreadSafeRefCounted<CryptoKey> {
public:
using Type = CryptoKeyType;
using AlgorithmVariant = Variant<CryptoKeyAlgorithm, CryptoAesKeyAlgorithm, CryptoEcKeyAlgorithm, CryptoHmacKeyAlgorithm, CryptoRsaHashedKeyAlgorithm, CryptoRsaKeyAlgorithm>;

CryptoKey(CryptoAlgorithmIdentifier, Type, bool extractable, CryptoKeyUsageBitmap);
virtual ~CryptoKey();

virtual CryptoKeyClass keyClass() const = 0;

Type type() const;
bool extractable() const { return m_extractable; }
virtual std::unique_ptr<KeyAlgorithm> buildAlgorithm() const = 0;

// Only for binding purpose.
AlgorithmVariant algorithm() const;
Vector<CryptoKeyUsage> usages() const;

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; }
void setUsagesBitmap(CryptoKeyUsageBitmap usage) { m_usages = usage; };
Expand Down
4 changes: 3 additions & 1 deletion Source/WebCore/crypto/CryptoKey.idl
Expand Up @@ -29,6 +29,8 @@ enum KeyType {
"secret"
};

typedef (CryptoKeyAlgorithm or CryptoAesKeyAlgorithm or CryptoEcKeyAlgorithm or CryptoHmacKeyAlgorithm or CryptoRsaHashedKeyAlgorithm or CryptoRsaKeyAlgorithm) KeyAlgorithm;

[
Conditional=SUBTLE_CRYPTO,
Exposed=(Window,Worker),
Expand All @@ -37,6 +39,6 @@ enum KeyType {
] interface CryptoKey {
readonly attribute KeyType type;
readonly attribute boolean extractable;
[CachedAttribute, CustomGetter] readonly attribute object algorithm;
[CachedAttribute] readonly attribute KeyAlgorithm algorithm;
[CachedAttribute] readonly attribute sequence<CryptoKeyUsage> usages;
};

0 comments on commit 30ef731

Please sign in to comment.