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/WebCore/crypto/CryptoKey.h | 83 +++++++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 20 deletions(-) (limited to 'Source/WebCore/crypto/CryptoKey.h') diff --git a/Source/WebCore/crypto/CryptoKey.h b/Source/WebCore/crypto/CryptoKey.h index 3a1be6900..df06b5456 100644 --- a/Source/WebCore/crypto/CryptoKey.h +++ b/Source/WebCore/crypto/CryptoKey.h @@ -23,17 +23,18 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CryptoKey_h -#define CryptoKey_h +#pragma once + +#if ENABLE(SUBTLE_CRYPTO) #include "CryptoAlgorithmIdentifier.h" #include "CryptoKeyType.h" #include "CryptoKeyUsage.h" #include -#include +#include +#include #include - -#if ENABLE(SUBTLE_CRYPTO) +#include namespace WebCore { @@ -41,42 +42,84 @@ class CryptoAlgorithmDescriptionBuilder; class CryptoKeyData; enum class CryptoKeyClass { - HMAC, AES, + HMAC, RSA }; -class CryptoKey : public RefCounted { +enum class KeyAlgorithmClass { + AES, + HMAC, + HRSA, + RSA, +}; + +class KeyAlgorithm { public: - CryptoKey(CryptoAlgorithmIdentifier, CryptoKeyType, bool extractable, CryptoKeyUsage); + 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 { +public: + using Type = CryptoKeyType; + CryptoKey(CryptoAlgorithmIdentifier, Type, bool extractable, CryptoKeyUsageBitmap); virtual ~CryptoKey(); virtual CryptoKeyClass keyClass() const = 0; - String type() const; + Type type() const; bool extractable() const { return m_extractable; } - virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const; - Vector usages() const; + virtual std::unique_ptr buildAlgorithm() const = 0; + + // Only for binding purpose. + Vector usages() const; - CryptoAlgorithmIdentifier algorithmIdentifier() const { return m_algorithm; } - CryptoKeyUsage usagesBitmap() const { return m_usages; } - bool allows(CryptoKeyUsage usage) const { return usage == (m_usages & usage); } + CryptoAlgorithmIdentifier algorithmIdentifier() const { return m_algorithmIdentifier; } + CryptoKeyUsageBitmap usagesBitmap() const { return m_usages; } + void setUsagesBitmap(CryptoKeyUsageBitmap usage) { m_usages = usage; }; + bool allows(CryptoKeyUsageBitmap usage) const { return usage == (m_usages & usage); } virtual std::unique_ptr exportData() const = 0; static Vector randomData(size_t); private: - CryptoAlgorithmIdentifier m_algorithm; - CryptoKeyType m_type; + CryptoAlgorithmIdentifier m_algorithmIdentifier; + Type m_type; bool m_extractable; - CryptoKeyUsage m_usages; + CryptoKeyUsageBitmap m_usages; }; -#define CRYPTO_KEY_TYPE_CASTS(ToClassName) \ - TYPE_CASTS_BASE(ToClassName, CryptoKey, key, WebCore::is##ToClassName(*key), WebCore::is##ToClassName(key)) +inline auto CryptoKey::type() const -> Type +{ + return m_type; +} } // namespace WebCore +#define SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(ToClassName, KeyClass) \ +SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToClassName) \ + 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) -#endif // CryptoKey_h -- cgit v1.2.1