summaryrefslogtreecommitdiff
path: root/Source/WebCore/crypto/CryptoKey.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/crypto/CryptoKey.h')
-rw-r--r--Source/WebCore/crypto/CryptoKey.h83
1 files changed, 63 insertions, 20 deletions
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 <wtf/Forward.h>
-#include <wtf/RefCounted.h>
+#include <wtf/ThreadSafeRefCounted.h>
+#include <wtf/TypeCasts.h>
#include <wtf/Vector.h>
-
-#if ENABLE(SUBTLE_CRYPTO)
+#include <wtf/text/WTFString.h>
namespace WebCore {
@@ -41,42 +42,84 @@ class CryptoAlgorithmDescriptionBuilder;
class CryptoKeyData;
enum class CryptoKeyClass {
- HMAC,
AES,
+ HMAC,
RSA
};
-class CryptoKey : public RefCounted<CryptoKey> {
+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<CryptoKey> {
+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<String> usages() const;
+ virtual std::unique_ptr<KeyAlgorithm> buildAlgorithm() const = 0;
+
+ // Only for binding purpose.
+ Vector<CryptoKeyUsage> 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<CryptoKeyData> exportData() const = 0;
static Vector<uint8_t> 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