| 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 Vector<const char*, 10> m_messages; | 262 Vector<const char*, 10> m_messages; |
| 263 }; | 263 }; |
| 264 | 264 |
| 265 // Defined by the WebCrypto spec as: | 265 // Defined by the WebCrypto spec as: |
| 266 // | 266 // |
| 267 // typedef (ArrayBuffer or ArrayBufferView) CryptoOperationData; | 267 // typedef (ArrayBuffer or ArrayBufferView) CryptoOperationData; |
| 268 // | 268 // |
| 269 // FIXME: Currently only supports ArrayBufferView. | 269 // FIXME: Currently only supports ArrayBufferView. |
| 270 bool getOptionalCryptoOperationData(const Dictionary& raw, const char* propertyN
ame, bool& hasProperty, RefPtr<ArrayBufferView>& buffer, const ErrorContext& con
text, AlgorithmError* error) | 270 bool getOptionalCryptoOperationData(const Dictionary& raw, const char* propertyN
ame, bool& hasProperty, RefPtr<ArrayBufferView>& buffer, const ErrorContext& con
text, AlgorithmError* error) |
| 271 { | 271 { |
| 272 if (!DictionaryHelper::get(raw, propertyName, buffer)) { | 272 if (!raw.get(propertyName, buffer)) { |
| 273 hasProperty = false; | 273 hasProperty = false; |
| 274 return true; | 274 return true; |
| 275 } | 275 } |
| 276 | 276 |
| 277 hasProperty = true; | 277 hasProperty = true; |
| 278 | 278 |
| 279 if (!buffer) { | 279 if (!buffer) { |
| 280 setSyntaxError(context.toString(propertyName, "Not an ArrayBufferView"),
error); | 280 setSyntaxError(context.toString(propertyName, "Not an ArrayBufferView"),
error); |
| 281 return false; | 281 return false; |
| 282 } | 282 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 295 bool ok = getOptionalCryptoOperationData(raw, propertyName, hasProperty, buf
fer, context, error); | 295 bool ok = getOptionalCryptoOperationData(raw, propertyName, hasProperty, buf
fer, context, error); |
| 296 if (!hasProperty) { | 296 if (!hasProperty) { |
| 297 setSyntaxError(context.toString(propertyName, "Missing required property
"), error); | 297 setSyntaxError(context.toString(propertyName, "Missing required property
"), error); |
| 298 return false; | 298 return false; |
| 299 } | 299 } |
| 300 return ok; | 300 return ok; |
| 301 } | 301 } |
| 302 | 302 |
| 303 bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ErrorContext& context, AlgorithmError* error) | 303 bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ErrorContext& context, AlgorithmError* error) |
| 304 { | 304 { |
| 305 if (!DictionaryHelper::get(raw, propertyName, array) || !array) { | 305 if (!raw.get(propertyName, array) || !array) { |
| 306 setSyntaxError(context.toString(propertyName, "Missing or not a Uint8Arr
ay"), error); | 306 setSyntaxError(context.toString(propertyName, "Missing or not a Uint8Arr
ay"), error); |
| 307 return false; | 307 return false; |
| 308 } | 308 } |
| 309 return true; | 309 return true; |
| 310 } | 310 } |
| 311 | 311 |
| 312 // Defined by the WebCrypto spec as: | 312 // Defined by the WebCrypto spec as: |
| 313 // | 313 // |
| 314 // typedef Uint8Array BigInteger; | 314 // typedef Uint8Array BigInteger; |
| 315 bool getBigInteger(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ErrorContext& context, AlgorithmError* error) | 315 bool getBigInteger(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ErrorContext& context, AlgorithmError* error) |
| 316 { | 316 { |
| 317 if (!getUint8Array(raw, propertyName, array, context, error)) | 317 if (!getUint8Array(raw, propertyName, array, context, error)) |
| 318 return false; | 318 return false; |
| 319 | 319 |
| 320 if (!array->byteLength()) { | 320 if (!array->byteLength()) { |
| 321 setSyntaxError(context.toString(propertyName, "BigInteger should not be
empty"), error); | 321 setSyntaxError(context.toString(propertyName, "BigInteger should not be
empty"), error); |
| 322 return false; | 322 return false; |
| 323 } | 323 } |
| 324 | 324 |
| 325 if (!DictionaryHelper::get(raw, propertyName, array) || !array) { | 325 if (!raw.get(propertyName, array) || !array) { |
| 326 setSyntaxError(context.toString(propertyName, "Missing or not a Uint8Arr
ay"), error); | 326 setSyntaxError(context.toString(propertyName, "Missing or not a Uint8Arr
ay"), error); |
| 327 return false; | 327 return false; |
| 328 } | 328 } |
| 329 return true; | 329 return true; |
| 330 } | 330 } |
| 331 | 331 |
| 332 // Gets an integer according to WebIDL's [EnforceRange]. | 332 // Gets an integer according to WebIDL's [EnforceRange]. |
| 333 bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& h
asProperty, double& value, double minValue, double maxValue, const ErrorContext&
context, AlgorithmError* error) | 333 bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& h
asProperty, double& value, double minValue, double maxValue, const ErrorContext&
context, AlgorithmError* error) |
| 334 { | 334 { |
| 335 double number; | 335 double number; |
| 336 bool ok = DictionaryHelper::get(raw, propertyName, number, hasProperty); | 336 bool ok = raw.get(propertyName, number, hasProperty); |
| 337 | 337 |
| 338 if (!hasProperty) | 338 if (!hasProperty) |
| 339 return true; | 339 return true; |
| 340 | 340 |
| 341 if (!ok || std::isnan(number)) { | 341 if (!ok || std::isnan(number)) { |
| 342 setSyntaxError(context.toString(propertyName, "Is not a number"), error)
; | 342 setSyntaxError(context.toString(propertyName, "Is not a number"), error)
; |
| 343 return false; | 343 return false; |
| 344 } | 344 } |
| 345 | 345 |
| 346 number = trunc(number); | 346 number = trunc(number); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 | 438 |
| 439 params = adoptPtr(new WebCryptoAesKeyGenParams(length)); | 439 params = adoptPtr(new WebCryptoAesKeyGenParams(length)); |
| 440 return true; | 440 return true; |
| 441 } | 441 } |
| 442 | 442 |
| 443 bool parseAlgorithm(const Dictionary&, WebCryptoOperation, WebCryptoAlgorithm&,
ErrorContext, AlgorithmError*); | 443 bool parseAlgorithm(const Dictionary&, WebCryptoOperation, WebCryptoAlgorithm&,
ErrorContext, AlgorithmError*); |
| 444 | 444 |
| 445 bool parseHash(const Dictionary& raw, WebCryptoAlgorithm& hash, ErrorContext con
text, AlgorithmError* error) | 445 bool parseHash(const Dictionary& raw, WebCryptoAlgorithm& hash, ErrorContext con
text, AlgorithmError* error) |
| 446 { | 446 { |
| 447 Dictionary rawHash; | 447 Dictionary rawHash; |
| 448 if (!DictionaryHelper::get(raw, "hash", rawHash)) { | 448 if (!raw.get("hash", rawHash)) { |
| 449 setSyntaxError(context.toString("hash", "Missing or not a dictionary"),
error); | 449 setSyntaxError(context.toString("hash", "Missing or not a dictionary"),
error); |
| 450 return false; | 450 return false; |
| 451 } | 451 } |
| 452 | 452 |
| 453 context.add("hash"); | 453 context.add("hash"); |
| 454 return parseAlgorithm(rawHash, WebCryptoOperationDigest, hash, context, erro
r); | 454 return parseAlgorithm(rawHash, WebCryptoOperationDigest, hash, context, erro
r); |
| 455 } | 455 } |
| 456 | 456 |
| 457 // Defined by the WebCrypto spec as: | 457 // Defined by the WebCrypto spec as: |
| 458 // | 458 // |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 bool parseAlgorithm(const Dictionary& raw, WebCryptoOperation op, WebCryptoAlgor
ithm& algorithm, ErrorContext context, AlgorithmError* error) | 678 bool parseAlgorithm(const Dictionary& raw, WebCryptoOperation op, WebCryptoAlgor
ithm& algorithm, ErrorContext context, AlgorithmError* error) |
| 679 { | 679 { |
| 680 context.add("Algorithm"); | 680 context.add("Algorithm"); |
| 681 | 681 |
| 682 if (!raw.isObject()) { | 682 if (!raw.isObject()) { |
| 683 setSyntaxError(context.toString("Not an object"), error); | 683 setSyntaxError(context.toString("Not an object"), error); |
| 684 return false; | 684 return false; |
| 685 } | 685 } |
| 686 | 686 |
| 687 String algorithmName; | 687 String algorithmName; |
| 688 if (!DictionaryHelper::get(raw, "name", algorithmName)) { | 688 if (!raw.get("name", algorithmName)) { |
| 689 setSyntaxError(context.toString("name", "Missing or not a string"), erro
r); | 689 setSyntaxError(context.toString("name", "Missing or not a string"), erro
r); |
| 690 return false; | 690 return false; |
| 691 } | 691 } |
| 692 | 692 |
| 693 WebCryptoAlgorithmId algorithmId; | 693 WebCryptoAlgorithmId algorithmId; |
| 694 if (!lookupAlgorithmIdByName(algorithmName, algorithmId)) { | 694 if (!lookupAlgorithmIdByName(algorithmName, algorithmId)) { |
| 695 // FIXME: The spec says to return a SyntaxError if the input contains | 695 // FIXME: The spec says to return a SyntaxError if the input contains |
| 696 // any non-ASCII characters. | 696 // any non-ASCII characters. |
| 697 setNotSupportedError(context.toString("Unrecognized name"), error); | 697 setNotSupportedError(context.toString("Unrecognized name"), error); |
| 698 return false; | 698 return false; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 720 } | 720 } |
| 721 | 721 |
| 722 } // namespace | 722 } // namespace |
| 723 | 723 |
| 724 bool normalizeAlgorithm(const Dictionary& raw, WebCryptoOperation op, WebCryptoA
lgorithm& algorithm, AlgorithmError* error) | 724 bool normalizeAlgorithm(const Dictionary& raw, WebCryptoOperation op, WebCryptoA
lgorithm& algorithm, AlgorithmError* error) |
| 725 { | 725 { |
| 726 return parseAlgorithm(raw, op, algorithm, ErrorContext(), error); | 726 return parseAlgorithm(raw, op, algorithm, ErrorContext(), error); |
| 727 } | 727 } |
| 728 | 728 |
| 729 } // namespace blink | 729 } // namespace blink |
| OLD | NEW |