This source file includes following definitions.
- isIntegerArray
- getRandomValues
- subtle
- trace
#include "config.h"
#include "modules/crypto/Crypto.h"
#include "bindings/v8/ExceptionState.h"
#include "core/dom/ExceptionCode.h"
#include "wtf/ArrayBufferView.h"
#include "wtf/CryptographicallyRandomNumber.h"
namespace WebCore {
namespace {
bool isIntegerArray(ArrayBufferView* array)
{
ArrayBufferView::ViewType type = array->type();
return type == ArrayBufferView::TypeInt8
|| type == ArrayBufferView::TypeUint8
|| type == ArrayBufferView::TypeUint8Clamped
|| type == ArrayBufferView::TypeInt16
|| type == ArrayBufferView::TypeUint16
|| type == ArrayBufferView::TypeInt32
|| type == ArrayBufferView::TypeUint32;
}
}
Crypto::Crypto()
{
ScriptWrappable::init(this);
}
void Crypto::getRandomValues(ArrayBufferView* array, ExceptionState& exceptionState)
{
if (!array) {
exceptionState.throwDOMException(TypeMismatchError, "The provided ArrayBufferView is null.");
return;
}
if (!isIntegerArray(array)) {
exceptionState.throwDOMException(TypeMismatchError, String::format("The provided ArrayBufferView is of type '%s', which is not an integer array type.", array->typeName()));
return;
}
if (array->byteLength() > 65536) {
exceptionState.throwDOMException(QuotaExceededError, String::format("The ArrayBufferView's byte length (%u) exceeds the number of bytes of entropy available via this API (65536).", array->byteLength()));
return;
}
cryptographicallyRandomValues(array->baseAddress(), array->byteLength());
}
SubtleCrypto* Crypto::subtle()
{
if (!m_subtleCrypto)
m_subtleCrypto = SubtleCrypto::create();
return m_subtleCrypto.get();
}
void Crypto::trace(Visitor* visitor)
{
visitor->trace(m_subtleCrypto);
}
}