Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(661)

Side by Side Diff: Source/modules/crypto/SubtleCrypto.cpp

Issue 243853004: [webcrypto] Reject failed operations with a DOMException rather than null. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix compile warning Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/crypto/NormalizeAlgorithm.cpp ('k') | Source/platform/CryptoResult.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 namespace { 45 namespace {
46 46
47 // Seems like the generated bindings should take care of these however it 47 // Seems like the generated bindings should take care of these however it
48 // currently doesn't. See also http://crbug.com/264520 48 // currently doesn't. See also http://crbug.com/264520
49 template <typename T> 49 template <typename T>
50 bool ensureNotNull(T* x, const char* paramName, CryptoResult* result) 50 bool ensureNotNull(T* x, const char* paramName, CryptoResult* result)
51 { 51 {
52 if (!x) { 52 if (!x) {
53 String message = String("Invalid ") + paramName + String(" argument"); 53 String message = String("Invalid ") + paramName + String(" argument");
54 result->completeWithError(blink::WebString(message)); 54 result->completeWithError(blink::WebCryptoErrorTypeType, blink::WebStrin g(message));
55 return false; 55 return false;
56 } 56 }
57 return true; 57 return true;
58 } 58 }
59 59
60 ScriptPromise startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, Alg orithmOperation operationType, ArrayBufferView* signature, ArrayBufferView* data Buffer) 60 ScriptPromise startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, Alg orithmOperation operationType, ArrayBufferView* signature, ArrayBufferView* data Buffer)
61 { 61 {
62 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(); 62 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create();
63 ScriptPromise promise = result->promise(); 63 ScriptPromise promise = result->promise();
64 64
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 ScriptPromise promise = result->promise(); 186 ScriptPromise promise = result->promise();
187 187
188 if (!ensureNotNull(key, "key", result.get())) 188 if (!ensureNotNull(key, "key", result.get()))
189 return promise; 189 return promise;
190 190
191 blink::WebCryptoKeyFormat format; 191 blink::WebCryptoKeyFormat format;
192 if (!Key::parseFormat(rawFormat, format, result.get())) 192 if (!Key::parseFormat(rawFormat, format, result.get()))
193 return promise; 193 return promise;
194 194
195 if (!key->extractable()) { 195 if (!key->extractable()) {
196 result->completeWithError("key is not extractable"); 196 result->completeWithError(blink::WebCryptoErrorTypeInvalidAccess, "key i s not extractable");
197 return promise; 197 return promise;
198 } 198 }
199 199
200 blink::Platform::current()->crypto()->exportKey(format, key->key(), result-> result()); 200 blink::Platform::current()->crypto()->exportKey(format, key->key(), result-> result());
201 return promise; 201 return promise;
202 } 202 }
203 203
204 ScriptPromise SubtleCrypto::wrapKey(const String& rawFormat, Key* key, Key* wrap pingKey, const Dictionary& rawWrapAlgorithm) 204 ScriptPromise SubtleCrypto::wrapKey(const String& rawFormat, Key* key, Key* wrap pingKey, const Dictionary& rawWrapAlgorithm)
205 { 205 {
206 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(); 206 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create();
207 ScriptPromise promise = result->promise(); 207 ScriptPromise promise = result->promise();
208 208
209 if (!ensureNotNull(key, "key", result.get())) 209 if (!ensureNotNull(key, "key", result.get()))
210 return promise; 210 return promise;
211 211
212 if (!ensureNotNull(wrappingKey, "wrappingKey", result.get())) 212 if (!ensureNotNull(wrappingKey, "wrappingKey", result.get()))
213 return promise; 213 return promise;
214 214
215 blink::WebCryptoKeyFormat format; 215 blink::WebCryptoKeyFormat format;
216 if (!Key::parseFormat(rawFormat, format, result.get())) 216 if (!Key::parseFormat(rawFormat, format, result.get()))
217 return promise; 217 return promise;
218 218
219 blink::WebCryptoAlgorithm wrapAlgorithm; 219 blink::WebCryptoAlgorithm wrapAlgorithm;
220 if (!parseAlgorithm(rawWrapAlgorithm, WrapKey, wrapAlgorithm, result.get())) 220 if (!parseAlgorithm(rawWrapAlgorithm, WrapKey, wrapAlgorithm, result.get()))
221 return promise; 221 return promise;
222 222
223 if (!key->extractable()) { 223 if (!key->extractable()) {
224 result->completeWithError("key is not extractable"); 224 result->completeWithError(blink::WebCryptoErrorTypeInvalidAccess, "key i s not extractable");
225 return promise; 225 return promise;
226 } 226 }
227 227
228 if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, WrapKey, result.get() )) 228 if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, WrapKey, result.get() ))
229 return promise; 229 return promise;
230 230
231 blink::Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKe y->key(), wrapAlgorithm, result->result()); 231 blink::Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKe y->key(), wrapAlgorithm, result->result());
232 return promise; 232 return promise;
233 } 233 }
234 234
(...skipping 27 matching lines...) Expand all
262 return promise; 262 return promise;
263 263
264 const unsigned char* wrappedKeyData = static_cast<const unsigned char*>(wrap pedKey->baseAddress()); 264 const unsigned char* wrappedKeyData = static_cast<const unsigned char*>(wrap pedKey->baseAddress());
265 unsigned wrappedKeyDataSize = wrappedKey->byteLength(); 265 unsigned wrappedKeyDataSize = wrappedKey->byteLength();
266 266
267 blink::Platform::current()->crypto()->unwrapKey(format, wrappedKeyData, wrap pedKeyDataSize, unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, ex tractable, keyUsages, result->result()); 267 blink::Platform::current()->crypto()->unwrapKey(format, wrappedKeyData, wrap pedKeyDataSize, unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, ex tractable, keyUsages, result->result());
268 return promise; 268 return promise;
269 } 269 }
270 270
271 } // namespace WebCore 271 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/crypto/NormalizeAlgorithm.cpp ('k') | Source/platform/CryptoResult.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698