#ifndef CryptoKey_h
#define CryptoKey_h
#if ENABLE(SUBTLE_CRYPTO)
#include "CryptoAlgorithmIdentifier.h"
#include "CryptoKeyType.h"
#include "CryptoKeyUsage.h"
#include <wtf/Forward.h>
#include <wtf/RefCounted.h>
#include <wtf/TypeCasts.h>
#include <wtf/Vector.h>
namespace WebCore {
class CryptoAlgorithmDescriptionBuilder;
class CryptoKeyData;
enum class CryptoKeyClass {
HMAC,
AES,
RSA
};
class CryptoKey : public RefCounted<CryptoKey> {
public:
CryptoKey(CryptoAlgorithmIdentifier, CryptoKeyType, bool extractable, CryptoKeyUsage);
virtual ~CryptoKey();
virtual CryptoKeyClass keyClass() const = 0;
String type() const;
bool extractable() const { return m_extractable; }
virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const;
Vector<String> usages() const;
CryptoAlgorithmIdentifier algorithmIdentifier() const { return m_algorithm; }
CryptoKeyUsage usagesBitmap() const { return m_usages; }
bool allows(CryptoKeyUsage 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;
bool m_extractable;
CryptoKeyUsage m_usages;
};
}
#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()
#endif // ENABLE(SUBTLE_CRYPTO)
#endif // CryptoKey_h