| Index: third_party/WebKit/Source/modules/crypto/NormalizeAlgorithm.cpp
|
| diff --git a/third_party/WebKit/Source/modules/crypto/NormalizeAlgorithm.cpp b/third_party/WebKit/Source/modules/crypto/NormalizeAlgorithm.cpp
|
| index caf063811aec299c0ac76e1e1354fd885ea10057..d09a7b0f0f7fc89a2a87814d0a4e568affd4efd1 100644
|
| --- a/third_party/WebKit/Source/modules/crypto/NormalizeAlgorithm.cpp
|
| +++ b/third_party/WebKit/Source/modules/crypto/NormalizeAlgorithm.cpp
|
| @@ -40,9 +40,11 @@
|
| #include "public/platform/WebCryptoAlgorithmParams.h"
|
| #include "public/platform/WebString.h"
|
| #include "wtf/MathExtras.h"
|
| +#include "wtf/PtrUtil.h"
|
| #include "wtf/Vector.h"
|
| #include "wtf/text/StringBuilder.h"
|
| #include <algorithm>
|
| +#include <memory>
|
|
|
| namespace blink {
|
|
|
| @@ -447,7 +449,7 @@ bool getAlgorithmIdentifier(const Dictionary& raw, const char* propertyName, Alg
|
| // dictionary AesCbcParams : Algorithm {
|
| // required BufferSource iv;
|
| // };
|
| -bool parseAesCbcParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseAesCbcParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| BufferSource ivBufferSource;
|
| if (!getBufferSource(raw, "iv", ivBufferSource, context, error))
|
| @@ -455,7 +457,7 @@ bool parseAesCbcParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
|
|
|
| DOMArrayPiece iv(ivBufferSource);
|
|
|
| - params = adoptPtr(new WebCryptoAesCbcParams(iv.bytes(), iv.byteLength()));
|
| + params = wrapUnique(new WebCryptoAesCbcParams(iv.bytes(), iv.byteLength()));
|
| return true;
|
| }
|
|
|
| @@ -464,13 +466,13 @@ bool parseAesCbcParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
|
| // dictionary AesKeyGenParams : Algorithm {
|
| // [EnforceRange] required unsigned short length;
|
| // };
|
| -bool parseAesKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseAesKeyGenParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| uint16_t length;
|
| if (!getUint16(raw, "length", length, context, error))
|
| return false;
|
|
|
| - params = adoptPtr(new WebCryptoAesKeyGenParams(length));
|
| + params = wrapUnique(new WebCryptoAesKeyGenParams(length));
|
| return true;
|
| }
|
|
|
| @@ -496,7 +498,7 @@ bool parseHash(const Dictionary& raw, WebCryptoAlgorithm& hash, ErrorContext con
|
| // FIXME: http://crbug.com/438475: The current implementation differs from the
|
| // spec in that the "hash" parameter is required. This seems more sensible, and
|
| // is being proposed as a change to the spec. (https://www.w3.org/Bugs/Public/show_bug.cgi?id=27448).
|
| -bool parseHmacImportParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseHmacImportParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| WebCryptoAlgorithm hash;
|
| if (!parseHash(raw, hash, context, error))
|
| @@ -507,7 +509,7 @@ bool parseHmacImportParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParam
|
| if (!getOptionalUint32(raw, "length", hasLength, length, context, error))
|
| return false;
|
|
|
| - params = adoptPtr(new WebCryptoHmacImportParams(hash, hasLength, length));
|
| + params = wrapUnique(new WebCryptoHmacImportParams(hash, hasLength, length));
|
| return true;
|
| }
|
|
|
| @@ -517,7 +519,7 @@ bool parseHmacImportParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParam
|
| // required HashAlgorithmIdentifier hash;
|
| // [EnforceRange] unsigned long length;
|
| // };
|
| -bool parseHmacKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseHmacKeyGenParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| WebCryptoAlgorithm hash;
|
| if (!parseHash(raw, hash, context, error))
|
| @@ -528,7 +530,7 @@ bool parseHmacKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParam
|
| if (!getOptionalUint32(raw, "length", hasLength, length, context, error))
|
| return false;
|
|
|
| - params = adoptPtr(new WebCryptoHmacKeyGenParams(hash, hasLength, length));
|
| + params = wrapUnique(new WebCryptoHmacKeyGenParams(hash, hasLength, length));
|
| return true;
|
| }
|
|
|
| @@ -537,13 +539,13 @@ bool parseHmacKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParam
|
| // dictionary RsaHashedImportParams : Algorithm {
|
| // required HashAlgorithmIdentifier hash;
|
| // };
|
| -bool parseRsaHashedImportParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseRsaHashedImportParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| WebCryptoAlgorithm hash;
|
| if (!parseHash(raw, hash, context, error))
|
| return false;
|
|
|
| - params = adoptPtr(new WebCryptoRsaHashedImportParams(hash));
|
| + params = wrapUnique(new WebCryptoRsaHashedImportParams(hash));
|
| return true;
|
| }
|
|
|
| @@ -557,7 +559,7 @@ bool parseRsaHashedImportParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithm
|
| // dictionary RsaHashedKeyGenParams : RsaKeyGenParams {
|
| // required HashAlgorithmIdentifier hash;
|
| // };
|
| -bool parseRsaHashedKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseRsaHashedKeyGenParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| uint32_t modulusLength;
|
| if (!getUint32(raw, "modulusLength", modulusLength, context, error))
|
| @@ -571,7 +573,7 @@ bool parseRsaHashedKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithm
|
| if (!parseHash(raw, hash, context, error))
|
| return false;
|
|
|
| - params = adoptPtr(new WebCryptoRsaHashedKeyGenParams(hash, modulusLength, static_cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteLength()));
|
| + params = wrapUnique(new WebCryptoRsaHashedKeyGenParams(hash, modulusLength, static_cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteLength()));
|
| return true;
|
| }
|
|
|
| @@ -581,7 +583,7 @@ bool parseRsaHashedKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithm
|
| // required BufferSource counter;
|
| // [EnforceRange] required octet length;
|
| // };
|
| -bool parseAesCtrParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseAesCtrParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| BufferSource counterBufferSource;
|
| if (!getBufferSource(raw, "counter", counterBufferSource, context, error))
|
| @@ -592,7 +594,7 @@ bool parseAesCtrParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
|
| if (!getUint8(raw, "length", length, context, error))
|
| return false;
|
|
|
| - params = adoptPtr(new WebCryptoAesCtrParams(length, counter.bytes(), counter.byteLength()));
|
| + params = wrapUnique(new WebCryptoAesCtrParams(length, counter.bytes(), counter.byteLength()));
|
| return true;
|
| }
|
|
|
| @@ -603,7 +605,7 @@ bool parseAesCtrParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
|
| // BufferSource additionalData;
|
| // [EnforceRange] octet tagLength;
|
| // }
|
| -bool parseAesGcmParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseAesGcmParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| BufferSource ivBufferSource;
|
| if (!getBufferSource(raw, "iv", ivBufferSource, context, error))
|
| @@ -622,7 +624,7 @@ bool parseAesGcmParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
|
| DOMArrayPiece iv(ivBufferSource);
|
| DOMArrayPiece additionalData(additionalDataBufferSource, DOMArrayPiece::AllowNullPointToNullWithZeroSize);
|
|
|
| - params = adoptPtr(new WebCryptoAesGcmParams(iv.bytes(), iv.byteLength(), hasAdditionalData, additionalData.bytes(), additionalData.byteLength(), hasTagLength, tagLength));
|
| + params = wrapUnique(new WebCryptoAesGcmParams(iv.bytes(), iv.byteLength(), hasAdditionalData, additionalData.bytes(), additionalData.byteLength(), hasTagLength, tagLength));
|
| return true;
|
| }
|
|
|
| @@ -631,7 +633,7 @@ bool parseAesGcmParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
|
| // dictionary RsaOaepParams : Algorithm {
|
| // BufferSource label;
|
| // };
|
| -bool parseRsaOaepParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseRsaOaepParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| bool hasLabel;
|
| BufferSource labelBufferSource;
|
| @@ -639,7 +641,7 @@ bool parseRsaOaepParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
|
| return false;
|
|
|
| DOMArrayPiece label(labelBufferSource, DOMArrayPiece::AllowNullPointToNullWithZeroSize);
|
| - params = adoptPtr(new WebCryptoRsaOaepParams(hasLabel, label.bytes(), label.byteLength()));
|
| + params = wrapUnique(new WebCryptoRsaOaepParams(hasLabel, label.bytes(), label.byteLength()));
|
| return true;
|
| }
|
|
|
| @@ -648,13 +650,13 @@ bool parseRsaOaepParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
|
| // dictionary RsaPssParams : Algorithm {
|
| // [EnforceRange] required unsigned long saltLength;
|
| // };
|
| -bool parseRsaPssParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseRsaPssParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| uint32_t saltLengthBytes;
|
| if (!getUint32(raw, "saltLength", saltLengthBytes, context, error))
|
| return false;
|
|
|
| - params = adoptPtr(new WebCryptoRsaPssParams(saltLengthBytes));
|
| + params = wrapUnique(new WebCryptoRsaPssParams(saltLengthBytes));
|
| return true;
|
| }
|
|
|
| @@ -663,13 +665,13 @@ bool parseRsaPssParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
|
| // dictionary EcdsaParams : Algorithm {
|
| // required HashAlgorithmIdentifier hash;
|
| // };
|
| -bool parseEcdsaParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseEcdsaParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| WebCryptoAlgorithm hash;
|
| if (!parseHash(raw, hash, context, error))
|
| return false;
|
|
|
| - params = adoptPtr(new WebCryptoEcdsaParams(hash));
|
| + params = wrapUnique(new WebCryptoEcdsaParams(hash));
|
| return true;
|
| }
|
|
|
| @@ -711,13 +713,13 @@ bool parseNamedCurve(const Dictionary& raw, WebCryptoNamedCurve& namedCurve, Err
|
| // dictionary EcKeyGenParams : Algorithm {
|
| // required NamedCurve namedCurve;
|
| // };
|
| -bool parseEcKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseEcKeyGenParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| WebCryptoNamedCurve namedCurve;
|
| if (!parseNamedCurve(raw, namedCurve, context, error))
|
| return false;
|
|
|
| - params = adoptPtr(new WebCryptoEcKeyGenParams(namedCurve));
|
| + params = wrapUnique(new WebCryptoEcKeyGenParams(namedCurve));
|
| return true;
|
| }
|
|
|
| @@ -726,13 +728,13 @@ bool parseEcKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>
|
| // dictionary EcKeyImportParams : Algorithm {
|
| // required NamedCurve namedCurve;
|
| // };
|
| -bool parseEcKeyImportParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseEcKeyImportParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| WebCryptoNamedCurve namedCurve;
|
| if (!parseNamedCurve(raw, namedCurve, context, error))
|
| return false;
|
|
|
| - params = adoptPtr(new WebCryptoEcKeyImportParams(namedCurve));
|
| + params = wrapUnique(new WebCryptoEcKeyImportParams(namedCurve));
|
| return true;
|
| }
|
|
|
| @@ -741,7 +743,7 @@ bool parseEcKeyImportParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPara
|
| // dictionary EcdhKeyDeriveParams : Algorithm {
|
| // required CryptoKey public;
|
| // };
|
| -bool parseEcdhKeyDeriveParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseEcdhKeyDeriveParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| v8::Local<v8::Value> v8Value;
|
| if (!raw.get("public", v8Value)) {
|
| @@ -755,7 +757,7 @@ bool parseEcdhKeyDeriveParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa
|
| return false;
|
| }
|
|
|
| - params = adoptPtr(new WebCryptoEcdhKeyDeriveParams(cryptoKey->key()));
|
| + params = wrapUnique(new WebCryptoEcdhKeyDeriveParams(cryptoKey->key()));
|
| return true;
|
| }
|
|
|
| @@ -766,7 +768,7 @@ bool parseEcdhKeyDeriveParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa
|
| // [EnforceRange] required unsigned long iterations;
|
| // required HashAlgorithmIdentifier hash;
|
| // };
|
| -bool parsePbkdf2Params(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parsePbkdf2Params(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| BufferSource saltBufferSource;
|
| if (!getBufferSource(raw, "salt", saltBufferSource, context, error))
|
| @@ -781,7 +783,7 @@ bool parsePbkdf2Params(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
|
| WebCryptoAlgorithm hash;
|
| if (!parseHash(raw, hash, context, error))
|
| return false;
|
| - params = adoptPtr(new WebCryptoPbkdf2Params(hash, salt.bytes(), salt.byteLength(), iterations));
|
| + params = wrapUnique(new WebCryptoPbkdf2Params(hash, salt.bytes(), salt.byteLength(), iterations));
|
| return true;
|
| }
|
|
|
| @@ -790,13 +792,13 @@ bool parsePbkdf2Params(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
|
| // dictionary AesDerivedKeyParams : Algorithm {
|
| // [EnforceRange] required unsigned short length;
|
| // };
|
| -bool parseAesDerivedKeyParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseAesDerivedKeyParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| uint16_t length;
|
| if (!getUint16(raw, "length", length, context, error))
|
| return false;
|
|
|
| - params = adoptPtr(new WebCryptoAesDerivedKeyParams(length));
|
| + params = wrapUnique(new WebCryptoAesDerivedKeyParams(length));
|
| return true;
|
| }
|
|
|
| @@ -812,7 +814,7 @@ bool parseAesDerivedKeyParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa
|
| // required BufferSource salt;
|
| // required BufferSource info;
|
| // };
|
| -bool parseHkdfParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| +bool parseHkdfParams(const Dictionary& raw, std::unique_ptr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
|
| {
|
| WebCryptoAlgorithm hash;
|
| if (!parseHash(raw, hash, context, error))
|
| @@ -827,11 +829,11 @@ bool parseHkdfParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& pa
|
| DOMArrayPiece salt(saltBufferSource);
|
| DOMArrayPiece info(infoBufferSource);
|
|
|
| - params = adoptPtr(new WebCryptoHkdfParams(hash, salt.bytes(), salt.byteLength(), info.bytes(), info.byteLength()));
|
| + params = wrapUnique(new WebCryptoHkdfParams(hash, salt.bytes(), salt.byteLength(), info.bytes(), info.byteLength()));
|
| return true;
|
| }
|
|
|
| -bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType type, OwnPtr<WebCryptoAlgorithmParams>& params, ErrorContext& context, AlgorithmError* error)
|
| +bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType type, std::unique_ptr<WebCryptoAlgorithmParams>& params, ErrorContext& context, AlgorithmError* error)
|
| {
|
| switch (type) {
|
| case WebCryptoAlgorithmParamsTypeNone:
|
| @@ -942,7 +944,7 @@ bool parseAlgorithmDictionary(const String& algorithmName, const Dictionary& raw
|
|
|
| WebCryptoAlgorithmParamsType paramsType = static_cast<WebCryptoAlgorithmParamsType>(algorithmInfo->operationToParamsType[op]);
|
|
|
| - OwnPtr<WebCryptoAlgorithmParams> params;
|
| + std::unique_ptr<WebCryptoAlgorithmParams> params;
|
| if (!parseAlgorithmParams(raw, paramsType, params, context, error))
|
| return false;
|
|
|
|
|