#ifndef WebCryptoKeyAlgorithmParams_h
#define WebCryptoKeyAlgorithmParams_h
#include "WebCommon.h"
#include "WebCryptoAlgorithm.h"
#include "WebVector.h"
#define WEBCRYPTO_HMAC_KEY_HAS_LENGTH 1
namespace blink {
enum WebCryptoKeyAlgorithmParamsType {
WebCryptoKeyAlgorithmParamsTypeNone,
WebCryptoKeyAlgorithmParamsTypeHmac,
WebCryptoKeyAlgorithmParamsTypeAes,
WebCryptoKeyAlgorithmParamsTypeRsa,
WebCryptoKeyAlgorithmParamsTypeRsaHashed
};
class WebCryptoKeyAlgorithmParams {
public:
virtual ~WebCryptoKeyAlgorithmParams() { }
virtual WebCryptoKeyAlgorithmParamsType type() const
{
return WebCryptoKeyAlgorithmParamsTypeNone;
}
};
class WebCryptoAesKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams {
public:
explicit WebCryptoAesKeyAlgorithmParams(unsigned short lengthBits)
: m_lengthBits(lengthBits)
{
}
unsigned short lengthBits() const
{
return m_lengthBits;
}
virtual WebCryptoKeyAlgorithmParamsType type() const
{
return WebCryptoKeyAlgorithmParamsTypeAes;
}
private:
unsigned short m_lengthBits;
};
class WebCryptoHmacKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams {
public:
WebCryptoHmacKeyAlgorithmParams(const WebCryptoAlgorithm& hash, unsigned lengthBits)
: m_hash(hash)
, m_lengthBits(lengthBits)
{
}
const WebCryptoAlgorithm& hash() const
{
return m_hash;
}
unsigned lengthBits() const
{
return m_lengthBits;
}
virtual WebCryptoKeyAlgorithmParamsType type() const
{
return WebCryptoKeyAlgorithmParamsTypeHmac;
}
private:
WebCryptoAlgorithm m_hash;
unsigned m_lengthBits;
};
class WebCryptoRsaKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams {
public:
WebCryptoRsaKeyAlgorithmParams(unsigned modulusLengthBits, const unsigned char* publicExponent, unsigned publicExponentSize)
: m_modulusLengthBits(modulusLengthBits)
, m_publicExponent(publicExponent, publicExponentSize)
{
}
unsigned modulusLengthBits() const
{
return m_modulusLengthBits;
}
const WebVector<unsigned char>& publicExponent() const
{
return m_publicExponent;
}
virtual WebCryptoKeyAlgorithmParamsType type() const
{
return WebCryptoKeyAlgorithmParamsTypeRsa;
}
private:
unsigned m_modulusLengthBits;
WebVector<unsigned char> m_publicExponent;
};
class WebCryptoRsaHashedKeyAlgorithmParams : public WebCryptoRsaKeyAlgorithmParams {
public:
WebCryptoRsaHashedKeyAlgorithmParams(unsigned modulusLengthBits, const unsigned char* publicExponent, unsigned publicExponentSize, const WebCryptoAlgorithm& hash)
: WebCryptoRsaKeyAlgorithmParams(modulusLengthBits, publicExponent, publicExponentSize)
, m_hash(hash)
{
}
const WebCryptoAlgorithm& hash() const
{
return m_hash;
}
virtual WebCryptoKeyAlgorithmParamsType type() const
{
return WebCryptoKeyAlgorithmParamsTypeRsaHashed;
}
private:
WebCryptoAlgorithm m_hash;
};
}
#endif