1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "bindings/modules/v8/V8SubtleCrypto.h"
8 #include "bindings/core/v8/Dictionary.h"
9 #include "bindings/core/v8/custom/V8ArrayBufferCustom.h"
10 #include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h"
11 #include "bindings/modules/v8/V8CryptoKey.h"
15 ////////////////////////////////////////////////////////////////////////////////
16 // Overload resolution for verify()
17 // FIXME: needs support for union types http://crbug.com/240176
18 ////////////////////////////////////////////////////////////////////////////////
20 // Promise verify(Dictionary algorithm, CryptoKey key, ArrayBuffer signature, ArrayBuffer data);
21 void verify1Method(const v8::FunctionCallbackInfo<v8::Value>& info)
23 SubtleCrypto* impl = V8SubtleCrypto::toNative(info.Holder());
24 TONATIVE_VOID(Dictionary, algorithm, Dictionary(info[0], info.GetIsolate()));
25 if (!algorithm.isUndefinedOrNull() && !algorithm.isObject()) {
26 V8ThrowException::throwTypeError(ExceptionMessages::failedToExecute("verify", "SubtleCrypto", "parameter 1 ('algorithm') is not an object."), info.GetIsolate());
29 TONATIVE_VOID(CryptoKey*, key, V8CryptoKey::toNativeWithTypeCheck(info.GetIsolate(), info[1]));
30 TONATIVE_VOID(ArrayBuffer*, signature, info[2]->IsArrayBuffer() ? V8ArrayBuffer::toNative(v8::Handle<v8::ArrayBuffer>::Cast(info[2])) : 0);
31 TONATIVE_VOID(ArrayBuffer*, data, info[3]->IsArrayBuffer() ? V8ArrayBuffer::toNative(v8::Handle<v8::ArrayBuffer>::Cast(info[3])) : 0);
32 v8SetReturnValue(info, impl->verifySignature(ScriptState::current(info.GetIsolate()), algorithm, key, signature, data).v8Value());
35 // Promise verify(Dictionary algorithm, CryptoKey key, ArrayBuffer signature, ArrayBufferView data);
36 void verify2Method(const v8::FunctionCallbackInfo<v8::Value>& info)
38 SubtleCrypto* impl = V8SubtleCrypto::toNative(info.Holder());
39 TONATIVE_VOID(Dictionary, algorithm, Dictionary(info[0], info.GetIsolate()));
40 if (!algorithm.isUndefinedOrNull() && !algorithm.isObject()) {
41 V8ThrowException::throwTypeError(ExceptionMessages::failedToExecute("verify", "SubtleCrypto", "parameter 1 ('algorithm') is not an object."), info.GetIsolate());
44 TONATIVE_VOID(CryptoKey*, key, V8CryptoKey::toNativeWithTypeCheck(info.GetIsolate(), info[1]));
45 TONATIVE_VOID(ArrayBuffer*, signature, info[2]->IsArrayBuffer() ? V8ArrayBuffer::toNative(v8::Handle<v8::ArrayBuffer>::Cast(info[2])) : 0);
46 TONATIVE_VOID(ArrayBufferView*, data, info[3]->IsArrayBufferView() ? V8ArrayBufferView::toNative(v8::Handle<v8::ArrayBufferView>::Cast(info[3])) : 0);
47 v8SetReturnValue(info, impl->verifySignature(ScriptState::current(info.GetIsolate()), algorithm, key, signature, data).v8Value());
50 // Promise verify(Dictionary algorithm, CryptoKey key, ArrayBufferView signature, ArrayBuffer data);
51 void verify3Method(const v8::FunctionCallbackInfo<v8::Value>& info)
53 SubtleCrypto* impl = V8SubtleCrypto::toNative(info.Holder());
54 TONATIVE_VOID(Dictionary, algorithm, Dictionary(info[0], info.GetIsolate()));
55 if (!algorithm.isUndefinedOrNull() && !algorithm.isObject()) {
56 V8ThrowException::throwTypeError(ExceptionMessages::failedToExecute("verify", "SubtleCrypto", "parameter 1 ('algorithm') is not an object."), info.GetIsolate());
59 TONATIVE_VOID(CryptoKey*, key, V8CryptoKey::toNativeWithTypeCheck(info.GetIsolate(), info[1]));
60 TONATIVE_VOID(ArrayBufferView*, signature, info[2]->IsArrayBufferView() ? V8ArrayBufferView::toNative(v8::Handle<v8::ArrayBufferView>::Cast(info[2])) : 0);
61 TONATIVE_VOID(ArrayBuffer*, data, info[3]->IsArrayBuffer() ? V8ArrayBuffer::toNative(v8::Handle<v8::ArrayBuffer>::Cast(info[3])) : 0);
62 v8SetReturnValue(info, impl->verifySignature(ScriptState::current(info.GetIsolate()), algorithm, key, signature, data).v8Value());
65 // Promise verify(Dictionary algorithm, CryptoKey key, ArrayBufferView signature, ArrayBufferView data);
66 void verify4Method(const v8::FunctionCallbackInfo<v8::Value>& info)
68 SubtleCrypto* impl = V8SubtleCrypto::toNative(info.Holder());
69 TONATIVE_VOID(Dictionary, algorithm, Dictionary(info[0], info.GetIsolate()));
70 if (!algorithm.isUndefinedOrNull() && !algorithm.isObject()) {
71 V8ThrowException::throwTypeError(ExceptionMessages::failedToExecute("verify", "SubtleCrypto", "parameter 1 ('algorithm') is not an object."), info.GetIsolate());
74 TONATIVE_VOID(CryptoKey*, key, V8CryptoKey::toNativeWithTypeCheck(info.GetIsolate(), info[1]));
75 TONATIVE_VOID(ArrayBufferView*, signature, info[2]->IsArrayBufferView() ? V8ArrayBufferView::toNative(v8::Handle<v8::ArrayBufferView>::Cast(info[2])) : 0);
76 TONATIVE_VOID(ArrayBufferView*, data, info[3]->IsArrayBufferView() ? V8ArrayBufferView::toNative(v8::Handle<v8::ArrayBufferView>::Cast(info[3])) : 0);
77 v8SetReturnValue(info, impl->verifySignature(ScriptState::current(info.GetIsolate()), algorithm, key, signature, data).v8Value());
80 void V8SubtleCrypto::verifyMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
82 v8::Isolate* isolate = info.GetIsolate();
83 ExceptionState exceptionState(ExceptionState::ExecutionContext, "verify", "SubtleCrypto", info.Holder(), isolate);
84 // typedef (ArrayBuffer or ArrayBufferView) CryptoOperationData;
86 // Promise verify(Dictionary algorithm, CryptoKey key,
87 // CryptoOperationData signature,
88 // CryptoOperationData data);
89 switch (info.Length()) {
91 // Promise verify(Dictionary algorithm, CryptoKey key, ArrayBuffer signature, ArrayBuffer data);
92 if (V8ArrayBuffer::hasInstance(info[2], isolate)
93 && V8ArrayBuffer::hasInstance(info[3], isolate)) {
97 // Promise verify(Dictionary algorithm, CryptoKey key, ArrayBuffer signature, ArrayBufferView data);
98 if (V8ArrayBuffer::hasInstance(info[2], isolate)
99 && V8ArrayBufferView::hasInstance(info[3], isolate)) {
103 // Promise verify(Dictionary algorithm, CryptoKey key, ArrayBufferView signature, ArrayBuffer data);
104 if (V8ArrayBufferView::hasInstance(info[2], isolate)
105 && V8ArrayBuffer::hasInstance(info[3], isolate)) {
109 // Promise verify(Dictionary algorithm, CryptoKey key, ArrayBufferView signature, ArrayBufferView data);
110 if (V8ArrayBufferView::hasInstance(info[2], isolate)
111 && V8ArrayBufferView::hasInstance(info[3], isolate)) {
117 setArityTypeError(exceptionState, "[4]", info.Length());
118 exceptionState.throwIfNeeded();
122 exceptionState.throwTypeError("No function was found that matched the signature provided.");
123 exceptionState.throwIfNeeded();