| 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 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "modules/crypto/NormalizeAlgorithm.h" | 32 #include "modules/crypto/NormalizeAlgorithm.h" |
| 33 | 33 |
| 34 #include "bindings/v8/Dictionary.h" | 34 #include "bindings/v8/Dictionary.h" |
| 35 #include "platform/CryptoResult.h" | |
| 36 #include "platform/NotImplemented.h" | 35 #include "platform/NotImplemented.h" |
| 37 #include "public/platform/WebCryptoAlgorithmParams.h" | 36 #include "public/platform/WebCryptoAlgorithmParams.h" |
| 38 #include "public/platform/WebString.h" | 37 #include "public/platform/WebString.h" |
| 39 #include "wtf/ArrayBuffer.h" | 38 #include "wtf/ArrayBuffer.h" |
| 40 #include "wtf/ArrayBufferView.h" | 39 #include "wtf/ArrayBufferView.h" |
| 41 #include "wtf/MathExtras.h" | 40 #include "wtf/MathExtras.h" |
| 42 #include "wtf/Uint8Array.h" | 41 #include "wtf/Uint8Array.h" |
| 43 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
| 44 #include "wtf/text/StringBuilder.h" | 43 #include "wtf/text/StringBuilder.h" |
| 45 #include <algorithm> | 44 #include <algorithm> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 78 |
| 80 typedef char ParamsTypeOrUndefined; | 79 typedef char ParamsTypeOrUndefined; |
| 81 const ParamsTypeOrUndefined Undefined = -1; | 80 const ParamsTypeOrUndefined Undefined = -1; |
| 82 | 81 |
| 83 struct AlgorithmInfo { | 82 struct AlgorithmInfo { |
| 84 // The canonical (case-sensitive) name for the algorithm. | 83 // The canonical (case-sensitive) name for the algorithm. |
| 85 const char* name; | 84 const char* name; |
| 86 | 85 |
| 87 // A map from the operation to the expected parameter type of the algorithm. | 86 // A map from the operation to the expected parameter type of the algorithm. |
| 88 // If an operation is not applicable for the algorithm, set to Undefined. | 87 // If an operation is not applicable for the algorithm, set to Undefined. |
| 89 const ParamsTypeOrUndefined operationToParamsType[LastAlgorithmOperation + 1
]; | 88 const ParamsTypeOrUndefined operationToParamsType[blink::LastAlgorithmOperat
ion + 1]; |
| 90 }; | 89 }; |
| 91 | 90 |
| 92 // A mapping from the algorithm ID to information about the algorithm. | 91 // A mapping from the algorithm ID to information about the algorithm. |
| 93 const AlgorithmInfo algorithmIdToInfo[] = { | 92 const AlgorithmInfo algorithmIdToInfo[] = { |
| 94 { // Index 0 | 93 { // Index 0 |
| 95 "AES-CBC", { | 94 "AES-CBC", { |
| 96 blink::WebCryptoAlgorithmParamsTypeAesCbcParams, // Encrypt | 95 blink::WebCryptoAlgorithmParamsTypeAesCbcParams, // Encrypt |
| 97 blink::WebCryptoAlgorithmParamsTypeAesCbcParams, // Decrypt | 96 blink::WebCryptoAlgorithmParamsTypeAesCbcParams, // Decrypt |
| 98 Undefined, // Sign | 97 Undefined, // Sign |
| 99 Undefined, // Verify | 98 Undefined, // Verify |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5 == 3, RsaEsPkcs1v1_5_id
DoesntMatch); | 270 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5 == 3, RsaEsPkcs1v1_5_id
DoesntMatch); |
| 272 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdSha1 == 4, Sha1_idDoesntMatch); | 271 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdSha1 == 4, Sha1_idDoesntMatch); |
| 273 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdSha256 == 5, Sha256_idDoesntMatch); | 272 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdSha256 == 5, Sha256_idDoesntMatch); |
| 274 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdSha384 == 6, Sha384_idDoesntMatch); | 273 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdSha384 == 6, Sha384_idDoesntMatch); |
| 275 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdSha512 == 7, Sha512_idDoesntMatch); | 274 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdSha512 == 7, Sha512_idDoesntMatch); |
| 276 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdAesGcm == 8, AesGcm_idDoesntMatch); | 275 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdAesGcm == 8, AesGcm_idDoesntMatch); |
| 277 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdRsaOaep == 9, RsaOaep_idDoesntMatch); | 276 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdRsaOaep == 9, RsaOaep_idDoesntMatch); |
| 278 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdAesCtr == 10, AesCtr_idDoesntMatch); | 277 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdAesCtr == 10, AesCtr_idDoesntMatch); |
| 279 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdAesKw == 11, AesKw_idDoesntMatch); | 278 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdAesKw == 11, AesKw_idDoesntMatch); |
| 280 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdLast == 11, Last_idDoesntMatch); | 279 COMPILE_ASSERT(blink::WebCryptoAlgorithmIdLast == 11, Last_idDoesntMatch); |
| 281 COMPILE_ASSERT(10 == LastAlgorithmOperation, UpdateParamsMapping); | 280 COMPILE_ASSERT(10 == blink::LastAlgorithmOperation, UpdateParamsMapping); |
| 282 | 281 |
| 283 #if ASSERT_ENABLED | 282 #if ASSERT_ENABLED |
| 284 | 283 |
| 285 // Essentially std::is_sorted() (however that function is new to C++11). | 284 // Essentially std::is_sorted() (however that function is new to C++11). |
| 286 template <typename Iterator> | 285 template <typename Iterator> |
| 287 bool isSorted(Iterator begin, Iterator end) | 286 bool isSorted(Iterator begin, Iterator end) |
| 288 { | 287 { |
| 289 if (begin == end) | 288 if (begin == end) |
| 290 return true; | 289 return true; |
| 291 | 290 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 return true; | 388 return true; |
| 390 } | 389 } |
| 391 | 390 |
| 392 const AlgorithmInfo* lookupAlgorithmInfo(blink::WebCryptoAlgorithmId id) | 391 const AlgorithmInfo* lookupAlgorithmInfo(blink::WebCryptoAlgorithmId id) |
| 393 { | 392 { |
| 394 if (id < 0 || id >= WTF_ARRAY_LENGTH(algorithmIdToInfo)) | 393 if (id < 0 || id >= WTF_ARRAY_LENGTH(algorithmIdToInfo)) |
| 395 return 0; | 394 return 0; |
| 396 return &algorithmIdToInfo[id]; | 395 return &algorithmIdToInfo[id]; |
| 397 } | 396 } |
| 398 | 397 |
| 399 void completeWithSyntaxError(const String& message, CryptoResult* result) | 398 void setSyntaxError(const String& message, AlgorithmError* error) |
| 400 { | 399 { |
| 401 result->completeWithError(blink::WebCryptoErrorTypeSyntax, message); | 400 error->errorType = blink::WebCryptoErrorTypeSyntax; |
| 401 error->errorDetails = message; |
| 402 } | 402 } |
| 403 | 403 |
| 404 void completeWithNotSupportedError(const String& message, CryptoResult* result) | 404 void setNotSupportedError(const String& message, AlgorithmError* error) |
| 405 { | 405 { |
| 406 result->completeWithError(blink::WebCryptoErrorTypeNotSupported, message); | 406 error->errorType = blink::WebCryptoErrorTypeNotSupported; |
| 407 error->errorDetails = message; |
| 407 } | 408 } |
| 408 | 409 |
| 409 void completeWithDataError(const String& message, CryptoResult* result) | 410 void setDataError(const String& message, AlgorithmError* error) |
| 410 { | 411 { |
| 411 result->completeWithError(blink::WebCryptoErrorTypeData, message); | 412 error->errorType = blink::WebCryptoErrorTypeData; |
| 413 error->errorDetails = message; |
| 412 } | 414 } |
| 413 | 415 |
| 414 // ErrorContext holds a stack of string literals which describe what was | 416 // ErrorContext holds a stack of string literals which describe what was |
| 415 // happening at the time the error occurred. This is helpful because | 417 // happening at the time the error occurred. This is helpful because |
| 416 // parsing of the algorithm dictionary can be recursive and it is difficult to | 418 // parsing of the algorithm dictionary can be recursive and it is difficult to |
| 417 // tell what went wrong from a failure alone. | 419 // tell what went wrong from a failure alone. |
| 418 class ErrorContext { | 420 class ErrorContext { |
| 419 public: | 421 public: |
| 420 void add(const char* message) | 422 void add(const char* message) |
| 421 { | 423 { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 // This inline size is large enough to avoid having to grow the Vector in | 471 // This inline size is large enough to avoid having to grow the Vector in |
| 470 // the majority of cases (up to 1 nested algorithm identifier). | 472 // the majority of cases (up to 1 nested algorithm identifier). |
| 471 Vector<const char*, 10> m_messages; | 473 Vector<const char*, 10> m_messages; |
| 472 }; | 474 }; |
| 473 | 475 |
| 474 // Defined by the WebCrypto spec as: | 476 // Defined by the WebCrypto spec as: |
| 475 // | 477 // |
| 476 // typedef (ArrayBuffer or ArrayBufferView) CryptoOperationData; | 478 // typedef (ArrayBuffer or ArrayBufferView) CryptoOperationData; |
| 477 // | 479 // |
| 478 // FIXME: Currently only supports ArrayBufferView. | 480 // FIXME: Currently only supports ArrayBufferView. |
| 479 bool getOptionalCryptoOperationData(const Dictionary& raw, const char* propertyN
ame, bool& hasProperty, RefPtr<ArrayBufferView>& buffer, const ErrorContext& con
text, CryptoResult* result) | 481 bool getOptionalCryptoOperationData(const Dictionary& raw, const char* propertyN
ame, bool& hasProperty, RefPtr<ArrayBufferView>& buffer, const ErrorContext& con
text, AlgorithmError* error) |
| 480 { | 482 { |
| 481 if (!raw.get(propertyName, buffer)) { | 483 if (!raw.get(propertyName, buffer)) { |
| 482 hasProperty = false; | 484 hasProperty = false; |
| 483 return true; | 485 return true; |
| 484 } | 486 } |
| 485 | 487 |
| 486 hasProperty = true; | 488 hasProperty = true; |
| 487 | 489 |
| 488 if (!buffer) { | 490 if (!buffer) { |
| 489 completeWithSyntaxError(context.toString(propertyName, "Not an ArrayBuff
erView"), result); | 491 setSyntaxError(context.toString(propertyName, "Not an ArrayBufferView"),
error); |
| 490 return false; | 492 return false; |
| 491 } | 493 } |
| 492 | 494 |
| 493 return true; | 495 return true; |
| 494 } | 496 } |
| 495 | 497 |
| 496 // Defined by the WebCrypto spec as: | 498 // Defined by the WebCrypto spec as: |
| 497 // | 499 // |
| 498 // typedef (ArrayBuffer or ArrayBufferView) CryptoOperationData; | 500 // typedef (ArrayBuffer or ArrayBufferView) CryptoOperationData; |
| 499 // | 501 // |
| 500 // FIXME: Currently only supports ArrayBufferView. | 502 // FIXME: Currently only supports ArrayBufferView. |
| 501 bool getCryptoOperationData(const Dictionary& raw, const char* propertyName, Ref
Ptr<ArrayBufferView>& buffer, const ErrorContext& context, CryptoResult* result) | 503 bool getCryptoOperationData(const Dictionary& raw, const char* propertyName, Ref
Ptr<ArrayBufferView>& buffer, const ErrorContext& context, AlgorithmError* error
) |
| 502 { | 504 { |
| 503 bool hasProperty; | 505 bool hasProperty; |
| 504 bool ok = getOptionalCryptoOperationData(raw, propertyName, hasProperty, buf
fer, context, result); | 506 bool ok = getOptionalCryptoOperationData(raw, propertyName, hasProperty, buf
fer, context, error); |
| 505 if (!hasProperty) { | 507 if (!hasProperty) { |
| 506 completeWithSyntaxError(context.toString(propertyName, "Missing required
property"), result); | 508 setSyntaxError(context.toString(propertyName, "Missing required property
"), error); |
| 507 return false; | 509 return false; |
| 508 } | 510 } |
| 509 return ok; | 511 return ok; |
| 510 } | 512 } |
| 511 | 513 |
| 512 bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ErrorContext& context, CryptoResult* result) | 514 bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ErrorContext& context, AlgorithmError* error) |
| 513 { | 515 { |
| 514 if (!raw.get(propertyName, array) || !array) { | 516 if (!raw.get(propertyName, array) || !array) { |
| 515 completeWithSyntaxError(context.toString(propertyName, "Missing or not a
Uint8Array"), result); | 517 setSyntaxError(context.toString(propertyName, "Missing or not a Uint8Arr
ay"), error); |
| 516 return false; | 518 return false; |
| 517 } | 519 } |
| 518 return true; | 520 return true; |
| 519 } | 521 } |
| 520 | 522 |
| 521 // Defined by the WebCrypto spec as: | 523 // Defined by the WebCrypto spec as: |
| 522 // | 524 // |
| 523 // typedef Uint8Array BigInteger; | 525 // typedef Uint8Array BigInteger; |
| 524 bool getBigInteger(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ErrorContext& context, CryptoResult* result) | 526 bool getBigInteger(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ErrorContext& context, AlgorithmError* error) |
| 525 { | 527 { |
| 526 if (!getUint8Array(raw, propertyName, array, context, result)) | 528 if (!getUint8Array(raw, propertyName, array, context, error)) |
| 527 return false; | 529 return false; |
| 528 | 530 |
| 529 if (!array->byteLength()) { | 531 if (!array->byteLength()) { |
| 530 completeWithSyntaxError(context.toString(propertyName, "BigInteger shoul
d not be empty"), result); | 532 setSyntaxError(context.toString(propertyName, "BigInteger should not be
empty"), error); |
| 531 return false; | 533 return false; |
| 532 } | 534 } |
| 533 | 535 |
| 534 if (!raw.get(propertyName, array) || !array) { | 536 if (!raw.get(propertyName, array) || !array) { |
| 535 completeWithSyntaxError(context.toString(propertyName, "Missing or not a
Uint8Array"), result); | 537 setSyntaxError(context.toString(propertyName, "Missing or not a Uint8Arr
ay"), error); |
| 536 return false; | 538 return false; |
| 537 } | 539 } |
| 538 return true; | 540 return true; |
| 539 } | 541 } |
| 540 | 542 |
| 541 // Gets an integer according to WebIDL's [EnforceRange]. | 543 // Gets an integer according to WebIDL's [EnforceRange]. |
| 542 bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& h
asProperty, double& value, double minValue, double maxValue, const ErrorContext&
context, CryptoResult* result) | 544 bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& h
asProperty, double& value, double minValue, double maxValue, const ErrorContext&
context, AlgorithmError* error) |
| 543 { | 545 { |
| 544 double number; | 546 double number; |
| 545 bool ok = raw.get(propertyName, number, hasProperty); | 547 bool ok = raw.get(propertyName, number, hasProperty); |
| 546 | 548 |
| 547 if (!hasProperty) | 549 if (!hasProperty) |
| 548 return true; | 550 return true; |
| 549 | 551 |
| 550 if (!ok || std::isnan(number)) { | 552 if (!ok || std::isnan(number)) { |
| 551 completeWithSyntaxError(context.toString(propertyName, "Is not a number"
), result); | 553 setSyntaxError(context.toString(propertyName, "Is not a number"), error)
; |
| 552 return false; | 554 return false; |
| 553 } | 555 } |
| 554 | 556 |
| 555 number = trunc(number); | 557 number = trunc(number); |
| 556 | 558 |
| 557 if (std::isinf(number) || number < minValue || number > maxValue) { | 559 if (std::isinf(number) || number < minValue || number > maxValue) { |
| 558 completeWithSyntaxError(context.toString(propertyName, "Outside of numer
ic range"), result); | 560 setSyntaxError(context.toString(propertyName, "Outside of numeric range"
), error); |
| 559 return false; | 561 return false; |
| 560 } | 562 } |
| 561 | 563 |
| 562 value = number; | 564 value = number; |
| 563 return true; | 565 return true; |
| 564 } | 566 } |
| 565 | 567 |
| 566 bool getInteger(const Dictionary& raw, const char* propertyName, double& value,
double minValue, double maxValue, const ErrorContext& context, CryptoResult* res
ult) | 568 bool getInteger(const Dictionary& raw, const char* propertyName, double& value,
double minValue, double maxValue, const ErrorContext& context, AlgorithmError* e
rror) |
| 567 { | 569 { |
| 568 bool hasProperty; | 570 bool hasProperty; |
| 569 if (!getOptionalInteger(raw, propertyName, hasProperty, value, minValue, max
Value, context, result)) | 571 if (!getOptionalInteger(raw, propertyName, hasProperty, value, minValue, max
Value, context, error)) |
| 570 return false; | 572 return false; |
| 571 | 573 |
| 572 if (!hasProperty) { | 574 if (!hasProperty) { |
| 573 completeWithSyntaxError(context.toString(propertyName, "Missing required
property"), result); | 575 setSyntaxError(context.toString(propertyName, "Missing required property
"), error); |
| 574 return false; | 576 return false; |
| 575 } | 577 } |
| 576 | 578 |
| 577 return true; | 579 return true; |
| 578 } | 580 } |
| 579 | 581 |
| 580 bool getUint32(const Dictionary& raw, const char* propertyName, uint32_t& value,
const ErrorContext& context, CryptoResult* result) | 582 bool getUint32(const Dictionary& raw, const char* propertyName, uint32_t& value,
const ErrorContext& context, AlgorithmError* error) |
| 581 { | 583 { |
| 582 double number; | 584 double number; |
| 583 if (!getInteger(raw, propertyName, number, 0, 0xFFFFFFFF, context, result)) | 585 if (!getInteger(raw, propertyName, number, 0, 0xFFFFFFFF, context, error)) |
| 584 return false; | 586 return false; |
| 585 value = number; | 587 value = number; |
| 586 return true; | 588 return true; |
| 587 } | 589 } |
| 588 | 590 |
| 589 bool getUint16(const Dictionary& raw, const char* propertyName, uint16_t& value,
const ErrorContext& context, CryptoResult* result) | 591 bool getUint16(const Dictionary& raw, const char* propertyName, uint16_t& value,
const ErrorContext& context, AlgorithmError* error) |
| 590 { | 592 { |
| 591 double number; | 593 double number; |
| 592 if (!getInteger(raw, propertyName, number, 0, 0xFFFF, context, result)) | 594 if (!getInteger(raw, propertyName, number, 0, 0xFFFF, context, error)) |
| 593 return false; | 595 return false; |
| 594 value = number; | 596 value = number; |
| 595 return true; | 597 return true; |
| 596 } | 598 } |
| 597 | 599 |
| 598 bool getUint8(const Dictionary& raw, const char* propertyName, uint8_t& value, c
onst ErrorContext& context, CryptoResult* result) | 600 bool getUint8(const Dictionary& raw, const char* propertyName, uint8_t& value, c
onst ErrorContext& context, AlgorithmError* error) |
| 599 { | 601 { |
| 600 double number; | 602 double number; |
| 601 if (!getInteger(raw, propertyName, number, 0, 0xFF, context, result)) | 603 if (!getInteger(raw, propertyName, number, 0, 0xFF, context, error)) |
| 602 return false; | 604 return false; |
| 603 value = number; | 605 value = number; |
| 604 return true; | 606 return true; |
| 605 } | 607 } |
| 606 | 608 |
| 607 bool getOptionalUint32(const Dictionary& raw, const char* propertyName, bool& ha
sValue, uint32_t& value, const ErrorContext& context, CryptoResult* result) | 609 bool getOptionalUint32(const Dictionary& raw, const char* propertyName, bool& ha
sValue, uint32_t& value, const ErrorContext& context, AlgorithmError* error) |
| 608 { | 610 { |
| 609 double number; | 611 double number; |
| 610 if (!getOptionalInteger(raw, propertyName, hasValue, number, 0, 0xFFFFFFFF,
context, result)) | 612 if (!getOptionalInteger(raw, propertyName, hasValue, number, 0, 0xFFFFFFFF,
context, error)) |
| 611 return false; | 613 return false; |
| 612 if (hasValue) | 614 if (hasValue) |
| 613 value = number; | 615 value = number; |
| 614 return true; | 616 return true; |
| 615 } | 617 } |
| 616 | 618 |
| 617 // Defined by the WebCrypto spec as: | 619 // Defined by the WebCrypto spec as: |
| 618 // | 620 // |
| 619 // dictionary AesCbcParams : Algorithm { | 621 // dictionary AesCbcParams : Algorithm { |
| 620 // CryptoOperationData iv; | 622 // CryptoOperationData iv; |
| 621 // }; | 623 // }; |
| 622 bool parseAesCbcParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, CryptoResult* result) | 624 bool parseAesCbcParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, AlgorithmError* error) |
| 623 { | 625 { |
| 624 RefPtr<ArrayBufferView> iv; | 626 RefPtr<ArrayBufferView> iv; |
| 625 if (!getCryptoOperationData(raw, "iv", iv, context, result)) | 627 if (!getCryptoOperationData(raw, "iv", iv, context, error)) |
| 626 return false; | 628 return false; |
| 627 | 629 |
| 628 if (iv->byteLength() != 16) { | 630 if (iv->byteLength() != 16) { |
| 629 completeWithDataError(context.toString("iv", "Must be 16 bytes"), result
); | 631 setDataError(context.toString("iv", "Must be 16 bytes"), error); |
| 630 return false; | 632 return false; |
| 631 } | 633 } |
| 632 | 634 |
| 633 params = adoptPtr(new blink::WebCryptoAesCbcParams(static_cast<unsigned char
*>(iv->baseAddress()), iv->byteLength())); | 635 params = adoptPtr(new blink::WebCryptoAesCbcParams(static_cast<unsigned char
*>(iv->baseAddress()), iv->byteLength())); |
| 634 return true; | 636 return true; |
| 635 } | 637 } |
| 636 | 638 |
| 637 // Defined by the WebCrypto spec as: | 639 // Defined by the WebCrypto spec as: |
| 638 // | 640 // |
| 639 // dictionary AesKeyGenParams : Algorithm { | 641 // dictionary AesKeyGenParams : Algorithm { |
| 640 // [EnforceRange] unsigned short length; | 642 // [EnforceRange] unsigned short length; |
| 641 // }; | 643 // }; |
| 642 bool parseAesKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, CryptoResult* result) | 644 bool parseAesKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, AlgorithmError* error) |
| 643 { | 645 { |
| 644 uint16_t length; | 646 uint16_t length; |
| 645 if (!getUint16(raw, "length", length, context, result)) | 647 if (!getUint16(raw, "length", length, context, error)) |
| 646 return false; | 648 return false; |
| 647 | 649 |
| 648 params = adoptPtr(new blink::WebCryptoAesKeyGenParams(length)); | 650 params = adoptPtr(new blink::WebCryptoAesKeyGenParams(length)); |
| 649 return true; | 651 return true; |
| 650 } | 652 } |
| 651 | 653 |
| 652 bool parseAlgorithm(const Dictionary&, AlgorithmOperation, blink::WebCryptoAlgor
ithm&, ErrorContext, CryptoResult*); | 654 bool parseAlgorithm(const Dictionary&, blink::AlgorithmOperation, blink::WebCryp
toAlgorithm&, ErrorContext, AlgorithmError*); |
| 653 | 655 |
| 654 bool parseHash(const Dictionary& raw, blink::WebCryptoAlgorithm& hash, ErrorCont
ext context, CryptoResult* result) | 656 bool parseHash(const Dictionary& raw, blink::WebCryptoAlgorithm& hash, ErrorCont
ext context, AlgorithmError* error) |
| 655 { | 657 { |
| 656 Dictionary rawHash; | 658 Dictionary rawHash; |
| 657 if (!raw.get("hash", rawHash)) { | 659 if (!raw.get("hash", rawHash)) { |
| 658 completeWithSyntaxError(context.toString("hash", "Missing or not a dicti
onary"), result); | 660 setSyntaxError(context.toString("hash", "Missing or not a dictionary"),
error); |
| 659 return false; | 661 return false; |
| 660 } | 662 } |
| 661 | 663 |
| 662 context.add("hash"); | 664 context.add("hash"); |
| 663 return parseAlgorithm(rawHash, Digest, hash, context, result); | 665 return parseAlgorithm(rawHash, blink::Digest, hash, context, error); |
| 664 } | 666 } |
| 665 | 667 |
| 666 // Defined by the WebCrypto spec as: | 668 // Defined by the WebCrypto spec as: |
| 667 // | 669 // |
| 668 // dictionary HmacImportParams : Algorithm { | 670 // dictionary HmacImportParams : Algorithm { |
| 669 // AlgorithmIdentifier hash; | 671 // AlgorithmIdentifier hash; |
| 670 // }; | 672 // }; |
| 671 bool parseHmacImportParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorit
hmParams>& params, const ErrorContext& context, CryptoResult* result) | 673 bool parseHmacImportParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorit
hmParams>& params, const ErrorContext& context, AlgorithmError* error) |
| 672 { | 674 { |
| 673 blink::WebCryptoAlgorithm hash; | 675 blink::WebCryptoAlgorithm hash; |
| 674 if (!parseHash(raw, hash, context, result)) | 676 if (!parseHash(raw, hash, context, error)) |
| 675 return false; | 677 return false; |
| 676 | 678 |
| 677 params = adoptPtr(new blink::WebCryptoHmacImportParams(hash)); | 679 params = adoptPtr(new blink::WebCryptoHmacImportParams(hash)); |
| 678 return true; | 680 return true; |
| 679 } | 681 } |
| 680 | 682 |
| 681 // Defined by the WebCrypto spec as: | 683 // Defined by the WebCrypto spec as: |
| 682 // | 684 // |
| 683 // dictionary HmacKeyGenParams : Algorithm { | 685 // dictionary HmacKeyGenParams : Algorithm { |
| 684 // AlgorithmIdentifier hash; | 686 // AlgorithmIdentifier hash; |
| 685 // // The length (in bits) of the key to generate. If unspecified, the | 687 // // The length (in bits) of the key to generate. If unspecified, the |
| 686 // // recommended length will be used, which is the size of the associated
hash function's block | 688 // // recommended length will be used, which is the size of the associated
hash function's block |
| 687 // // size. | 689 // // size. |
| 688 // unsigned long length; | 690 // unsigned long length; |
| 689 // }; | 691 // }; |
| 690 bool parseHmacKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorit
hmParams>& params, const ErrorContext& context, CryptoResult* result) | 692 bool parseHmacKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorit
hmParams>& params, const ErrorContext& context, AlgorithmError* error) |
| 691 { | 693 { |
| 692 blink::WebCryptoAlgorithm hash; | 694 blink::WebCryptoAlgorithm hash; |
| 693 if (!parseHash(raw, hash, context, result)) | 695 if (!parseHash(raw, hash, context, error)) |
| 694 return false; | 696 return false; |
| 695 | 697 |
| 696 bool hasLength; | 698 bool hasLength; |
| 697 uint32_t length = 0; | 699 uint32_t length = 0; |
| 698 if (!getOptionalUint32(raw, "length", hasLength, length, context, result)) | 700 if (!getOptionalUint32(raw, "length", hasLength, length, context, error)) |
| 699 return false; | 701 return false; |
| 700 | 702 |
| 701 params = adoptPtr(new blink::WebCryptoHmacKeyGenParams(hash, hasLength, leng
th)); | 703 params = adoptPtr(new blink::WebCryptoHmacKeyGenParams(hash, hasLength, leng
th)); |
| 702 return true; | 704 return true; |
| 703 } | 705 } |
| 704 | 706 |
| 705 // Defined by the WebCrypto spec as: | 707 // Defined by the WebCrypto spec as: |
| 706 // | 708 // |
| 707 // dictionary RsaHashedImportParams { | 709 // dictionary RsaHashedImportParams { |
| 708 // AlgorithmIdentifier hash; | 710 // AlgorithmIdentifier hash; |
| 709 // }; | 711 // }; |
| 710 bool parseRsaHashedImportParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAl
gorithmParams>& params, const ErrorContext& context, CryptoResult* result) | 712 bool parseRsaHashedImportParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAl
gorithmParams>& params, const ErrorContext& context, AlgorithmError* error) |
| 711 { | 713 { |
| 712 blink::WebCryptoAlgorithm hash; | 714 blink::WebCryptoAlgorithm hash; |
| 713 if (!parseHash(raw, hash, context, result)) | 715 if (!parseHash(raw, hash, context, error)) |
| 714 return false; | 716 return false; |
| 715 | 717 |
| 716 params = adoptPtr(new blink::WebCryptoRsaHashedImportParams(hash)); | 718 params = adoptPtr(new blink::WebCryptoRsaHashedImportParams(hash)); |
| 717 return true; | 719 return true; |
| 718 } | 720 } |
| 719 | 721 |
| 720 // Defined by the WebCrypto spec as: | 722 // Defined by the WebCrypto spec as: |
| 721 // | 723 // |
| 722 // dictionary RsaKeyGenParams : Algorithm { | 724 // dictionary RsaKeyGenParams : Algorithm { |
| 723 // unsigned long modulusLength; | 725 // unsigned long modulusLength; |
| 724 // BigInteger publicExponent; | 726 // BigInteger publicExponent; |
| 725 // }; | 727 // }; |
| 726 bool parseRsaKeyGenParams(const Dictionary& raw, uint32_t& modulusLength, RefPtr
<Uint8Array>& publicExponent, const ErrorContext& context, CryptoResult* result) | 728 bool parseRsaKeyGenParams(const Dictionary& raw, uint32_t& modulusLength, RefPtr
<Uint8Array>& publicExponent, const ErrorContext& context, AlgorithmError* error
) |
| 727 { | 729 { |
| 728 if (!getUint32(raw, "modulusLength", modulusLength, context, result)) | 730 if (!getUint32(raw, "modulusLength", modulusLength, context, error)) |
| 729 return false; | 731 return false; |
| 730 | 732 |
| 731 if (!getBigInteger(raw, "publicExponent", publicExponent, context, result)) | 733 if (!getBigInteger(raw, "publicExponent", publicExponent, context, error)) |
| 732 return false; | 734 return false; |
| 733 | 735 |
| 734 return true; | 736 return true; |
| 735 } | 737 } |
| 736 | 738 |
| 737 bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, CryptoResult* result) | 739 bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, AlgorithmError* error) |
| 738 { | 740 { |
| 739 uint32_t modulusLength; | 741 uint32_t modulusLength; |
| 740 RefPtr<Uint8Array> publicExponent; | 742 RefPtr<Uint8Array> publicExponent; |
| 741 if (!parseRsaKeyGenParams(raw, modulusLength, publicExponent, context, resul
t)) | 743 if (!parseRsaKeyGenParams(raw, modulusLength, publicExponent, context, error
)) |
| 742 return false; | 744 return false; |
| 743 | 745 |
| 744 params = adoptPtr(new blink::WebCryptoRsaKeyGenParams(modulusLength, static_
cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteL
ength())); | 746 params = adoptPtr(new blink::WebCryptoRsaKeyGenParams(modulusLength, static_
cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteL
ength())); |
| 745 return true; | 747 return true; |
| 746 } | 748 } |
| 747 | 749 |
| 748 // Defined by the WebCrypto spec as: | 750 // Defined by the WebCrypto spec as: |
| 749 // | 751 // |
| 750 // dictionary RsaHashedKeyGenParams : RsaKeyGenParams { | 752 // dictionary RsaHashedKeyGenParams : RsaKeyGenParams { |
| 751 // AlgorithmIdentifier hash; | 753 // AlgorithmIdentifier hash; |
| 752 // }; | 754 // }; |
| 753 bool parseRsaHashedKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAl
gorithmParams>& params, const ErrorContext& context, CryptoResult* result) | 755 bool parseRsaHashedKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAl
gorithmParams>& params, const ErrorContext& context, AlgorithmError* error) |
| 754 { | 756 { |
| 755 uint32_t modulusLength; | 757 uint32_t modulusLength; |
| 756 RefPtr<Uint8Array> publicExponent; | 758 RefPtr<Uint8Array> publicExponent; |
| 757 if (!parseRsaKeyGenParams(raw, modulusLength, publicExponent, context, resul
t)) | 759 if (!parseRsaKeyGenParams(raw, modulusLength, publicExponent, context, error
)) |
| 758 return false; | 760 return false; |
| 759 | 761 |
| 760 blink::WebCryptoAlgorithm hash; | 762 blink::WebCryptoAlgorithm hash; |
| 761 if (!parseHash(raw, hash, context, result)) | 763 if (!parseHash(raw, hash, context, error)) |
| 762 return false; | 764 return false; |
| 763 | 765 |
| 764 params = adoptPtr(new blink::WebCryptoRsaHashedKeyGenParams(hash, modulusLen
gth, static_cast<const unsigned char*>(publicExponent->baseAddress()), publicExp
onent->byteLength())); | 766 params = adoptPtr(new blink::WebCryptoRsaHashedKeyGenParams(hash, modulusLen
gth, static_cast<const unsigned char*>(publicExponent->baseAddress()), publicExp
onent->byteLength())); |
| 765 return true; | 767 return true; |
| 766 } | 768 } |
| 767 | 769 |
| 768 // Defined by the WebCrypto spec as: | 770 // Defined by the WebCrypto spec as: |
| 769 // | 771 // |
| 770 // dictionary AesCtrParams : Algorithm { | 772 // dictionary AesCtrParams : Algorithm { |
| 771 // CryptoOperationData counter; | 773 // CryptoOperationData counter; |
| 772 // [EnforceRange] octet length; | 774 // [EnforceRange] octet length; |
| 773 // }; | 775 // }; |
| 774 bool parseAesCtrParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, CryptoResult* result) | 776 bool parseAesCtrParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, AlgorithmError* error) |
| 775 { | 777 { |
| 776 RefPtr<ArrayBufferView> counter; | 778 RefPtr<ArrayBufferView> counter; |
| 777 if (!getCryptoOperationData(raw, "counter", counter, context, result)) | 779 if (!getCryptoOperationData(raw, "counter", counter, context, error)) |
| 778 return false; | 780 return false; |
| 779 | 781 |
| 780 uint8_t length; | 782 uint8_t length; |
| 781 if (!getUint8(raw, "length", length, context, result)) | 783 if (!getUint8(raw, "length", length, context, error)) |
| 782 return false; | 784 return false; |
| 783 | 785 |
| 784 params = adoptPtr(new blink::WebCryptoAesCtrParams(length, static_cast<const
unsigned char*>(counter->baseAddress()), counter->byteLength())); | 786 params = adoptPtr(new blink::WebCryptoAesCtrParams(length, static_cast<const
unsigned char*>(counter->baseAddress()), counter->byteLength())); |
| 785 return true; | 787 return true; |
| 786 } | 788 } |
| 787 | 789 |
| 788 // Defined by the WebCrypto spec as: | 790 // Defined by the WebCrypto spec as: |
| 789 // | 791 // |
| 790 // dictionary AesGcmParams : Algorithm { | 792 // dictionary AesGcmParams : Algorithm { |
| 791 // CryptoOperationData iv; | 793 // CryptoOperationData iv; |
| 792 // CryptoOperationData? additionalData; | 794 // CryptoOperationData? additionalData; |
| 793 // [EnforceRange] octet? tagLength; // May be 0-128 | 795 // [EnforceRange] octet? tagLength; // May be 0-128 |
| 794 // } | 796 // } |
| 795 bool parseAesGcmParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, CryptoResult* result) | 797 bool parseAesGcmParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, AlgorithmError* error) |
| 796 { | 798 { |
| 797 RefPtr<ArrayBufferView> iv; | 799 RefPtr<ArrayBufferView> iv; |
| 798 if (!getCryptoOperationData(raw, "iv", iv, context, result)) | 800 if (!getCryptoOperationData(raw, "iv", iv, context, error)) |
| 799 return false; | 801 return false; |
| 800 | 802 |
| 801 bool hasAdditionalData; | 803 bool hasAdditionalData; |
| 802 RefPtr<ArrayBufferView> additionalData; | 804 RefPtr<ArrayBufferView> additionalData; |
| 803 if (!getOptionalCryptoOperationData(raw, "additionalData", hasAdditionalData
, additionalData, context, result)) | 805 if (!getOptionalCryptoOperationData(raw, "additionalData", hasAdditionalData
, additionalData, context, error)) |
| 804 return false; | 806 return false; |
| 805 | 807 |
| 806 double tagLength; | 808 double tagLength; |
| 807 bool hasTagLength; | 809 bool hasTagLength; |
| 808 if (!getOptionalInteger(raw, "tagLength", hasTagLength, tagLength, 0, 128, c
ontext, result)) | 810 if (!getOptionalInteger(raw, "tagLength", hasTagLength, tagLength, 0, 128, c
ontext, error)) |
| 809 return false; | 811 return false; |
| 810 | 812 |
| 811 const unsigned char* ivStart = static_cast<const unsigned char*>(iv->baseAdd
ress()); | 813 const unsigned char* ivStart = static_cast<const unsigned char*>(iv->baseAdd
ress()); |
| 812 unsigned ivLength = iv->byteLength(); | 814 unsigned ivLength = iv->byteLength(); |
| 813 | 815 |
| 814 const unsigned char* additionalDataStart = hasAdditionalData ? static_cast<c
onst unsigned char*>(additionalData->baseAddress()) : 0; | 816 const unsigned char* additionalDataStart = hasAdditionalData ? static_cast<c
onst unsigned char*>(additionalData->baseAddress()) : 0; |
| 815 unsigned additionalDataLength = hasAdditionalData ? additionalData->byteLeng
th() : 0; | 817 unsigned additionalDataLength = hasAdditionalData ? additionalData->byteLeng
th() : 0; |
| 816 | 818 |
| 817 params = adoptPtr(new blink::WebCryptoAesGcmParams(ivStart, ivLength, hasAdd
itionalData, additionalDataStart, additionalDataLength, hasTagLength, tagLength)
); | 819 params = adoptPtr(new blink::WebCryptoAesGcmParams(ivStart, ivLength, hasAdd
itionalData, additionalDataStart, additionalDataLength, hasTagLength, tagLength)
); |
| 818 return true; | 820 return true; |
| 819 } | 821 } |
| 820 | 822 |
| 821 // Defined by the WebCrypto spec as: | 823 // Defined by the WebCrypto spec as: |
| 822 // | 824 // |
| 823 // dictionary RsaOaepParams : Algorithm { | 825 // dictionary RsaOaepParams : Algorithm { |
| 824 // CryptoOperationData? label; | 826 // CryptoOperationData? label; |
| 825 // }; | 827 // }; |
| 826 bool parseRsaOaepParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmP
arams>& params, const ErrorContext& context, CryptoResult* result) | 828 bool parseRsaOaepParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmP
arams>& params, const ErrorContext& context, AlgorithmError* error) |
| 827 { | 829 { |
| 828 bool hasLabel; | 830 bool hasLabel; |
| 829 RefPtr<ArrayBufferView> label; | 831 RefPtr<ArrayBufferView> label; |
| 830 if (!getOptionalCryptoOperationData(raw, "label", hasLabel, label, context,
result)) | 832 if (!getOptionalCryptoOperationData(raw, "label", hasLabel, label, context,
error)) |
| 831 return false; | 833 return false; |
| 832 | 834 |
| 833 const unsigned char* labelStart = hasLabel ? static_cast<const unsigned char
*>(label->baseAddress()) : 0; | 835 const unsigned char* labelStart = hasLabel ? static_cast<const unsigned char
*>(label->baseAddress()) : 0; |
| 834 unsigned labelLength = hasLabel ? label->byteLength() : 0; | 836 unsigned labelLength = hasLabel ? label->byteLength() : 0; |
| 835 | 837 |
| 836 params = adoptPtr(new blink::WebCryptoRsaOaepParams(hasLabel, labelStart, la
belLength)); | 838 params = adoptPtr(new blink::WebCryptoRsaOaepParams(hasLabel, labelStart, la
belLength)); |
| 837 return true; | 839 return true; |
| 838 } | 840 } |
| 839 | 841 |
| 840 bool parseAlgorithmParams(const Dictionary& raw, blink::WebCryptoAlgorithmParams
Type type, OwnPtr<blink::WebCryptoAlgorithmParams>& params, ErrorContext& contex
t, CryptoResult* result) | 842 bool parseAlgorithmParams(const Dictionary& raw, blink::WebCryptoAlgorithmParams
Type type, OwnPtr<blink::WebCryptoAlgorithmParams>& params, ErrorContext& contex
t, AlgorithmError* error) |
| 841 { | 843 { |
| 842 switch (type) { | 844 switch (type) { |
| 843 case blink::WebCryptoAlgorithmParamsTypeNone: | 845 case blink::WebCryptoAlgorithmParamsTypeNone: |
| 844 return true; | 846 return true; |
| 845 case blink::WebCryptoAlgorithmParamsTypeAesCbcParams: | 847 case blink::WebCryptoAlgorithmParamsTypeAesCbcParams: |
| 846 context.add("AesCbcParams"); | 848 context.add("AesCbcParams"); |
| 847 return parseAesCbcParams(raw, params, context, result); | 849 return parseAesCbcParams(raw, params, context, error); |
| 848 case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams: | 850 case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams: |
| 849 context.add("AesKeyGenParams"); | 851 context.add("AesKeyGenParams"); |
| 850 return parseAesKeyGenParams(raw, params, context, result); | 852 return parseAesKeyGenParams(raw, params, context, error); |
| 851 case blink::WebCryptoAlgorithmParamsTypeHmacImportParams: | 853 case blink::WebCryptoAlgorithmParamsTypeHmacImportParams: |
| 852 context.add("HmacImportParams"); | 854 context.add("HmacImportParams"); |
| 853 return parseHmacImportParams(raw, params, context, result); | 855 return parseHmacImportParams(raw, params, context, error); |
| 854 case blink::WebCryptoAlgorithmParamsTypeHmacKeyGenParams: | 856 case blink::WebCryptoAlgorithmParamsTypeHmacKeyGenParams: |
| 855 context.add("HmacKeyGenParams"); | 857 context.add("HmacKeyGenParams"); |
| 856 return parseHmacKeyGenParams(raw, params, context, result); | 858 return parseHmacKeyGenParams(raw, params, context, error); |
| 857 case blink::WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams: | 859 case blink::WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams: |
| 858 context.add("RsaHashedKeyGenParams"); | 860 context.add("RsaHashedKeyGenParams"); |
| 859 return parseRsaHashedKeyGenParams(raw, params, context, result); | 861 return parseRsaHashedKeyGenParams(raw, params, context, error); |
| 860 case blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams: | 862 case blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams: |
| 861 context.add("RsaHashedImportParams"); | 863 context.add("RsaHashedImportParams"); |
| 862 return parseRsaHashedImportParams(raw, params, context, result); | 864 return parseRsaHashedImportParams(raw, params, context, error); |
| 863 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: | 865 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: |
| 864 context.add("RsaKeyGenParams"); | 866 context.add("RsaKeyGenParams"); |
| 865 return parseRsaKeyGenParams(raw, params, context, result); | 867 return parseRsaKeyGenParams(raw, params, context, error); |
| 866 case blink::WebCryptoAlgorithmParamsTypeAesCtrParams: | 868 case blink::WebCryptoAlgorithmParamsTypeAesCtrParams: |
| 867 context.add("AesCtrParams"); | 869 context.add("AesCtrParams"); |
| 868 return parseAesCtrParams(raw, params, context, result); | 870 return parseAesCtrParams(raw, params, context, error); |
| 869 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: | 871 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: |
| 870 context.add("AesGcmParams"); | 872 context.add("AesGcmParams"); |
| 871 return parseAesGcmParams(raw, params, context, result); | 873 return parseAesGcmParams(raw, params, context, error); |
| 872 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: | 874 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: |
| 873 context.add("RsaOaepParams"); | 875 context.add("RsaOaepParams"); |
| 874 return parseRsaOaepParams(raw, params, context, result); | 876 return parseRsaOaepParams(raw, params, context, error); |
| 875 break; | 877 break; |
| 876 } | 878 } |
| 877 ASSERT_NOT_REACHED(); | 879 ASSERT_NOT_REACHED(); |
| 878 return false; | 880 return false; |
| 879 } | 881 } |
| 880 | 882 |
| 881 const char* operationToString(AlgorithmOperation op) | 883 const char* operationToString(blink::AlgorithmOperation op) |
| 882 { | 884 { |
| 883 switch (op) { | 885 switch (op) { |
| 884 case Encrypt: | 886 case blink::Encrypt: |
| 885 return "encrypt"; | 887 return "encrypt"; |
| 886 case Decrypt: | 888 case blink::Decrypt: |
| 887 return "decrypt"; | 889 return "decrypt"; |
| 888 case Sign: | 890 case blink::Sign: |
| 889 return "sign"; | 891 return "sign"; |
| 890 case Verify: | 892 case blink::Verify: |
| 891 return "verify"; | 893 return "verify"; |
| 892 case Digest: | 894 case blink::Digest: |
| 893 return "digest"; | 895 return "digest"; |
| 894 case GenerateKey: | 896 case blink::GenerateKey: |
| 895 return "generateKey"; | 897 return "generateKey"; |
| 896 case ImportKey: | 898 case blink::ImportKey: |
| 897 return "importKey"; | 899 return "importKey"; |
| 898 case DeriveKey: | 900 case blink::DeriveKey: |
| 899 return "deriveKey"; | 901 return "deriveKey"; |
| 900 case DeriveBits: | 902 case blink::DeriveBits: |
| 901 return "deriveBits"; | 903 return "deriveBits"; |
| 902 case WrapKey: | 904 case blink::WrapKey: |
| 903 return "wrapKey"; | 905 return "wrapKey"; |
| 904 case UnwrapKey: | 906 case blink::UnwrapKey: |
| 905 return "unwrapKey"; | 907 return "unwrapKey"; |
| 906 } | 908 } |
| 907 return 0; | 909 return 0; |
| 908 } | 910 } |
| 909 | 911 |
| 910 bool parseAlgorithm(const Dictionary& raw, AlgorithmOperation op, blink::WebCryp
toAlgorithm& algorithm, ErrorContext context, CryptoResult* result) | 912 bool parseAlgorithm(const Dictionary& raw, blink::AlgorithmOperation op, blink::
WebCryptoAlgorithm& algorithm, ErrorContext context, AlgorithmError* error) |
| 911 { | 913 { |
| 912 context.add("Algorithm"); | 914 context.add("Algorithm"); |
| 913 | 915 |
| 914 if (!raw.isObject()) { | 916 if (!raw.isObject()) { |
| 915 completeWithSyntaxError(context.toString("Not an object"), result); | 917 setSyntaxError(context.toString("Not an object"), error); |
| 916 return false; | 918 return false; |
| 917 } | 919 } |
| 918 | 920 |
| 919 String algorithmName; | 921 String algorithmName; |
| 920 if (!raw.get("name", algorithmName)) { | 922 if (!raw.get("name", algorithmName)) { |
| 921 completeWithSyntaxError(context.toString("name", "Missing or not a strin
g"), result); | 923 setSyntaxError(context.toString("name", "Missing or not a string"), erro
r); |
| 922 return false; | 924 return false; |
| 923 } | 925 } |
| 924 | 926 |
| 925 blink::WebCryptoAlgorithmId algorithmId; | 927 blink::WebCryptoAlgorithmId algorithmId; |
| 926 if (!lookupAlgorithmIdByName(algorithmName, algorithmId)) { | 928 if (!lookupAlgorithmIdByName(algorithmName, algorithmId)) { |
| 927 // FIXME: The spec says to return a SyntaxError if the input contains | 929 // FIXME: The spec says to return a SyntaxError if the input contains |
| 928 // any non-ASCII characters. | 930 // any non-ASCII characters. |
| 929 completeWithNotSupportedError(context.toString("Unrecognized name"), res
ult); | 931 setNotSupportedError(context.toString("Unrecognized name"), error); |
| 930 return false; | 932 return false; |
| 931 } | 933 } |
| 932 | 934 |
| 933 // Remove the "Algorithm:" prefix for all subsequent errors. | 935 // Remove the "Algorithm:" prefix for all subsequent errors. |
| 934 context.removeLast(); | 936 context.removeLast(); |
| 935 | 937 |
| 936 const AlgorithmInfo* algorithmInfo = lookupAlgorithmInfo(algorithmId); | 938 const AlgorithmInfo* algorithmInfo = lookupAlgorithmInfo(algorithmId); |
| 937 | 939 |
| 938 if (algorithmInfo->operationToParamsType[op] == Undefined) { | 940 if (algorithmInfo->operationToParamsType[op] == Undefined) { |
| 939 context.add(algorithmIdToName(algorithmId)); | 941 context.add(algorithmIdToName(algorithmId)); |
| 940 completeWithNotSupportedError(context.toString("Unsupported operation",
operationToString(op)), result); | 942 setNotSupportedError(context.toString("Unsupported operation", operation
ToString(op)), error); |
| 941 return false; | 943 return false; |
| 942 } | 944 } |
| 943 | 945 |
| 944 blink::WebCryptoAlgorithmParamsType paramsType = static_cast<blink::WebCrypt
oAlgorithmParamsType>(algorithmInfo->operationToParamsType[op]); | 946 blink::WebCryptoAlgorithmParamsType paramsType = static_cast<blink::WebCrypt
oAlgorithmParamsType>(algorithmInfo->operationToParamsType[op]); |
| 945 | 947 |
| 946 OwnPtr<blink::WebCryptoAlgorithmParams> params; | 948 OwnPtr<blink::WebCryptoAlgorithmParams> params; |
| 947 if (!parseAlgorithmParams(raw, paramsType, params, context, result)) | 949 if (!parseAlgorithmParams(raw, paramsType, params, context, error)) |
| 948 return false; | 950 return false; |
| 949 | 951 |
| 950 algorithm = blink::WebCryptoAlgorithm(algorithmId, params.release()); | 952 algorithm = blink::WebCryptoAlgorithm(algorithmId, params.release()); |
| 951 return true; | 953 return true; |
| 952 } | 954 } |
| 953 | 955 |
| 954 } // namespace | 956 } // namespace |
| 955 | 957 |
| 956 bool parseAlgorithm(const Dictionary& raw, AlgorithmOperation op, blink::WebCryp
toAlgorithm& algorithm, CryptoResult* result) | 958 bool normalizeAlgorithm(const Dictionary& raw, blink::AlgorithmOperation op, bli
nk::WebCryptoAlgorithm& algorithm, AlgorithmError* error) |
| 957 { | 959 { |
| 958 return parseAlgorithm(raw, op, algorithm, ErrorContext(), result); | 960 return parseAlgorithm(raw, op, algorithm, ErrorContext(), error); |
| 959 } | 961 } |
| 960 | 962 |
| 961 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) | 963 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) |
| 962 { | 964 { |
| 963 return lookupAlgorithmInfo(id)->name; | 965 return lookupAlgorithmInfo(id)->name; |
| 964 } | 966 } |
| 965 | 967 |
| 966 } // namespace WebCore | 968 } // namespace WebCore |
| OLD | NEW |