| Index: third_party/WebKit/Source/modules/crypto/SubtleCrypto.cpp
|
| diff --git a/third_party/WebKit/Source/modules/crypto/SubtleCrypto.cpp b/third_party/WebKit/Source/modules/crypto/SubtleCrypto.cpp
|
| index 5b3f2e83ac1283188ae6045fbc76e562bfc81028..c6fcbdc5229f291cb0b4f0b63914854474273cfe 100644
|
| --- a/third_party/WebKit/Source/modules/crypto/SubtleCrypto.cpp
|
| +++ b/third_party/WebKit/Source/modules/crypto/SubtleCrypto.cpp
|
| @@ -44,10 +44,6 @@
|
| #include "public/platform/WebCrypto.h"
|
| #include "public/platform/WebCryptoAlgorithm.h"
|
|
|
| -// TODO(eroman): Change the public blink::WebCrypto interface to allow
|
| -// transferring ownership of data buffers instead of just taking
|
| -// a raw pointer+length. This will avoid an extra copy.
|
| -
|
| namespace blink {
|
|
|
| static bool parseAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op, WebCryptoAlgorithm& algorithm, CryptoResult* result)
|
| @@ -95,7 +91,7 @@ static bool copySequenceOfStringProperty(const char* property, const Dictionary&
|
| // an unpublished editor's draft for:
|
| // https://www.w3.org/Bugs/Public/show_bug.cgi?id=24963
|
| // See http://crbug.com/373917.
|
| -static bool copyJwkDictionaryToJson(const Dictionary& dict, Vector<uint8_t>& jsonUtf8, CryptoResult* result)
|
| +static bool copyJwkDictionaryToJson(const Dictionary& dict, WebVector<uint8_t>& jsonUtf8, CryptoResult* result)
|
| {
|
| RefPtr<JSONObject> jsonObject = JSONObject::create();
|
|
|
| @@ -117,16 +113,13 @@ static bool copyJwkDictionaryToJson(const Dictionary& dict, Vector<uint8_t>& jso
|
| copyStringProperty(propertyNames[i], dict, jsonObject.get());
|
|
|
| String json = jsonObject->toJSONString();
|
| - jsonUtf8.clear();
|
| - jsonUtf8.append(json.utf8().data(), json.utf8().length());
|
| + jsonUtf8 = WebVector<uint8_t>(json.utf8().data(), json.utf8().length());
|
| return true;
|
| }
|
|
|
| -static Vector<uint8_t> copyBytes(const DOMArrayPiece& source)
|
| +static WebVector<uint8_t> copyBytes(const DOMArrayPiece& source)
|
| {
|
| - Vector<uint8_t> result;
|
| - result.append(reinterpret_cast<const uint8_t*>(source.data()), source.byteLength());
|
| - return result;
|
| + return WebVector<uint8_t>(static_cast<uint8_t*>(source.data()), source.byteLength());
|
| }
|
|
|
| SubtleCrypto::SubtleCrypto()
|
| @@ -145,7 +138,7 @@ ScriptPromise SubtleCrypto::encrypt(ScriptState* scriptState, const AlgorithmIde
|
|
|
| // 14.3.1.2: Let data be the result of getting a copy of the bytes held by
|
| // the data parameter passed to the encrypt method.
|
| - Vector<uint8_t> data = copyBytes(rawData);
|
| + WebVector<uint8_t> data = copyBytes(rawData);
|
|
|
| WebCryptoAlgorithm algorithm;
|
| if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationEncrypt, algorithm, result))
|
| @@ -155,7 +148,7 @@ ScriptPromise SubtleCrypto::encrypt(ScriptState* scriptState, const AlgorithmIde
|
| return promise;
|
|
|
| histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key->key());
|
| - Platform::current()->crypto()->encrypt(algorithm, key->key(), data.data(), data.size(), result->result());
|
| + Platform::current()->crypto()->encrypt(algorithm, key->key(), std::move(data), result->result());
|
| return promise;
|
| }
|
|
|
| @@ -171,7 +164,7 @@ ScriptPromise SubtleCrypto::decrypt(ScriptState* scriptState, const AlgorithmIde
|
|
|
| // 14.3.2.2: Let data be the result of getting a copy of the bytes held by
|
| // the data parameter passed to the decrypt method.
|
| - Vector<uint8_t> data = copyBytes(rawData);
|
| + WebVector<uint8_t> data = copyBytes(rawData);
|
|
|
| WebCryptoAlgorithm algorithm;
|
| if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDecrypt, algorithm, result))
|
| @@ -181,7 +174,7 @@ ScriptPromise SubtleCrypto::decrypt(ScriptState* scriptState, const AlgorithmIde
|
| return promise;
|
|
|
| histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key->key());
|
| - Platform::current()->crypto()->decrypt(algorithm, key->key(), data.data(), data.size(), result->result());
|
| + Platform::current()->crypto()->decrypt(algorithm, key->key(), std::move(data), result->result());
|
| return promise;
|
| }
|
|
|
| @@ -197,7 +190,7 @@ ScriptPromise SubtleCrypto::sign(ScriptState* scriptState, const AlgorithmIdenti
|
|
|
| // 14.3.3.2: Let data be the result of getting a copy of the bytes held by
|
| // the data parameter passed to the sign method.
|
| - Vector<uint8_t> data = copyBytes(rawData);
|
| + WebVector<uint8_t> data = copyBytes(rawData);
|
|
|
| WebCryptoAlgorithm algorithm;
|
| if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationSign, algorithm, result))
|
| @@ -207,7 +200,7 @@ ScriptPromise SubtleCrypto::sign(ScriptState* scriptState, const AlgorithmIdenti
|
| return promise;
|
|
|
| histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key->key());
|
| - Platform::current()->crypto()->sign(algorithm, key->key(), data.data(), data.size(), result->result());
|
| + Platform::current()->crypto()->sign(algorithm, key->key(), std::move(data), result->result());
|
| return promise;
|
| }
|
|
|
| @@ -223,7 +216,7 @@ ScriptPromise SubtleCrypto::verifySignature(ScriptState* scriptState, const Algo
|
|
|
| // 14.3.4.2: Let signature be the result of getting a copy of the bytes
|
| // held by the signature parameter passed to the verify method.
|
| - Vector<uint8_t> signature = copyBytes(rawSignature);
|
| + WebVector<uint8_t> signature = copyBytes(rawSignature);
|
|
|
| WebCryptoAlgorithm algorithm;
|
| if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationVerify, algorithm, result))
|
| @@ -231,13 +224,13 @@ ScriptPromise SubtleCrypto::verifySignature(ScriptState* scriptState, const Algo
|
|
|
| // 14.3.4.5: Let data be the result of getting a copy of the bytes held by
|
| // the data parameter passed to the verify method.
|
| - Vector<uint8_t> data = copyBytes(rawData);
|
| + WebVector<uint8_t> data = copyBytes(rawData);
|
|
|
| if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageVerify, result))
|
| return promise;
|
|
|
| histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key->key());
|
| - Platform::current()->crypto()->verifySignature(algorithm, key->key(), signature.data(), signature.size(), data.data(), data.size(), result->result());
|
| + Platform::current()->crypto()->verifySignature(algorithm, key->key(), std::move(signature), std::move(data), result->result());
|
| return promise;
|
| }
|
|
|
| @@ -253,14 +246,14 @@ ScriptPromise SubtleCrypto::digest(ScriptState* scriptState, const AlgorithmIden
|
|
|
| // 14.3.5.2: Let data be the result of getting a copy of the bytes held
|
| // by the data parameter passed to the digest method.
|
| - Vector<uint8_t> data = copyBytes(rawData);
|
| + WebVector<uint8_t> data = copyBytes(rawData);
|
|
|
| WebCryptoAlgorithm algorithm;
|
| if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDigest, algorithm, result))
|
| return promise;
|
|
|
| histogramAlgorithm(scriptState->getExecutionContext(), algorithm);
|
| - Platform::current()->crypto()->digest(algorithm, data.data(), data.size(), result->result());
|
| + Platform::current()->crypto()->digest(algorithm, std::move(data), result->result());
|
| return promise;
|
| }
|
|
|
| @@ -317,7 +310,7 @@ ScriptPromise SubtleCrypto::importKey(ScriptState* scriptState, const String& ra
|
| if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationImportKey, algorithm, result))
|
| return promise;
|
|
|
| - Vector<uint8_t> keyData;
|
| + WebVector<uint8_t> keyData;
|
| if (rawKeyData.isArrayBuffer()) {
|
| keyData = copyBytes(rawKeyData.getAsArrayBuffer());
|
| } else if (rawKeyData.isArrayBufferView()) {
|
| @@ -327,7 +320,7 @@ ScriptPromise SubtleCrypto::importKey(ScriptState* scriptState, const String& ra
|
| return promise;
|
| }
|
| histogramAlgorithm(scriptState->getExecutionContext(), algorithm);
|
| - Platform::current()->crypto()->importKey(format, keyData.data(), keyData.size(), algorithm, extractable, keyUsages, result->result());
|
| + Platform::current()->crypto()->importKey(format, std::move(keyData), algorithm, extractable, keyUsages, result->result());
|
| return promise;
|
| }
|
|
|
| @@ -404,7 +397,7 @@ ScriptPromise SubtleCrypto::unwrapKey(ScriptState* scriptState, const String& ra
|
| // 14.3.12.2: Let wrappedKey be the result of getting a copy of the bytes
|
| // held by the wrappedKey parameter passed to the unwrapKey
|
| // method.
|
| - Vector<uint8_t> wrappedKey = copyBytes(rawWrappedKey);
|
| + WebVector<uint8_t> wrappedKey = copyBytes(rawWrappedKey);
|
|
|
| WebCryptoAlgorithm unwrapAlgorithm;
|
| if (!parseAlgorithm(rawUnwrapAlgorithm, WebCryptoOperationUnwrapKey, unwrapAlgorithm, result))
|
| @@ -419,7 +412,7 @@ ScriptPromise SubtleCrypto::unwrapKey(ScriptState* scriptState, const String& ra
|
|
|
| histogramAlgorithmAndKey(scriptState->getExecutionContext(), unwrapAlgorithm, unwrappingKey->key());
|
| histogramAlgorithm(scriptState->getExecutionContext(), unwrappedKeyAlgorithm);
|
| - Platform::current()->crypto()->unwrapKey(format, wrappedKey.data(), wrappedKey.size(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages, result->result());
|
| + Platform::current()->crypto()->unwrapKey(format, std::move(wrappedKey), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages, result->result());
|
| return promise;
|
| }
|
|
|
|
|