OLD | NEW |
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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 exceptionState.throwDOMException(NotSupportedError, "key is not extracta
ble"); | 196 exceptionState.throwDOMException(NotSupportedError, "key is not extracta
ble"); |
197 return ScriptPromise(); | 197 return ScriptPromise(); |
198 } | 198 } |
199 | 199 |
200 ScriptPromise promise = ScriptPromise::createPending(); | 200 ScriptPromise promise = ScriptPromise::createPending(); |
201 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(promise); | 201 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(promise); |
202 blink::Platform::current()->crypto()->exportKey(format, key->key(), result->
result()); | 202 blink::Platform::current()->crypto()->exportKey(format, key->key(), result->
result()); |
203 return promise; | 203 return promise; |
204 } | 204 } |
205 | 205 |
| 206 ScriptPromise SubtleCrypto::wrapKey(const String& rawFormat, Key* key, Key* wrap
pingKey, const Dictionary& rawWrapAlgorithm, ExceptionState& exceptionState) |
| 207 { |
| 208 blink::WebCryptoKeyFormat format; |
| 209 if (!Key::parseFormat(rawFormat, format, exceptionState)) |
| 210 return ScriptPromise(); |
| 211 |
| 212 if (!key) { |
| 213 exceptionState.throwTypeError("Invalid key argument"); |
| 214 return ScriptPromise(); |
| 215 } |
| 216 |
| 217 if (!wrappingKey) { |
| 218 exceptionState.throwTypeError("Invalid wrappingKey argument"); |
| 219 return ScriptPromise(); |
| 220 } |
| 221 |
| 222 blink::WebCryptoAlgorithm wrapAlgorithm; |
| 223 if (!normalizeAlgorithm(rawWrapAlgorithm, WrapKey, wrapAlgorithm, exceptionS
tate)) |
| 224 return ScriptPromise(); |
| 225 |
| 226 if (!key->extractable()) { |
| 227 exceptionState.throwDOMException(NotSupportedError, "key is not extracta
ble"); |
| 228 return ScriptPromise(); |
| 229 } |
| 230 |
| 231 if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, WrapKey, exceptionSta
te)) |
| 232 return ScriptPromise(); |
| 233 |
| 234 ScriptPromise promise = ScriptPromise::createPending(); |
| 235 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(promise); |
| 236 blink::Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKe
y->key(), wrapAlgorithm, result->result()); |
| 237 return promise; |
| 238 } |
| 239 |
| 240 ScriptPromise SubtleCrypto::unwrapKey(const String& rawFormat, ArrayBufferView*
wrappedKey, Key* unwrappingKey, const Dictionary& rawUnwrapAlgorithm, const Dict
ionary& rawUnwrappedKeyAlgorithm, bool extractable, const Vector<String>& rawKey
Usages, ExceptionState& exceptionState) |
| 241 { |
| 242 blink::WebCryptoKeyFormat format; |
| 243 if (!Key::parseFormat(rawFormat, format, exceptionState)) |
| 244 return ScriptPromise(); |
| 245 |
| 246 if (!wrappedKey) { |
| 247 exceptionState.throwTypeError("Invalid wrappedKey argument"); |
| 248 return ScriptPromise(); |
| 249 } |
| 250 |
| 251 if (!unwrappingKey) { |
| 252 exceptionState.throwTypeError("Invalid unwrappingKey argument"); |
| 253 return ScriptPromise(); |
| 254 } |
| 255 |
| 256 blink::WebCryptoAlgorithm unwrapAlgorithm; |
| 257 if (!normalizeAlgorithm(rawUnwrapAlgorithm, UnwrapKey, unwrapAlgorithm, exce
ptionState)) |
| 258 return ScriptPromise(); |
| 259 |
| 260 // The unwrappedKeyAlgorithm is optional. |
| 261 blink::WebCryptoAlgorithm unwrappedKeyAlgorithm; |
| 262 if (!rawUnwrappedKeyAlgorithm.isUndefinedOrNull() && !normalizeAlgorithm(raw
UnwrappedKeyAlgorithm, ImportKey, unwrappedKeyAlgorithm, exceptionState)) |
| 263 return ScriptPromise(); |
| 264 |
| 265 blink::WebCryptoKeyUsageMask keyUsages; |
| 266 if (!Key::parseUsageMask(rawKeyUsages, keyUsages, exceptionState)) |
| 267 return ScriptPromise(); |
| 268 |
| 269 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, UnwrapKey, except
ionState)) |
| 270 return ScriptPromise(); |
| 271 |
| 272 const unsigned char* wrappedKeyData = static_cast<const unsigned char*>(wrap
pedKey->baseAddress()); |
| 273 unsigned wrappedKeyDataSize = wrappedKey->byteLength(); |
| 274 |
| 275 ScriptPromise promise = ScriptPromise::createPending(); |
| 276 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(promise); |
| 277 blink::Platform::current()->crypto()->unwrapKey(format, wrappedKeyData, wrap
pedKeyDataSize, unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, ex
tractable, keyUsages, result->result()); |
| 278 return promise; |
| 279 } |
| 280 |
| 281 |
206 } // namespace WebCore | 282 } // namespace WebCore |
OLD | NEW |