OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "config.h" | |
6 #include "bindings/modules/v8/V8SubtleCrypto.h" | |
7 | |
8 #include "bindings/modules/v8/V8Key.h" | |
9 #include "bindings/v8/Dictionary.h" | |
10 #include "bindings/v8/custom/V8ArrayBufferCustom.h" | |
11 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" | |
12 | |
13 namespace WebCore { | |
14 | |
15 //////////////////////////////////////////////////////////////////////////////// | |
16 // Overload resolution for verify() | |
17 // FIXME: needs support for union types http://crbug.com/240176 | |
18 //////////////////////////////////////////////////////////////////////////////// | |
19 | |
20 // Promise verify(Dictionary algorithm, Key key, ArrayBuffer signature, ArrayBuf
fer data); | |
21 void verify1Method(const v8::FunctionCallbackInfo<v8::Value>& info) | |
22 { | |
23 SubtleCrypto* impl = V8SubtleCrypto::toNative(info.Holder()); | |
24 TONATIVE_VOID(Dictionary, algorithm, Dictionary(info[0], info.GetIsolate()))
; | |
25 if (!algorithm.isUndefinedOrNull() && !algorithm.isObject()) { | |
26 throwTypeError(ExceptionMessages::failedToExecute("verify", "SubtleCrypt
o", "parameter 1 ('algorithm') is not an object."), info.GetIsolate()); | |
27 return; | |
28 } | |
29 TONATIVE_VOID(Key*, key, V8Key::toNativeWithTypeCheck(info.GetIsolate(), inf
o[1])); | |
30 TONATIVE_VOID(ArrayBuffer*, signature, info[2]->IsArrayBuffer() ? V8ArrayBuf
fer::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.GetIs
olate()), algorithm, key, signature, data).v8Value()); | |
33 } | |
34 | |
35 // Promise verify(Dictionary algorithm, Key key, ArrayBuffer signature, ArrayBuf
ferView data); | |
36 void verify2Method(const v8::FunctionCallbackInfo<v8::Value>& info) | |
37 { | |
38 SubtleCrypto* impl = V8SubtleCrypto::toNative(info.Holder()); | |
39 TONATIVE_VOID(Dictionary, algorithm, Dictionary(info[0], info.GetIsolate()))
; | |
40 if (!algorithm.isUndefinedOrNull() && !algorithm.isObject()) { | |
41 throwTypeError(ExceptionMessages::failedToExecute("verify", "SubtleCrypt
o", "parameter 1 ('algorithm') is not an object."), info.GetIsolate()); | |
42 return; | |
43 } | |
44 TONATIVE_VOID(Key*, key, V8Key::toNativeWithTypeCheck(info.GetIsolate(), inf
o[1])); | |
45 TONATIVE_VOID(ArrayBuffer*, signature, info[2]->IsArrayBuffer() ? V8ArrayBuf
fer::toNative(v8::Handle<v8::ArrayBuffer>::Cast(info[2])) : 0); | |
46 TONATIVE_VOID(ArrayBufferView*, data, info[3]->IsArrayBufferView() ? V8Array
BufferView::toNative(v8::Handle<v8::ArrayBufferView>::Cast(info[3])) : 0); | |
47 v8SetReturnValue(info, impl->verifySignature(ScriptState::current(info.GetIs
olate()), algorithm, key, signature, data).v8Value()); | |
48 } | |
49 | |
50 // Promise verify(Dictionary algorithm, Key key, ArrayBufferView signature, Arra
yBuffer data); | |
51 void verify3Method(const v8::FunctionCallbackInfo<v8::Value>& info) | |
52 { | |
53 SubtleCrypto* impl = V8SubtleCrypto::toNative(info.Holder()); | |
54 TONATIVE_VOID(Dictionary, algorithm, Dictionary(info[0], info.GetIsolate()))
; | |
55 if (!algorithm.isUndefinedOrNull() && !algorithm.isObject()) { | |
56 throwTypeError(ExceptionMessages::failedToExecute("verify", "SubtleCrypt
o", "parameter 1 ('algorithm') is not an object."), info.GetIsolate()); | |
57 return; | |
58 } | |
59 TONATIVE_VOID(Key*, key, V8Key::toNativeWithTypeCheck(info.GetIsolate(), inf
o[1])); | |
60 TONATIVE_VOID(ArrayBufferView*, signature, info[2]->IsArrayBufferView() ? V8
ArrayBufferView::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.GetIs
olate()), algorithm, key, signature, data).v8Value()); | |
63 } | |
64 | |
65 // Promise verify(Dictionary algorithm, Key key, ArrayBufferView signature, Arra
yBufferView data); | |
66 void verify4Method(const v8::FunctionCallbackInfo<v8::Value>& info) | |
67 { | |
68 SubtleCrypto* impl = V8SubtleCrypto::toNative(info.Holder()); | |
69 TONATIVE_VOID(Dictionary, algorithm, Dictionary(info[0], info.GetIsolate()))
; | |
70 if (!algorithm.isUndefinedOrNull() && !algorithm.isObject()) { | |
71 throwTypeError(ExceptionMessages::failedToExecute("verify", "SubtleCrypt
o", "parameter 1 ('algorithm') is not an object."), info.GetIsolate()); | |
72 return; | |
73 } | |
74 TONATIVE_VOID(Key*, key, V8Key::toNativeWithTypeCheck(info.GetIsolate(), inf
o[1])); | |
75 TONATIVE_VOID(ArrayBufferView*, signature, info[2]->IsArrayBufferView() ? V8
ArrayBufferView::toNative(v8::Handle<v8::ArrayBufferView>::Cast(info[2])) : 0); | |
76 TONATIVE_VOID(ArrayBufferView*, data, info[3]->IsArrayBufferView() ? V8Array
BufferView::toNative(v8::Handle<v8::ArrayBufferView>::Cast(info[3])) : 0); | |
77 v8SetReturnValue(info, impl->verifySignature(ScriptState::current(info.GetIs
olate()), algorithm, key, signature, data).v8Value()); | |
78 } | |
79 | |
80 void V8SubtleCrypto::verifyMethodCustom(const v8::FunctionCallbackInfo<v8::Value
>& info) | |
81 { | |
82 v8::Isolate* isolate = info.GetIsolate(); | |
83 ExceptionState exceptionState(ExceptionState::ExecutionContext, "verify", "S
ubtleCrypto", info.Holder(), isolate); | |
84 // typedef (ArrayBuffer or ArrayBufferView) CryptoOperationData; | |
85 // | |
86 // Promise verify(Dictionary algorithm, Key key, | |
87 // CryptoOperationData signature, | |
88 // CryptoOperationData data); | |
89 switch (info.Length()) { | |
90 case 4: | |
91 // Promise verify(Dictionary algorithm, Key key, ArrayBuffer signature,
ArrayBuffer data); | |
92 if (V8ArrayBuffer::hasInstance(info[2], isolate) | |
93 && V8ArrayBuffer::hasInstance(info[3], isolate)) { | |
94 verify1Method(info); | |
95 return; | |
96 } | |
97 // Promise verify(Dictionary algorithm, Key key, ArrayBuffer signature,
ArrayBufferView data); | |
98 if (V8ArrayBuffer::hasInstance(info[2], isolate) | |
99 && V8ArrayBufferView::hasInstance(info[3], isolate)) { | |
100 verify2Method(info); | |
101 return; | |
102 } | |
103 // Promise verify(Dictionary algorithm, Key key, ArrayBufferView signatu
re, ArrayBuffer data); | |
104 if (V8ArrayBufferView::hasInstance(info[2], isolate) | |
105 && V8ArrayBuffer::hasInstance(info[3], isolate)) { | |
106 verify3Method(info); | |
107 return; | |
108 } | |
109 // Promise verify(Dictionary algorithm, Key key, ArrayBufferView signatu
re, ArrayBufferView data); | |
110 if (V8ArrayBufferView::hasInstance(info[2], isolate) | |
111 && V8ArrayBufferView::hasInstance(info[3], isolate)) { | |
112 verify4Method(info); | |
113 return; | |
114 } | |
115 break; | |
116 default: | |
117 throwArityTypeError(exceptionState, "[4]", info.Length()); | |
118 return; | |
119 break; | |
120 } | |
121 exceptionState.throwTypeError("No function was found that matched the signat
ure provided."); | |
122 exceptionState.throwIfNeeded(); | |
123 } | |
124 | |
125 } // namespace WebCore | |
OLD | NEW |