Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: Source/modules/crypto/NormalizeAlgorithm.cpp

Issue 790373002: Address a FIXME. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 bool getOptionalUint32(const Dictionary& raw, const char* propertyName, bool& ha sValue, uint32_t& value, const ErrorContext& context, AlgorithmError* error) 401 bool getOptionalUint32(const Dictionary& raw, const char* propertyName, bool& ha sValue, uint32_t& value, const ErrorContext& context, AlgorithmError* error)
402 { 402 {
403 double number; 403 double number;
404 if (!getOptionalInteger(raw, propertyName, hasValue, number, 0, 0xFFFFFFFF, context, error)) 404 if (!getOptionalInteger(raw, propertyName, hasValue, number, 0, 0xFFFFFFFF, context, error))
405 return false; 405 return false;
406 if (hasValue) 406 if (hasValue)
407 value = number; 407 value = number;
408 return true; 408 return true;
409 } 409 }
410 410
411 bool getOptionalUint8(const Dictionary& raw, const char* propertyName, bool& has Value, uint8_t& value, const ErrorContext& context, AlgorithmError* error)
412 {
413 double number;
414 if (!getOptionalInteger(raw, propertyName, hasValue, number, 0, 0xFF, contex t, error))
415 return false;
416 if (hasValue)
417 value = number;
418 return true;
419 }
420
411 bool getAlgorithmIdentifier(const Dictionary& raw, const char* propertyName, Alg orithmIdentifier& value, const ErrorContext& context, AlgorithmError* error) 421 bool getAlgorithmIdentifier(const Dictionary& raw, const char* propertyName, Alg orithmIdentifier& value, const ErrorContext& context, AlgorithmError* error)
412 { 422 {
413 // FIXME: This is not correct: http://crbug.com/438060 423 // FIXME: This is not correct: http://crbug.com/438060
414 // (1) It may retrieve the property twice from the dictionary, whereas it 424 // (1) It may retrieve the property twice from the dictionary, whereas it
415 // should be reading the v8 value once to avoid issues with getters. 425 // should be reading the v8 value once to avoid issues with getters.
416 // (2) The value is stringified (whereas the spec says it should be an 426 // (2) The value is stringified (whereas the spec says it should be an
417 // instance of DOMString). 427 // instance of DOMString).
418 Dictionary dictionary; 428 Dictionary dictionary;
419 if (DictionaryHelper::get(raw, propertyName, dictionary) && !dictionary.isUn definedOrNull()) { 429 if (DictionaryHelper::get(raw, propertyName, dictionary) && !dictionary.isUn definedOrNull()) {
420 value.setDictionary(dictionary); 430 value.setDictionary(dictionary);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 593
584 params = adoptPtr(new WebCryptoAesCtrParams(length, counter.bytes(), counter .byteLength())); 594 params = adoptPtr(new WebCryptoAesCtrParams(length, counter.bytes(), counter .byteLength()));
585 return true; 595 return true;
586 } 596 }
587 597
588 // Defined by the WebCrypto spec as: 598 // Defined by the WebCrypto spec as:
589 // 599 //
590 // dictionary AesGcmParams : Algorithm { 600 // dictionary AesGcmParams : Algorithm {
591 // required BufferSource iv; 601 // required BufferSource iv;
592 // BufferSource additionalData; 602 // BufferSource additionalData;
593 // [EnforceRange] octet tagLength; // May be 0-128 603 // [EnforceRange] octet tagLength;
594 // } 604 // }
595 bool parseAesGcmParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error) 605 bool parseAesGcmParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
596 { 606 {
597 BufferSource ivBufferSource; 607 BufferSource ivBufferSource;
598 if (!getBufferSource(raw, "iv", ivBufferSource, context, error)) 608 if (!getBufferSource(raw, "iv", ivBufferSource, context, error))
599 return false; 609 return false;
600 610
601 bool hasAdditionalData; 611 bool hasAdditionalData;
602 BufferSource additionalDataBufferSource; 612 BufferSource additionalDataBufferSource;
603 if (!getOptionalBufferSource(raw, "additionalData", hasAdditionalData, addit ionalDataBufferSource, context, error)) 613 if (!getOptionalBufferSource(raw, "additionalData", hasAdditionalData, addit ionalDataBufferSource, context, error))
604 return false; 614 return false;
605 615
606 double tagLength; 616 uint8_t tagLength;
607 bool hasTagLength; 617 bool hasTagLength;
608 // FIXME: Layering -- should only enforce the WebIDL's "octet" range here, n ot the AES-CTR tagLength. 618 if (!getOptionalUint8(raw, "tagLength", hasTagLength, tagLength, context, er ror))
609 if (!getOptionalInteger(raw, "tagLength", hasTagLength, tagLength, 0, 128, c ontext, error))
610 return false; 619 return false;
611 620
612 DOMArrayPiece iv(ivBufferSource); 621 DOMArrayPiece iv(ivBufferSource);
613 DOMArrayPiece additionalData(additionalDataBufferSource); 622 DOMArrayPiece additionalData(additionalDataBufferSource);
614 623
615 params = adoptPtr(new WebCryptoAesGcmParams(iv.bytes(), iv.byteLength(), has AdditionalData, additionalData.bytes(), additionalData.byteLength(), hasTagLengt h, tagLength)); 624 params = adoptPtr(new WebCryptoAesGcmParams(iv.bytes(), iv.byteLength(), has AdditionalData, additionalData.bytes(), additionalData.byteLength(), hasTagLengt h, tagLength));
616 return true; 625 return true;
617 } 626 }
618 627
619 // Defined by the WebCrypto spec as: 628 // Defined by the WebCrypto spec as:
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 } 913 }
905 914
906 } // namespace 915 } // namespace
907 916
908 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W ebCryptoAlgorithm& algorithm, AlgorithmError* error) 917 bool normalizeAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, W ebCryptoAlgorithm& algorithm, AlgorithmError* error)
909 { 918 {
910 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error); 919 return parseAlgorithmIdentifier(raw, op, algorithm, ErrorContext(), error);
911 } 920 }
912 921
913 } // namespace blink 922 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698