| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 if (bufferSource.isArrayBuffer()) { | 52 if (bufferSource.isArrayBuffer()) { |
| 53 data = bufferSource.getAsArrayBuffer()->data(); | 53 data = bufferSource.getAsArrayBuffer()->data(); |
| 54 len = bufferSource.getAsArrayBuffer()->byteLength(); | 54 len = bufferSource.getAsArrayBuffer()->byteLength(); |
| 55 } else if (bufferSource.isArrayBufferView()) { | 55 } else if (bufferSource.isArrayBufferView()) { |
| 56 data = bufferSource.getAsArrayBufferView()->baseAddress(); | 56 data = bufferSource.getAsArrayBufferView()->baseAddress(); |
| 57 len = bufferSource.getAsArrayBufferView()->byteLength(); | 57 len = bufferSource.getAsArrayBufferView()->byteLength(); |
| 58 } | 58 } |
| 59 initWithData(data, len); | 59 initWithData(data, len); |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Seems like the generated bindings should take care of these however it | |
| 63 // currently doesn't. See also http://crbug.com/264520 | |
| 64 static bool ensureNotNull(const DOMArrayPiece& x, const char* paramName, CryptoR
esult* result) | |
| 65 { | |
| 66 if (x.isNull()) { | |
| 67 String message = String("Invalid ") + paramName + String(" argument"); | |
| 68 result->completeWithError(WebCryptoErrorTypeType, WebString(message)); | |
| 69 return false; | |
| 70 } | |
| 71 return true; | |
| 72 } | |
| 73 | |
| 74 static bool ensureNotNull(const ArrayBufferOrArrayBufferViewOrDictionary& dictio
nary, const char* paramName, CryptoResult* result) | |
| 75 { | |
| 76 if (dictionary.isNull()) { | |
| 77 String message = String("Invalid ") + paramName + String(" argument"); | |
| 78 result->completeWithError(WebCryptoErrorTypeType, WebString(message)); | |
| 79 return false; | |
| 80 } | |
| 81 return true; | |
| 82 } | |
| 83 | |
| 84 static bool ensureNotNull(CryptoKey* key, const char* paramName, CryptoResult* r
esult) | |
| 85 { | |
| 86 if (!key) { | |
| 87 String message = String("Invalid ") + paramName + String(" argument"); | |
| 88 result->completeWithError(WebCryptoErrorTypeType, WebString(message)); | |
| 89 return false; | |
| 90 } | |
| 91 return true; | |
| 92 } | |
| 93 | |
| 94 static bool parseAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op
, WebCryptoAlgorithm& algorithm, CryptoResult* result) | 62 static bool parseAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op
, WebCryptoAlgorithm& algorithm, CryptoResult* result) |
| 95 { | 63 { |
| 96 AlgorithmError error; | 64 AlgorithmError error; |
| 97 bool success = normalizeAlgorithm(raw, op, algorithm, &error); | 65 bool success = normalizeAlgorithm(raw, op, algorithm, &error); |
| 98 if (!success) | 66 if (!success) |
| 99 result->completeWithError(error.errorType, error.errorDetails); | 67 result->completeWithError(error.errorType, error.errorDetails); |
| 100 return success; | 68 return success; |
| 101 } | 69 } |
| 102 | 70 |
| 103 static bool canAccessWebCrypto(ScriptState* scriptState, CryptoResult* result) | 71 static bool canAccessWebCrypto(ScriptState* scriptState, CryptoResult* result) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 136 } |
| 169 | 137 |
| 170 ScriptPromise SubtleCrypto::encrypt(ScriptState* scriptState, const AlgorithmIde
ntifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) | 138 ScriptPromise SubtleCrypto::encrypt(ScriptState* scriptState, const AlgorithmIde
ntifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) |
| 171 { | 139 { |
| 172 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); | 140 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); |
| 173 ScriptPromise promise = result->promise(); | 141 ScriptPromise promise = result->promise(); |
| 174 | 142 |
| 175 if (!canAccessWebCrypto(scriptState, result.get())) | 143 if (!canAccessWebCrypto(scriptState, result.get())) |
| 176 return promise; | 144 return promise; |
| 177 | 145 |
| 178 if (!ensureNotNull(key, "key", result.get())) | |
| 179 return promise; | |
| 180 if (!ensureNotNull(data, "dataBuffer", result.get())) | |
| 181 return promise; | |
| 182 | |
| 183 WebCryptoAlgorithm algorithm; | 146 WebCryptoAlgorithm algorithm; |
| 184 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationEncrypt, algorithm, resu
lt.get())) | 147 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationEncrypt, algorithm, resu
lt.get())) |
| 185 return promise; | 148 return promise; |
| 186 | 149 |
| 187 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageEncrypt, result.
get())) | 150 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageEncrypt, result.
get())) |
| 188 return promise; | 151 return promise; |
| 189 | 152 |
| 190 Platform::current()->crypto()->encrypt(algorithm, key->key(), data.bytes(),
data.byteLength(), result->result()); | 153 Platform::current()->crypto()->encrypt(algorithm, key->key(), data.bytes(),
data.byteLength(), result->result()); |
| 191 return promise; | 154 return promise; |
| 192 } | 155 } |
| 193 | 156 |
| 194 ScriptPromise SubtleCrypto::decrypt(ScriptState* scriptState, const AlgorithmIde
ntifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) | 157 ScriptPromise SubtleCrypto::decrypt(ScriptState* scriptState, const AlgorithmIde
ntifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) |
| 195 { | 158 { |
| 196 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); | 159 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); |
| 197 ScriptPromise promise = result->promise(); | 160 ScriptPromise promise = result->promise(); |
| 198 | 161 |
| 199 if (!canAccessWebCrypto(scriptState, result.get())) | 162 if (!canAccessWebCrypto(scriptState, result.get())) |
| 200 return promise; | 163 return promise; |
| 201 | 164 |
| 202 if (!ensureNotNull(key, "key", result.get())) | |
| 203 return promise; | |
| 204 if (!ensureNotNull(data, "dataBuffer", result.get())) | |
| 205 return promise; | |
| 206 | |
| 207 WebCryptoAlgorithm algorithm; | 165 WebCryptoAlgorithm algorithm; |
| 208 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDecrypt, algorithm, resu
lt.get())) | 166 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDecrypt, algorithm, resu
lt.get())) |
| 209 return promise; | 167 return promise; |
| 210 | 168 |
| 211 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDecrypt, result.
get())) | 169 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDecrypt, result.
get())) |
| 212 return promise; | 170 return promise; |
| 213 | 171 |
| 214 Platform::current()->crypto()->decrypt(algorithm, key->key(), data.bytes(),
data.byteLength(), result->result()); | 172 Platform::current()->crypto()->decrypt(algorithm, key->key(), data.bytes(),
data.byteLength(), result->result()); |
| 215 return promise; | 173 return promise; |
| 216 } | 174 } |
| 217 | 175 |
| 218 ScriptPromise SubtleCrypto::sign(ScriptState* scriptState, const AlgorithmIdenti
fier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) | 176 ScriptPromise SubtleCrypto::sign(ScriptState* scriptState, const AlgorithmIdenti
fier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) |
| 219 { | 177 { |
| 220 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); | 178 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); |
| 221 ScriptPromise promise = result->promise(); | 179 ScriptPromise promise = result->promise(); |
| 222 | 180 |
| 223 if (!canAccessWebCrypto(scriptState, result.get())) | 181 if (!canAccessWebCrypto(scriptState, result.get())) |
| 224 return promise; | 182 return promise; |
| 225 | 183 |
| 226 if (!ensureNotNull(key, "key", result.get())) | |
| 227 return promise; | |
| 228 if (!ensureNotNull(data, "dataBuffer", result.get())) | |
| 229 return promise; | |
| 230 | |
| 231 WebCryptoAlgorithm algorithm; | 184 WebCryptoAlgorithm algorithm; |
| 232 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationSign, algorithm, result.
get())) | 185 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationSign, algorithm, result.
get())) |
| 233 return promise; | 186 return promise; |
| 234 | 187 |
| 235 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageSign, result.get
())) | 188 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageSign, result.get
())) |
| 236 return promise; | 189 return promise; |
| 237 | 190 |
| 238 Platform::current()->crypto()->sign(algorithm, key->key(), data.bytes(), dat
a.byteLength(), result->result()); | 191 Platform::current()->crypto()->sign(algorithm, key->key(), data.bytes(), dat
a.byteLength(), result->result()); |
| 239 return promise; | 192 return promise; |
| 240 } | 193 } |
| 241 | 194 |
| 242 ScriptPromise SubtleCrypto::verifySignature(ScriptState* scriptState, const Algo
rithmIdentifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& signature, c
onst DOMArrayPiece& data) | 195 ScriptPromise SubtleCrypto::verifySignature(ScriptState* scriptState, const Algo
rithmIdentifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& signature, c
onst DOMArrayPiece& data) |
| 243 { | 196 { |
| 244 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); | 197 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); |
| 245 ScriptPromise promise = result->promise(); | 198 ScriptPromise promise = result->promise(); |
| 246 | 199 |
| 247 if (!canAccessWebCrypto(scriptState, result.get())) | 200 if (!canAccessWebCrypto(scriptState, result.get())) |
| 248 return promise; | 201 return promise; |
| 249 | 202 |
| 250 if (!ensureNotNull(key, "key", result.get())) | |
| 251 return promise; | |
| 252 if (!ensureNotNull(data, "dataBuffer", result.get())) | |
| 253 return promise; | |
| 254 if (!ensureNotNull(signature, "signature", result.get())) | |
| 255 return promise; | |
| 256 | |
| 257 WebCryptoAlgorithm algorithm; | 203 WebCryptoAlgorithm algorithm; |
| 258 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationVerify, algorithm, resul
t.get())) | 204 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationVerify, algorithm, resul
t.get())) |
| 259 return promise; | 205 return promise; |
| 260 | 206 |
| 261 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageVerify, result.g
et())) | 207 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageVerify, result.g
et())) |
| 262 return promise; | 208 return promise; |
| 263 | 209 |
| 264 Platform::current()->crypto()->verifySignature(algorithm, key->key(), signat
ure.bytes(), signature.byteLength(), data.bytes(), data.byteLength(), result->re
sult()); | 210 Platform::current()->crypto()->verifySignature(algorithm, key->key(), signat
ure.bytes(), signature.byteLength(), data.bytes(), data.byteLength(), result->re
sult()); |
| 265 return promise; | 211 return promise; |
| 266 } | 212 } |
| 267 | 213 |
| 268 ScriptPromise SubtleCrypto::digest(ScriptState* scriptState, const AlgorithmIden
tifier& rawAlgorithm, const DOMArrayPiece& data) | 214 ScriptPromise SubtleCrypto::digest(ScriptState* scriptState, const AlgorithmIden
tifier& rawAlgorithm, const DOMArrayPiece& data) |
| 269 { | 215 { |
| 270 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); | 216 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); |
| 271 ScriptPromise promise = result->promise(); | 217 ScriptPromise promise = result->promise(); |
| 272 | 218 |
| 273 if (!canAccessWebCrypto(scriptState, result.get())) | 219 if (!canAccessWebCrypto(scriptState, result.get())) |
| 274 return promise; | 220 return promise; |
| 275 | 221 |
| 276 if (!ensureNotNull(data, "dataBuffer", result.get())) | |
| 277 return promise; | |
| 278 | |
| 279 WebCryptoAlgorithm algorithm; | 222 WebCryptoAlgorithm algorithm; |
| 280 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDigest, algorithm, resul
t.get())) | 223 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDigest, algorithm, resul
t.get())) |
| 281 return promise; | 224 return promise; |
| 282 | 225 |
| 283 Platform::current()->crypto()->digest(algorithm, data.bytes(), data.byteLeng
th(), result->result()); | 226 Platform::current()->crypto()->digest(algorithm, data.bytes(), data.byteLeng
th(), result->result()); |
| 284 return promise; | 227 return promise; |
| 285 } | 228 } |
| 286 | 229 |
| 287 ScriptPromise SubtleCrypto::generateKey(ScriptState* scriptState, const Algorith
mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) | 230 ScriptPromise SubtleCrypto::generateKey(ScriptState* scriptState, const Algorith
mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) |
| 288 { | 231 { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 305 } | 248 } |
| 306 | 249 |
| 307 ScriptPromise SubtleCrypto::importKey(ScriptState* scriptState, const String& ra
wFormat, const ArrayBufferOrArrayBufferViewOrDictionary& keyData, const Algorith
mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) | 250 ScriptPromise SubtleCrypto::importKey(ScriptState* scriptState, const String& ra
wFormat, const ArrayBufferOrArrayBufferViewOrDictionary& keyData, const Algorith
mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) |
| 308 { | 251 { |
| 309 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); | 252 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); |
| 310 ScriptPromise promise = result->promise(); | 253 ScriptPromise promise = result->promise(); |
| 311 | 254 |
| 312 if (!canAccessWebCrypto(scriptState, result.get())) | 255 if (!canAccessWebCrypto(scriptState, result.get())) |
| 313 return promise; | 256 return promise; |
| 314 | 257 |
| 315 if (!ensureNotNull(keyData, "keyData", result.get())) | |
| 316 return promise; | |
| 317 | |
| 318 WebCryptoKeyFormat format; | 258 WebCryptoKeyFormat format; |
| 319 if (!CryptoKey::parseFormat(rawFormat, format, result.get())) | 259 if (!CryptoKey::parseFormat(rawFormat, format, result.get())) |
| 320 return promise; | 260 return promise; |
| 321 | 261 |
| 322 if (keyData.isDictionary()) { | 262 if (keyData.isDictionary()) { |
| 323 if (format != WebCryptoKeyFormatJwk) { | 263 if (format != WebCryptoKeyFormatJwk) { |
| 324 result->completeWithError(WebCryptoErrorTypeData, "Key data must be
a buffer for non-JWK formats"); | 264 result->completeWithError(WebCryptoErrorTypeData, "Key data must be
a buffer for non-JWK formats"); |
| 325 return promise; | 265 return promise; |
| 326 } | 266 } |
| 327 } else if (format == WebCryptoKeyFormatJwk) { | 267 } else if (format == WebCryptoKeyFormatJwk) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 358 } | 298 } |
| 359 | 299 |
| 360 ScriptPromise SubtleCrypto::exportKey(ScriptState* scriptState, const String& ra
wFormat, CryptoKey* key) | 300 ScriptPromise SubtleCrypto::exportKey(ScriptState* scriptState, const String& ra
wFormat, CryptoKey* key) |
| 361 { | 301 { |
| 362 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); | 302 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); |
| 363 ScriptPromise promise = result->promise(); | 303 ScriptPromise promise = result->promise(); |
| 364 | 304 |
| 365 if (!canAccessWebCrypto(scriptState, result.get())) | 305 if (!canAccessWebCrypto(scriptState, result.get())) |
| 366 return promise; | 306 return promise; |
| 367 | 307 |
| 368 if (!ensureNotNull(key, "key", result.get())) | |
| 369 return promise; | |
| 370 | |
| 371 WebCryptoKeyFormat format; | 308 WebCryptoKeyFormat format; |
| 372 if (!CryptoKey::parseFormat(rawFormat, format, result.get())) | 309 if (!CryptoKey::parseFormat(rawFormat, format, result.get())) |
| 373 return promise; | 310 return promise; |
| 374 | 311 |
| 375 if (!key->extractable()) { | 312 if (!key->extractable()) { |
| 376 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key is not e
xtractable"); | 313 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key is not e
xtractable"); |
| 377 return promise; | 314 return promise; |
| 378 } | 315 } |
| 379 | 316 |
| 380 Platform::current()->crypto()->exportKey(format, key->key(), result->result(
)); | 317 Platform::current()->crypto()->exportKey(format, key->key(), result->result(
)); |
| 381 return promise; | 318 return promise; |
| 382 } | 319 } |
| 383 | 320 |
| 384 ScriptPromise SubtleCrypto::wrapKey(ScriptState* scriptState, const String& rawF
ormat, CryptoKey* key, CryptoKey* wrappingKey, const AlgorithmIdentifier& rawWra
pAlgorithm) | 321 ScriptPromise SubtleCrypto::wrapKey(ScriptState* scriptState, const String& rawF
ormat, CryptoKey* key, CryptoKey* wrappingKey, const AlgorithmIdentifier& rawWra
pAlgorithm) |
| 385 { | 322 { |
| 386 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); | 323 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); |
| 387 ScriptPromise promise = result->promise(); | 324 ScriptPromise promise = result->promise(); |
| 388 | 325 |
| 389 if (!canAccessWebCrypto(scriptState, result.get())) | 326 if (!canAccessWebCrypto(scriptState, result.get())) |
| 390 return promise; | 327 return promise; |
| 391 | 328 |
| 392 if (!ensureNotNull(key, "key", result.get())) | |
| 393 return promise; | |
| 394 | |
| 395 if (!ensureNotNull(wrappingKey, "wrappingKey", result.get())) | |
| 396 return promise; | |
| 397 | |
| 398 WebCryptoKeyFormat format; | 329 WebCryptoKeyFormat format; |
| 399 if (!CryptoKey::parseFormat(rawFormat, format, result.get())) | 330 if (!CryptoKey::parseFormat(rawFormat, format, result.get())) |
| 400 return promise; | 331 return promise; |
| 401 | 332 |
| 402 WebCryptoAlgorithm wrapAlgorithm; | 333 WebCryptoAlgorithm wrapAlgorithm; |
| 403 if (!parseAlgorithm(rawWrapAlgorithm, WebCryptoOperationWrapKey, wrapAlgorit
hm, result.get())) | 334 if (!parseAlgorithm(rawWrapAlgorithm, WebCryptoOperationWrapKey, wrapAlgorit
hm, result.get())) |
| 404 return promise; | 335 return promise; |
| 405 | 336 |
| 406 if (!key->extractable()) { | 337 if (!key->extractable()) { |
| 407 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key is not e
xtractable"); | 338 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key is not e
xtractable"); |
| 408 return promise; | 339 return promise; |
| 409 } | 340 } |
| 410 | 341 |
| 411 if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, WebCryptoKeyUsageWrap
Key, result.get())) | 342 if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, WebCryptoKeyUsageWrap
Key, result.get())) |
| 412 return promise; | 343 return promise; |
| 413 | 344 |
| 414 Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKey->key(
), wrapAlgorithm, result->result()); | 345 Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKey->key(
), wrapAlgorithm, result->result()); |
| 415 return promise; | 346 return promise; |
| 416 } | 347 } |
| 417 | 348 |
| 418 ScriptPromise SubtleCrypto::unwrapKey(ScriptState* scriptState, const String& ra
wFormat, const DOMArrayPiece& wrappedKey, CryptoKey* unwrappingKey, const Algori
thmIdentifier& rawUnwrapAlgorithm, const AlgorithmIdentifier& rawUnwrappedKeyAlg
orithm, bool extractable, const Vector<String>& rawKeyUsages) | 349 ScriptPromise SubtleCrypto::unwrapKey(ScriptState* scriptState, const String& ra
wFormat, const DOMArrayPiece& wrappedKey, CryptoKey* unwrappingKey, const Algori
thmIdentifier& rawUnwrapAlgorithm, const AlgorithmIdentifier& rawUnwrappedKeyAlg
orithm, bool extractable, const Vector<String>& rawKeyUsages) |
| 419 { | 350 { |
| 420 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); | 351 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); |
| 421 ScriptPromise promise = result->promise(); | 352 ScriptPromise promise = result->promise(); |
| 422 | 353 |
| 423 if (!canAccessWebCrypto(scriptState, result.get())) | 354 if (!canAccessWebCrypto(scriptState, result.get())) |
| 424 return promise; | 355 return promise; |
| 425 | 356 |
| 426 if (!ensureNotNull(wrappedKey, "wrappedKey", result.get())) | |
| 427 return promise; | |
| 428 if (!ensureNotNull(unwrappingKey, "unwrappingKey", result.get())) | |
| 429 return promise; | |
| 430 | |
| 431 WebCryptoKeyFormat format; | 357 WebCryptoKeyFormat format; |
| 432 if (!CryptoKey::parseFormat(rawFormat, format, result.get())) | 358 if (!CryptoKey::parseFormat(rawFormat, format, result.get())) |
| 433 return promise; | 359 return promise; |
| 434 | 360 |
| 435 WebCryptoKeyUsageMask keyUsages; | 361 WebCryptoKeyUsageMask keyUsages; |
| 436 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result.get())) | 362 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result.get())) |
| 437 return promise; | 363 return promise; |
| 438 | 364 |
| 439 WebCryptoAlgorithm unwrapAlgorithm; | 365 WebCryptoAlgorithm unwrapAlgorithm; |
| 440 if (!parseAlgorithm(rawUnwrapAlgorithm, WebCryptoOperationUnwrapKey, unwrapA
lgorithm, result.get())) | 366 if (!parseAlgorithm(rawUnwrapAlgorithm, WebCryptoOperationUnwrapKey, unwrapA
lgorithm, result.get())) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 452 } | 378 } |
| 453 | 379 |
| 454 ScriptPromise SubtleCrypto::deriveBits(ScriptState* scriptState, const Algorithm
Identifier& rawAlgorithm, CryptoKey* baseKey, unsigned lengthBits) | 380 ScriptPromise SubtleCrypto::deriveBits(ScriptState* scriptState, const Algorithm
Identifier& rawAlgorithm, CryptoKey* baseKey, unsigned lengthBits) |
| 455 { | 381 { |
| 456 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); | 382 RefPtrWillBeRawPtr<CryptoResultImpl> result = CryptoResultImpl::create(scrip
tState); |
| 457 ScriptPromise promise = result->promise(); | 383 ScriptPromise promise = result->promise(); |
| 458 | 384 |
| 459 if (!canAccessWebCrypto(scriptState, result.get())) | 385 if (!canAccessWebCrypto(scriptState, result.get())) |
| 460 return promise; | 386 return promise; |
| 461 | 387 |
| 462 if (!ensureNotNull(baseKey, "baseKey", result.get())) | |
| 463 return promise; | |
| 464 | |
| 465 WebCryptoAlgorithm algorithm; | 388 WebCryptoAlgorithm algorithm; |
| 466 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDeriveBits, algorithm, r
esult.get())) | 389 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDeriveBits, algorithm, r
esult.get())) |
| 467 return promise; | 390 return promise; |
| 468 | 391 |
| 469 if (!baseKey->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDeriveBits,
result.get())) | 392 if (!baseKey->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDeriveBits,
result.get())) |
| 470 return promise; | 393 return promise; |
| 471 | 394 |
| 472 Platform::current()->crypto()->deriveBits(algorithm, baseKey->key(), lengthB
its, result->result()); | 395 Platform::current()->crypto()->deriveBits(algorithm, baseKey->key(), lengthB
its, result->result()); |
| 473 return promise; | 396 return promise; |
| 474 } | 397 } |
| 475 | 398 |
| 476 ScriptPromise SubtleCrypto::deriveKey(ScriptState* scriptState, const AlgorithmI
dentifier& rawAlgorithm, CryptoKey* baseKey, const AlgorithmIdentifier& rawDeriv
edKeyType, bool extractable, const Vector<String>& rawKeyUsages) | 399 ScriptPromise SubtleCrypto::deriveKey(ScriptState* scriptState, const AlgorithmI
dentifier& rawAlgorithm, CryptoKey* baseKey, const AlgorithmIdentifier& rawDeriv
edKeyType, bool extractable, const Vector<String>& rawKeyUsages) |
| 477 { | 400 { |
| 478 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(scriptState); | 401 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(scriptState); |
| 479 ScriptPromise promise = result->promise(); | 402 ScriptPromise promise = result->promise(); |
| 480 | 403 |
| 481 if (!canAccessWebCrypto(scriptState, result.get())) | 404 if (!canAccessWebCrypto(scriptState, result.get())) |
| 482 return promise; | 405 return promise; |
| 483 | 406 |
| 484 if (!ensureNotNull(baseKey, "baseKey", result.get())) | |
| 485 return promise; | |
| 486 | |
| 487 WebCryptoKeyUsageMask keyUsages; | 407 WebCryptoKeyUsageMask keyUsages; |
| 488 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result.get())) | 408 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result.get())) |
| 489 return promise; | 409 return promise; |
| 490 | 410 |
| 491 WebCryptoAlgorithm algorithm; | 411 WebCryptoAlgorithm algorithm; |
| 492 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDeriveBits, algorithm, r
esult.get())) | 412 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDeriveBits, algorithm, r
esult.get())) |
| 493 return promise; | 413 return promise; |
| 494 | 414 |
| 495 if (!baseKey->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDeriveKey, r
esult.get())) | 415 if (!baseKey->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDeriveKey, r
esult.get())) |
| 496 return promise; | 416 return promise; |
| 497 | 417 |
| 498 WebCryptoAlgorithm importAlgorithm; | 418 WebCryptoAlgorithm importAlgorithm; |
| 499 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationImportKey, importAl
gorithm, result.get())) | 419 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationImportKey, importAl
gorithm, result.get())) |
| 500 return promise; | 420 return promise; |
| 501 | 421 |
| 502 WebCryptoAlgorithm keyLengthAlgorithm; | 422 WebCryptoAlgorithm keyLengthAlgorithm; |
| 503 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationGetKeyLength, keyLe
ngthAlgorithm, result.get())) | 423 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationGetKeyLength, keyLe
ngthAlgorithm, result.get())) |
| 504 return promise; | 424 return promise; |
| 505 | 425 |
| 506 Platform::current()->crypto()->deriveKey(algorithm, baseKey->key(), importAl
gorithm, keyLengthAlgorithm, extractable, keyUsages, result->result()); | 426 Platform::current()->crypto()->deriveKey(algorithm, baseKey->key(), importAl
gorithm, keyLengthAlgorithm, extractable, keyUsages, result->result()); |
| 507 return promise; | 427 return promise; |
| 508 } | 428 } |
| 509 | 429 |
| 510 } // namespace blink | 430 } // namespace blink |
| OLD | NEW |