This source file includes following definitions.
- params
- createNull
- adoptParamsAndCreate
- isNull
- id
- paramsType
- aesCbcParams
- aesCtrParams
- aesKeyGenParams
- hmacImportParams
- hmacKeyGenParams
- rsaKeyGenParams
- aesGcmParams
- rsaOaepParams
- rsaHashedImportParams
- rsaHashedKeyGenParams
- isHash
- assign
- reset
#include "config.h"
#include "public/platform/WebCryptoAlgorithm.h"
#include "public/platform/WebCryptoAlgorithmParams.h"
#include "wtf/OwnPtr.h"
#include "wtf/ThreadSafeRefCounted.h"
namespace blink {
class WebCryptoAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoAlgorithmPrivate> {
public:
WebCryptoAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoAlgorithmParams> params)
: id(id)
, params(params)
{
}
WebCryptoAlgorithmId id;
OwnPtr<WebCryptoAlgorithmParams> params;
};
WebCryptoAlgorithm::WebCryptoAlgorithm(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoAlgorithmParams> params)
: m_private(adoptRef(new WebCryptoAlgorithmPrivate(id, params)))
{
}
WebCryptoAlgorithm WebCryptoAlgorithm::createNull()
{
return WebCryptoAlgorithm();
}
WebCryptoAlgorithm WebCryptoAlgorithm::adoptParamsAndCreate(WebCryptoAlgorithmId id, WebCryptoAlgorithmParams* params)
{
return WebCryptoAlgorithm(id, adoptPtr(params));
}
bool WebCryptoAlgorithm::isNull() const
{
return m_private.isNull();
}
WebCryptoAlgorithmId WebCryptoAlgorithm::id() const
{
ASSERT(!isNull());
return m_private->id;
}
WebCryptoAlgorithmParamsType WebCryptoAlgorithm::paramsType() const
{
ASSERT(!isNull());
if (!m_private->params)
return WebCryptoAlgorithmParamsTypeNone;
return m_private->params->type();
}
const WebCryptoAesCbcParams* WebCryptoAlgorithm::aesCbcParams() const
{
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeAesCbcParams)
return static_cast<WebCryptoAesCbcParams*>(m_private->params.get());
return 0;
}
const WebCryptoAesCtrParams* WebCryptoAlgorithm::aesCtrParams() const
{
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeAesCtrParams)
return static_cast<WebCryptoAesCtrParams*>(m_private->params.get());
return 0;
}
const WebCryptoAesKeyGenParams* WebCryptoAlgorithm::aesKeyGenParams() const
{
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeAesKeyGenParams)
return static_cast<WebCryptoAesKeyGenParams*>(m_private->params.get());
return 0;
}
const WebCryptoHmacImportParams* WebCryptoAlgorithm::hmacImportParams() const
{
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeHmacImportParams)
return static_cast<WebCryptoHmacImportParams*>(m_private->params.get());
return 0;
}
const WebCryptoHmacKeyGenParams* WebCryptoAlgorithm::hmacKeyGenParams() const
{
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeHmacKeyGenParams)
return static_cast<WebCryptoHmacKeyGenParams*>(m_private->params.get());
return 0;
}
const WebCryptoRsaKeyGenParams* WebCryptoAlgorithm::rsaKeyGenParams() const
{
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeRsaKeyGenParams)
return static_cast<WebCryptoRsaKeyGenParams*>(m_private->params.get());
return 0;
}
const WebCryptoAesGcmParams* WebCryptoAlgorithm::aesGcmParams() const
{
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeAesGcmParams)
return static_cast<WebCryptoAesGcmParams*>(m_private->params.get());
return 0;
}
const WebCryptoRsaOaepParams* WebCryptoAlgorithm::rsaOaepParams() const
{
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeRsaOaepParams)
return static_cast<WebCryptoRsaOaepParams*>(m_private->params.get());
return 0;
}
const WebCryptoRsaHashedImportParams* WebCryptoAlgorithm::rsaHashedImportParams() const
{
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeRsaHashedImportParams)
return static_cast<WebCryptoRsaHashedImportParams*>(m_private->params.get());
return 0;
}
const WebCryptoRsaHashedKeyGenParams* WebCryptoAlgorithm::rsaHashedKeyGenParams() const
{
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams)
return static_cast<WebCryptoRsaHashedKeyGenParams*>(m_private->params.get());
return 0;
}
bool WebCryptoAlgorithm::isHash(WebCryptoAlgorithmId id)
{
switch (id) {
case WebCryptoAlgorithmIdSha1:
case WebCryptoAlgorithmIdSha256:
case WebCryptoAlgorithmIdSha384:
case WebCryptoAlgorithmIdSha512:
return true;
case WebCryptoAlgorithmIdAesCbc:
case WebCryptoAlgorithmIdHmac:
case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5:
case WebCryptoAlgorithmIdRsaEsPkcs1v1_5:
case WebCryptoAlgorithmIdAesGcm:
case WebCryptoAlgorithmIdRsaOaep:
case WebCryptoAlgorithmIdAesCtr:
case WebCryptoAlgorithmIdAesKw:
break;
}
return false;
}
void WebCryptoAlgorithm::assign(const WebCryptoAlgorithm& other)
{
m_private = other.m_private;
}
void WebCryptoAlgorithm::reset()
{
m_private.reset();
}
}