| 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 28 matching lines...) Expand all Loading... |
| 39 #include "core/dom/DOMTypedArray.h" | 39 #include "core/dom/DOMTypedArray.h" |
| 40 #include "public/platform/WebCryptoAlgorithmParams.h" | 40 #include "public/platform/WebCryptoAlgorithmParams.h" |
| 41 #include "public/platform/WebString.h" | 41 #include "public/platform/WebString.h" |
| 42 #include "wtf/MathExtras.h" | 42 #include "wtf/MathExtras.h" |
| 43 #include "wtf/PtrUtil.h" | 43 #include "wtf/PtrUtil.h" |
| 44 #include "wtf/Vector.h" | 44 #include "wtf/Vector.h" |
| 45 #include "wtf/text/StringBuilder.h" | 45 #include "wtf/text/StringBuilder.h" |
| 46 #include <algorithm> | 46 #include <algorithm> |
| 47 #include <memory> | 47 #include <memory> |
| 48 | 48 |
| 49 // TODO(eroman): Change the interface for constructing | |
| 50 // WebCryptoAlgorithmParams to allow transferring byte | |
| 51 // parameters (whereas currently it makes a copy). | |
| 52 | |
| 53 namespace blink { | 49 namespace blink { |
| 54 | 50 |
| 55 namespace { | 51 namespace { |
| 56 | 52 |
| 57 typedef ArrayBufferOrArrayBufferView BufferSource; | 53 typedef ArrayBufferOrArrayBufferView BufferSource; |
| 58 | 54 |
| 59 struct AlgorithmNameMapping { | 55 struct AlgorithmNameMapping { |
| 60 // Must be an upper case ASCII string. | 56 // Must be an upper case ASCII string. |
| 61 const char* const algorithmName; | 57 const char* const algorithmName; |
| 62 // Must be strlen(algorithmName). | 58 // Must be strlen(algorithmName). |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 stack.add(message2); | 263 stack.add(message2); |
| 268 return stack.toString(); | 264 return stack.toString(); |
| 269 } | 265 } |
| 270 | 266 |
| 271 private: | 267 private: |
| 272 // This inline size is large enough to avoid having to grow the Vector in | 268 // This inline size is large enough to avoid having to grow the Vector in |
| 273 // the majority of cases (up to 1 nested algorithm identifier). | 269 // the majority of cases (up to 1 nested algorithm identifier). |
| 274 Vector<const char*, 10> m_messages; | 270 Vector<const char*, 10> m_messages; |
| 275 }; | 271 }; |
| 276 | 272 |
| 277 static Vector<uint8_t> copyBytes(const DOMArrayPiece& source) | 273 static WebVector<uint8_t> copyBytes(const DOMArrayPiece& source) |
| 278 { | 274 { |
| 279 Vector<uint8_t> result; | 275 return WebVector<uint8_t>(static_cast<const uint8_t*>(source.data()), source
.byteLength()); |
| 280 result.append(reinterpret_cast<const uint8_t*>(source.data()), source.byteLe
ngth()); | |
| 281 return result; | |
| 282 } | 276 } |
| 283 | 277 |
| 284 // Defined by the WebCrypto spec as: | 278 // Defined by the WebCrypto spec as: |
| 285 // | 279 // |
| 286 // typedef (ArrayBuffer or ArrayBufferView) BufferSource; | 280 // typedef (ArrayBuffer or ArrayBufferView) BufferSource; |
| 287 // | 281 // |
| 288 bool getOptionalBufferSource(const Dictionary& raw, const char* propertyName, bo
ol& hasProperty, Vector<uint8_t>& bytes, const ErrorContext& context, AlgorithmE
rror* error) | 282 bool getOptionalBufferSource(const Dictionary& raw, const char* propertyName, bo
ol& hasProperty, WebVector<uint8_t>& bytes, const ErrorContext& context, Algorit
hmError* error) |
| 289 { | 283 { |
| 290 hasProperty = false; | 284 hasProperty = false; |
| 291 v8::Local<v8::Value> v8Value; | 285 v8::Local<v8::Value> v8Value; |
| 292 if (!raw.get(propertyName, v8Value)) | 286 if (!raw.get(propertyName, v8Value)) |
| 293 return true; | 287 return true; |
| 294 hasProperty = true; | 288 hasProperty = true; |
| 295 | 289 |
| 296 if (v8Value->IsArrayBufferView()) { | 290 if (v8Value->IsArrayBufferView()) { |
| 297 bytes = copyBytes(V8ArrayBufferView::toImpl(v8::Local<v8::Object>::Cast(
v8Value))); | 291 bytes = copyBytes(V8ArrayBufferView::toImpl(v8::Local<v8::Object>::Cast(
v8Value))); |
| 298 return true; | 292 return true; |
| 299 } | 293 } |
| 300 | 294 |
| 301 if (v8Value->IsArrayBuffer()) { | 295 if (v8Value->IsArrayBuffer()) { |
| 302 bytes = copyBytes(V8ArrayBuffer::toImpl(v8::Local<v8::Object>::Cast(v8Va
lue))); | 296 bytes = copyBytes(V8ArrayBuffer::toImpl(v8::Local<v8::Object>::Cast(v8Va
lue))); |
| 303 return true; | 297 return true; |
| 304 } | 298 } |
| 305 | 299 |
| 306 if (hasProperty) { | 300 if (hasProperty) { |
| 307 setTypeError(context.toString(propertyName, "Not a BufferSource"), error
); | 301 setTypeError(context.toString(propertyName, "Not a BufferSource"), error
); |
| 308 return false; | 302 return false; |
| 309 } | 303 } |
| 310 return true; | 304 return true; |
| 311 } | 305 } |
| 312 | 306 |
| 313 bool getBufferSource(const Dictionary& raw, const char* propertyName, Vector<uin
t8_t>& bytes, const ErrorContext& context, AlgorithmError* error) | 307 bool getBufferSource(const Dictionary& raw, const char* propertyName, WebVector<
uint8_t>& bytes, const ErrorContext& context, AlgorithmError* error) |
| 314 { | 308 { |
| 315 bool hasProperty; | 309 bool hasProperty; |
| 316 bool ok = getOptionalBufferSource(raw, propertyName, hasProperty, bytes, con
text, error); | 310 bool ok = getOptionalBufferSource(raw, propertyName, hasProperty, bytes, con
text, error); |
| 317 if (!hasProperty) { | 311 if (!hasProperty) { |
| 318 setTypeError(context.toString(propertyName, "Missing required property")
, error); | 312 setTypeError(context.toString(propertyName, "Missing required property")
, error); |
| 319 return false; | 313 return false; |
| 320 } | 314 } |
| 321 return ok; | 315 return ok; |
| 322 } | 316 } |
| 323 | 317 |
| 324 bool getUint8Array(const Dictionary& raw, const char* propertyName, Vector<uint8
_t>& bytes, const ErrorContext& context, AlgorithmError* error) | 318 bool getUint8Array(const Dictionary& raw, const char* propertyName, WebVector<ui
nt8_t>& bytes, const ErrorContext& context, AlgorithmError* error) |
| 325 { | 319 { |
| 326 DOMUint8Array* array = nullptr; | 320 DOMUint8Array* array = nullptr; |
| 327 if (!DictionaryHelper::get(raw, propertyName, array) || !array) { | 321 if (!DictionaryHelper::get(raw, propertyName, array) || !array) { |
| 328 setTypeError(context.toString(propertyName, "Missing or not a Uint8Array
"), error); | 322 setTypeError(context.toString(propertyName, "Missing or not a Uint8Array
"), error); |
| 329 return false; | 323 return false; |
| 330 } | 324 } |
| 331 bytes = copyBytes(array); | 325 bytes = copyBytes(array); |
| 332 return true; | 326 return true; |
| 333 } | 327 } |
| 334 | 328 |
| 335 // Defined by the WebCrypto spec as: | 329 // Defined by the WebCrypto spec as: |
| 336 // | 330 // |
| 337 // typedef Uint8Array BigInteger; | 331 // typedef Uint8Array BigInteger; |
| 338 bool getBigInteger(const Dictionary& raw, const char* propertyName, Vector<uint8
_t>& bytes, const ErrorContext& context, AlgorithmError* error) | 332 bool getBigInteger(const Dictionary& raw, const char* propertyName, WebVector<ui
nt8_t>& bytes, const ErrorContext& context, AlgorithmError* error) |
| 339 { | 333 { |
| 340 if (!getUint8Array(raw, propertyName, bytes, context, error)) | 334 if (!getUint8Array(raw, propertyName, bytes, context, error)) |
| 341 return false; | 335 return false; |
| 342 | 336 |
| 343 if (bytes.isEmpty()) { | 337 if (bytes.isEmpty()) { |
| 344 // Empty BigIntegers represent 0 according to the spec | 338 // Empty BigIntegers represent 0 according to the spec |
| 345 bytes.fill(0, 1); | 339 bytes = WebVector<uint8_t>(static_cast<size_t>(1u)); |
| 340 DCHECK_EQ(0u, bytes[0]); |
| 346 } | 341 } |
| 347 | 342 |
| 348 return true; | 343 return true; |
| 349 } | 344 } |
| 350 | 345 |
| 351 // Gets an integer according to WebIDL's [EnforceRange]. | 346 // Gets an integer according to WebIDL's [EnforceRange]. |
| 352 bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& h
asProperty, double& value, double minValue, double maxValue, const ErrorContext&
context, AlgorithmError* error) | 347 bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& h
asProperty, double& value, double minValue, double maxValue, const ErrorContext&
context, AlgorithmError* error) |
| 353 { | 348 { |
| 354 double number; | 349 double number; |
| 355 bool ok = DictionaryHelper::get(raw, propertyName, number, hasProperty); | 350 bool ok = DictionaryHelper::get(raw, propertyName, number, hasProperty); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 return true; | 452 return true; |
| 458 } | 453 } |
| 459 | 454 |
| 460 // Defined by the WebCrypto spec as: | 455 // Defined by the WebCrypto spec as: |
| 461 // | 456 // |
| 462 // dictionary AesCbcParams : Algorithm { | 457 // dictionary AesCbcParams : Algorithm { |
| 463 // required BufferSource iv; | 458 // required BufferSource iv; |
| 464 // }; | 459 // }; |
| 465 bool parseAesCbcParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm
Params>& params, const ErrorContext& context, AlgorithmError* error) | 460 bool parseAesCbcParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm
Params>& params, const ErrorContext& context, AlgorithmError* error) |
| 466 { | 461 { |
| 467 Vector<uint8_t> iv; | 462 WebVector<uint8_t> iv; |
| 468 if (!getBufferSource(raw, "iv", iv, context, error)) | 463 if (!getBufferSource(raw, "iv", iv, context, error)) |
| 469 return false; | 464 return false; |
| 470 | 465 |
| 471 params = wrapUnique(new WebCryptoAesCbcParams(iv.data(), iv.size())); | 466 params = wrapUnique(new WebCryptoAesCbcParams(std::move(iv))); |
| 472 return true; | 467 return true; |
| 473 } | 468 } |
| 474 | 469 |
| 475 // Defined by the WebCrypto spec as: | 470 // Defined by the WebCrypto spec as: |
| 476 // | 471 // |
| 477 // dictionary AesKeyGenParams : Algorithm { | 472 // dictionary AesKeyGenParams : Algorithm { |
| 478 // [EnforceRange] required unsigned short length; | 473 // [EnforceRange] required unsigned short length; |
| 479 // }; | 474 // }; |
| 480 bool parseAesKeyGenParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgori
thmParams>& params, const ErrorContext& context, AlgorithmError* error) | 475 bool parseAesKeyGenParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgori
thmParams>& params, const ErrorContext& context, AlgorithmError* error) |
| 481 { | 476 { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 // | 564 // |
| 570 // dictionary RsaHashedKeyGenParams : RsaKeyGenParams { | 565 // dictionary RsaHashedKeyGenParams : RsaKeyGenParams { |
| 571 // required HashAlgorithmIdentifier hash; | 566 // required HashAlgorithmIdentifier hash; |
| 572 // }; | 567 // }; |
| 573 bool parseRsaHashedKeyGenParams(const Dictionary& raw, std::unique_ptr<WebCrypto
AlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error) | 568 bool parseRsaHashedKeyGenParams(const Dictionary& raw, std::unique_ptr<WebCrypto
AlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error) |
| 574 { | 569 { |
| 575 uint32_t modulusLength; | 570 uint32_t modulusLength; |
| 576 if (!getUint32(raw, "modulusLength", modulusLength, context, error)) | 571 if (!getUint32(raw, "modulusLength", modulusLength, context, error)) |
| 577 return false; | 572 return false; |
| 578 | 573 |
| 579 Vector<uint8_t> publicExponent; | 574 WebVector<uint8_t> publicExponent; |
| 580 if (!getBigInteger(raw, "publicExponent", publicExponent, context, error)) | 575 if (!getBigInteger(raw, "publicExponent", publicExponent, context, error)) |
| 581 return false; | 576 return false; |
| 582 | 577 |
| 583 WebCryptoAlgorithm hash; | 578 WebCryptoAlgorithm hash; |
| 584 if (!parseHash(raw, hash, context, error)) | 579 if (!parseHash(raw, hash, context, error)) |
| 585 return false; | 580 return false; |
| 586 | 581 |
| 587 params = wrapUnique(new WebCryptoRsaHashedKeyGenParams(hash, modulusLength,
publicExponent.data(), publicExponent.size())); | 582 params = wrapUnique(new WebCryptoRsaHashedKeyGenParams(hash, modulusLength,
std::move(publicExponent))); |
| 588 return true; | 583 return true; |
| 589 } | 584 } |
| 590 | 585 |
| 591 // Defined by the WebCrypto spec as: | 586 // Defined by the WebCrypto spec as: |
| 592 // | 587 // |
| 593 // dictionary AesCtrParams : Algorithm { | 588 // dictionary AesCtrParams : Algorithm { |
| 594 // required BufferSource counter; | 589 // required BufferSource counter; |
| 595 // [EnforceRange] required octet length; | 590 // [EnforceRange] required octet length; |
| 596 // }; | 591 // }; |
| 597 bool parseAesCtrParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm
Params>& params, const ErrorContext& context, AlgorithmError* error) | 592 bool parseAesCtrParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm
Params>& params, const ErrorContext& context, AlgorithmError* error) |
| 598 { | 593 { |
| 599 Vector<uint8_t> counter; | 594 WebVector<uint8_t> counter; |
| 600 if (!getBufferSource(raw, "counter", counter, context, error)) | 595 if (!getBufferSource(raw, "counter", counter, context, error)) |
| 601 return false; | 596 return false; |
| 602 | 597 |
| 603 uint8_t length; | 598 uint8_t length; |
| 604 if (!getUint8(raw, "length", length, context, error)) | 599 if (!getUint8(raw, "length", length, context, error)) |
| 605 return false; | 600 return false; |
| 606 | 601 |
| 607 params = wrapUnique(new WebCryptoAesCtrParams(length, counter.data(), counte
r.size())); | 602 params = wrapUnique(new WebCryptoAesCtrParams(length, std::move(counter))); |
| 608 return true; | 603 return true; |
| 609 } | 604 } |
| 610 | 605 |
| 611 // Defined by the WebCrypto spec as: | 606 // Defined by the WebCrypto spec as: |
| 612 // | 607 // |
| 613 // dictionary AesGcmParams : Algorithm { | 608 // dictionary AesGcmParams : Algorithm { |
| 614 // required BufferSource iv; | 609 // required BufferSource iv; |
| 615 // BufferSource additionalData; | 610 // BufferSource additionalData; |
| 616 // [EnforceRange] octet tagLength; | 611 // [EnforceRange] octet tagLength; |
| 617 // } | 612 // } |
| 618 bool parseAesGcmParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm
Params>& params, const ErrorContext& context, AlgorithmError* error) | 613 bool parseAesGcmParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm
Params>& params, const ErrorContext& context, AlgorithmError* error) |
| 619 { | 614 { |
| 620 Vector<uint8_t> iv; | 615 WebVector<uint8_t> iv; |
| 621 if (!getBufferSource(raw, "iv", iv, context, error)) | 616 if (!getBufferSource(raw, "iv", iv, context, error)) |
| 622 return false; | 617 return false; |
| 623 | 618 |
| 624 bool hasAdditionalData; | 619 bool hasAdditionalData; |
| 625 Vector<uint8_t> additionalData; | 620 WebVector<uint8_t> additionalData; |
| 626 if (!getOptionalBufferSource(raw, "additionalData", hasAdditionalData, addit
ionalData, context, error)) | 621 if (!getOptionalBufferSource(raw, "additionalData", hasAdditionalData, addit
ionalData, context, error)) |
| 627 return false; | 622 return false; |
| 628 | 623 |
| 629 uint8_t tagLength = 0; | 624 uint8_t tagLength = 0; |
| 630 bool hasTagLength; | 625 bool hasTagLength; |
| 631 if (!getOptionalUint8(raw, "tagLength", hasTagLength, tagLength, context, er
ror)) | 626 if (!getOptionalUint8(raw, "tagLength", hasTagLength, tagLength, context, er
ror)) |
| 632 return false; | 627 return false; |
| 633 | 628 |
| 634 params = wrapUnique(new WebCryptoAesGcmParams(iv.data(), iv.size(), hasAddit
ionalData, additionalData.data(), additionalData.size(), hasTagLength, tagLength
)); | 629 params = wrapUnique(new WebCryptoAesGcmParams(std::move(iv), hasAdditionalDa
ta, std::move(additionalData), hasTagLength, tagLength)); |
| 635 return true; | 630 return true; |
| 636 } | 631 } |
| 637 | 632 |
| 638 // Defined by the WebCrypto spec as: | 633 // Defined by the WebCrypto spec as: |
| 639 // | 634 // |
| 640 // dictionary RsaOaepParams : Algorithm { | 635 // dictionary RsaOaepParams : Algorithm { |
| 641 // BufferSource label; | 636 // BufferSource label; |
| 642 // }; | 637 // }; |
| 643 bool parseRsaOaepParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorith
mParams>& params, const ErrorContext& context, AlgorithmError* error) | 638 bool parseRsaOaepParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorith
mParams>& params, const ErrorContext& context, AlgorithmError* error) |
| 644 { | 639 { |
| 645 bool hasLabel; | 640 bool hasLabel; |
| 646 Vector<uint8_t> label; | 641 WebVector<uint8_t> label; |
| 647 if (!getOptionalBufferSource(raw, "label", hasLabel, label, context, error)) | 642 if (!getOptionalBufferSource(raw, "label", hasLabel, label, context, error)) |
| 648 return false; | 643 return false; |
| 649 | 644 |
| 650 params = wrapUnique(new WebCryptoRsaOaepParams(hasLabel, label.data(), label
.size())); | 645 params = wrapUnique(new WebCryptoRsaOaepParams(hasLabel, std::move(label))); |
| 651 return true; | 646 return true; |
| 652 } | 647 } |
| 653 | 648 |
| 654 // Defined by the WebCrypto spec as: | 649 // Defined by the WebCrypto spec as: |
| 655 // | 650 // |
| 656 // dictionary RsaPssParams : Algorithm { | 651 // dictionary RsaPssParams : Algorithm { |
| 657 // [EnforceRange] required unsigned long saltLength; | 652 // [EnforceRange] required unsigned long saltLength; |
| 658 // }; | 653 // }; |
| 659 bool parseRsaPssParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm
Params>& params, const ErrorContext& context, AlgorithmError* error) | 654 bool parseRsaPssParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm
Params>& params, const ErrorContext& context, AlgorithmError* error) |
| 660 { | 655 { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 | 764 |
| 770 // Defined by the WebCrypto spec as: | 765 // Defined by the WebCrypto spec as: |
| 771 // | 766 // |
| 772 // dictionary Pbkdf2Params : Algorithm { | 767 // dictionary Pbkdf2Params : Algorithm { |
| 773 // required BufferSource salt; | 768 // required BufferSource salt; |
| 774 // [EnforceRange] required unsigned long iterations; | 769 // [EnforceRange] required unsigned long iterations; |
| 775 // required HashAlgorithmIdentifier hash; | 770 // required HashAlgorithmIdentifier hash; |
| 776 // }; | 771 // }; |
| 777 bool parsePbkdf2Params(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm
Params>& params, const ErrorContext& context, AlgorithmError* error) | 772 bool parsePbkdf2Params(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithm
Params>& params, const ErrorContext& context, AlgorithmError* error) |
| 778 { | 773 { |
| 779 Vector<uint8_t> salt; | 774 WebVector<uint8_t> salt; |
| 780 if (!getBufferSource(raw, "salt", salt, context, error)) | 775 if (!getBufferSource(raw, "salt", salt, context, error)) |
| 781 return false; | 776 return false; |
| 782 | 777 |
| 783 uint32_t iterations; | 778 uint32_t iterations; |
| 784 if (!getUint32(raw, "iterations", iterations, context, error)) | 779 if (!getUint32(raw, "iterations", iterations, context, error)) |
| 785 return false; | 780 return false; |
| 786 | 781 |
| 787 WebCryptoAlgorithm hash; | 782 WebCryptoAlgorithm hash; |
| 788 if (!parseHash(raw, hash, context, error)) | 783 if (!parseHash(raw, hash, context, error)) |
| 789 return false; | 784 return false; |
| 790 params = wrapUnique(new WebCryptoPbkdf2Params(hash, salt.data(), salt.size()
, iterations)); | 785 params = wrapUnique(new WebCryptoPbkdf2Params(hash, std::move(salt), iterati
ons)); |
| 791 return true; | 786 return true; |
| 792 } | 787 } |
| 793 | 788 |
| 794 // Defined by the WebCrypto spec as: | 789 // Defined by the WebCrypto spec as: |
| 795 // | 790 // |
| 796 // dictionary AesDerivedKeyParams : Algorithm { | 791 // dictionary AesDerivedKeyParams : Algorithm { |
| 797 // [EnforceRange] required unsigned short length; | 792 // [EnforceRange] required unsigned short length; |
| 798 // }; | 793 // }; |
| 799 bool parseAesDerivedKeyParams(const Dictionary& raw, std::unique_ptr<WebCryptoAl
gorithmParams>& params, const ErrorContext& context, AlgorithmError* error) | 794 bool parseAesDerivedKeyParams(const Dictionary& raw, std::unique_ptr<WebCryptoAl
gorithmParams>& params, const ErrorContext& context, AlgorithmError* error) |
| 800 { | 795 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 816 // dictionary HkdfParams : Algorithm { | 811 // dictionary HkdfParams : Algorithm { |
| 817 // required HashAlgorithmIdentifier hash; | 812 // required HashAlgorithmIdentifier hash; |
| 818 // required BufferSource salt; | 813 // required BufferSource salt; |
| 819 // required BufferSource info; | 814 // required BufferSource info; |
| 820 // }; | 815 // }; |
| 821 bool parseHkdfParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, AlgorithmError* error) | 816 bool parseHkdfParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmPa
rams>& params, const ErrorContext& context, AlgorithmError* error) |
| 822 { | 817 { |
| 823 WebCryptoAlgorithm hash; | 818 WebCryptoAlgorithm hash; |
| 824 if (!parseHash(raw, hash, context, error)) | 819 if (!parseHash(raw, hash, context, error)) |
| 825 return false; | 820 return false; |
| 826 Vector<uint8_t> salt; | 821 WebVector<uint8_t> salt; |
| 827 if (!getBufferSource(raw, "salt", salt, context, error)) | 822 if (!getBufferSource(raw, "salt", salt, context, error)) |
| 828 return false; | 823 return false; |
| 829 Vector<uint8_t> info; | 824 WebVector<uint8_t> info; |
| 830 if (!getBufferSource(raw, "info", info, context, error)) | 825 if (!getBufferSource(raw, "info", info, context, error)) |
| 831 return false; | 826 return false; |
| 832 | 827 |
| 833 params = wrapUnique(new WebCryptoHkdfParams(hash, salt.data(), salt.size(),
info.data(), info.size())); | 828 params = wrapUnique(new WebCryptoHkdfParams(hash, std::move(salt), std::move
(info))); |
| 834 return true; | 829 return true; |
| 835 } | 830 } |
| 836 | 831 |
| 837 bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType ty
pe, std::unique_ptr<WebCryptoAlgorithmParams>& params, ErrorContext& context, Al
gorithmError* error) | 832 bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType ty
pe, std::unique_ptr<WebCryptoAlgorithmParams>& params, ErrorContext& context, Al
gorithmError* error) |
| 838 { | 833 { |
| 839 switch (type) { | 834 switch (type) { |
| 840 case WebCryptoAlgorithmParamsTypeNone: | 835 case WebCryptoAlgorithmParamsTypeNone: |
| 841 return true; | 836 return true; |
| 842 case WebCryptoAlgorithmParamsTypeAesCbcParams: | 837 case WebCryptoAlgorithmParamsTypeAesCbcParams: |
| 843 context.add("AesCbcParams"); | 838 context.add("AesCbcParams"); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 } | 975 } |
| 981 | 976 |
| 982 } // namespace | 977 } // namespace |
| 983 | 978 |
| 984 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W
ebCryptoAlgorithm& algorithm, AlgorithmError* error) | 979 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W
ebCryptoAlgorithm& algorithm, AlgorithmError* error) |
| 985 { | 980 { |
| 986 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); | 981 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); |
| 987 } | 982 } |
| 988 | 983 |
| 989 } // namespace blink | 984 } // namespace blink |
| OLD | NEW |