| Index: Source/modules/crypto/SubtleCrypto.cpp
|
| diff --git a/Source/modules/crypto/SubtleCrypto.cpp b/Source/modules/crypto/SubtleCrypto.cpp
|
| index 492bf904befa56a364c5cf855449f1af7d15816b..d0dd4e5435e45e680cd68f7a3a93593449ba87f0 100644
|
| --- a/Source/modules/crypto/SubtleCrypto.cpp
|
| +++ b/Source/modules/crypto/SubtleCrypto.cpp
|
| @@ -46,10 +46,9 @@ namespace {
|
|
|
| // Seems like the generated bindings should take care of these however it
|
| // currently doesn't. See also http://crbug.com/264520
|
| -template <typename T>
|
| -bool ensureNotNull(T* x, const char* paramName, CryptoResult* result)
|
| +bool ensureNotNull(const SubtleCrypto::Bytes& x, const char* paramName, CryptoResult* result)
|
| {
|
| - if (!x) {
|
| + if (x.isNull) {
|
| String message = String("Invalid ") + paramName + String(" argument");
|
| result->completeWithError(blink::WebCryptoErrorTypeType, blink::WebString(message));
|
| return false;
|
| @@ -57,7 +56,17 @@ bool ensureNotNull(T* x, const char* paramName, CryptoResult* result)
|
| return true;
|
| }
|
|
|
| -ScriptPromise startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, AlgorithmOperation operationType, ArrayBufferView* signature, ArrayBufferView* dataBuffer)
|
| +bool ensureNotNull(Key* key, const char* paramName, CryptoResult* result)
|
| +{
|
| + if (!key) {
|
| + String message = String("Invalid ") + paramName + String(" argument");
|
| + result->completeWithError(blink::WebCryptoErrorTypeType, blink::WebString(message));
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +ScriptPromise startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, AlgorithmOperation operationType, const SubtleCrypto::Bytes& signature, const SubtleCrypto::Bytes& dataBuffer)
|
| {
|
| RefPtr<CryptoResultImpl> result = CryptoResultImpl::create();
|
| ScriptPromise promise = result->promise();
|
| @@ -78,8 +87,8 @@ ScriptPromise startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, Alg
|
| if (requiresKey && !key->canBeUsedForAlgorithm(algorithm, operationType, result.get()))
|
| return promise;
|
|
|
| - const unsigned char* data = static_cast<const unsigned char*>(dataBuffer->baseAddress());
|
| - unsigned dataSize = dataBuffer->byteLength();
|
| + const unsigned char* data = dataBuffer.bytes;
|
| + unsigned dataSize = dataBuffer.size;
|
|
|
| switch (operationType) {
|
| case Encrypt:
|
| @@ -92,7 +101,7 @@ ScriptPromise startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, Alg
|
| blink::Platform::current()->crypto()->sign(algorithm, key->key(), data, dataSize, result->result());
|
| break;
|
| case Verify:
|
| - blink::Platform::current()->crypto()->verifySignature(algorithm, key->key(), reinterpret_cast<const unsigned char*>(signature->baseAddress()), signature->byteLength(), data, dataSize, result->result());
|
| + blink::Platform::current()->crypto()->verifySignature(algorithm, key->key(), signature.bytes, signature.size, data, dataSize, result->result());
|
| break;
|
| case Digest:
|
| blink::Platform::current()->crypto()->digest(algorithm, data, dataSize, result->result());
|
| @@ -107,34 +116,68 @@ ScriptPromise startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, Alg
|
|
|
| } // namespace
|
|
|
| +SubtleCrypto::Bytes::Bytes()
|
| +{
|
| + initNull();
|
| +}
|
| +
|
| +SubtleCrypto::Bytes::Bytes(ArrayBuffer* buffer)
|
| +{
|
| + if (buffer) {
|
| + bytes = static_cast<unsigned char*>(buffer->data());
|
| + size = buffer->byteLength();
|
| + isNull = false;
|
| + } else {
|
| + initNull();
|
| + }
|
| +}
|
| +
|
| +SubtleCrypto::Bytes::Bytes(ArrayBufferView* buffer)
|
| +{
|
| + if (buffer) {
|
| + bytes = static_cast<unsigned char*>(buffer->baseAddress());
|
| + size = buffer->byteLength();
|
| + isNull = false;
|
| + } else {
|
| + initNull();
|
| + }
|
| +}
|
| +
|
| +void SubtleCrypto::Bytes::initNull()
|
| +{
|
| + bytes = 0;
|
| + size = 0;
|
| + isNull = true;
|
| +}
|
| +
|
| SubtleCrypto::SubtleCrypto()
|
| {
|
| ScriptWrappable::init(this);
|
| }
|
|
|
| -ScriptPromise SubtleCrypto::encrypt(const Dictionary& rawAlgorithm, Key* key, ArrayBufferView* data)
|
| +ScriptPromise SubtleCrypto::encrypt(const Dictionary& rawAlgorithm, Key* key, const Bytes& data)
|
| {
|
| - return startCryptoOperation(rawAlgorithm, key, Encrypt, 0, data);
|
| + return startCryptoOperation(rawAlgorithm, key, Encrypt, Bytes(), data);
|
| }
|
|
|
| -ScriptPromise SubtleCrypto::decrypt(const Dictionary& rawAlgorithm, Key* key, ArrayBufferView* data)
|
| +ScriptPromise SubtleCrypto::decrypt(const Dictionary& rawAlgorithm, Key* key, const Bytes& data)
|
| {
|
| - return startCryptoOperation(rawAlgorithm, key, Decrypt, 0, data);
|
| + return startCryptoOperation(rawAlgorithm, key, Decrypt, Bytes(), data);
|
| }
|
|
|
| -ScriptPromise SubtleCrypto::sign(const Dictionary& rawAlgorithm, Key* key, ArrayBufferView* data)
|
| +ScriptPromise SubtleCrypto::sign(const Dictionary& rawAlgorithm, Key* key, const Bytes& data)
|
| {
|
| - return startCryptoOperation(rawAlgorithm, key, Sign, 0, data);
|
| + return startCryptoOperation(rawAlgorithm, key, Sign, Bytes(), data);
|
| }
|
|
|
| -ScriptPromise SubtleCrypto::verifySignature(const Dictionary& rawAlgorithm, Key* key, ArrayBufferView* signature, ArrayBufferView* data)
|
| +ScriptPromise SubtleCrypto::verifySignature(const Dictionary& rawAlgorithm, Key* key, const Bytes& signature, const Bytes& data)
|
| {
|
| return startCryptoOperation(rawAlgorithm, key, Verify, signature, data);
|
| }
|
|
|
| -ScriptPromise SubtleCrypto::digest(const Dictionary& rawAlgorithm, ArrayBufferView* data)
|
| +ScriptPromise SubtleCrypto::digest(const Dictionary& rawAlgorithm, const Bytes& data)
|
| {
|
| - return startCryptoOperation(rawAlgorithm, 0, Digest, 0, data);
|
| + return startCryptoOperation(rawAlgorithm, 0, Digest, Bytes(), data);
|
| }
|
|
|
| ScriptPromise SubtleCrypto::generateKey(const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages)
|
| @@ -154,7 +197,7 @@ ScriptPromise SubtleCrypto::generateKey(const Dictionary& rawAlgorithm, bool ext
|
| return promise;
|
| }
|
|
|
| -ScriptPromise SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView* keyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages)
|
| +ScriptPromise SubtleCrypto::importKey(const String& rawFormat, const Bytes& keyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages)
|
| {
|
| RefPtr<CryptoResultImpl> result = CryptoResultImpl::create();
|
| ScriptPromise promise = result->promise();
|
| @@ -174,9 +217,7 @@ ScriptPromise SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView*
|
| if (!parseAlgorithm(rawAlgorithm, ImportKey, algorithm, result.get()))
|
| return promise;
|
|
|
| - const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->baseAddress());
|
| -
|
| - blink::Platform::current()->crypto()->importKey(format, keyDataBytes, keyData->byteLength(), algorithm, extractable, keyUsages, result->result());
|
| + blink::Platform::current()->crypto()->importKey(format, keyData.bytes, keyData.size, algorithm, extractable, keyUsages, result->result());
|
| return promise;
|
| }
|
|
|
| @@ -232,7 +273,7 @@ ScriptPromise SubtleCrypto::wrapKey(const String& rawFormat, Key* key, Key* wrap
|
| return promise;
|
| }
|
|
|
| -ScriptPromise SubtleCrypto::unwrapKey(const String& rawFormat, ArrayBufferView* wrappedKey, Key* unwrappingKey, const Dictionary& rawUnwrapAlgorithm, const Dictionary& rawUnwrappedKeyAlgorithm, bool extractable, const Vector<String>& rawKeyUsages)
|
| +ScriptPromise SubtleCrypto::unwrapKey(const String& rawFormat, const Bytes& wrappedKey, Key* unwrappingKey, const Dictionary& rawUnwrapAlgorithm, const Dictionary& rawUnwrappedKeyAlgorithm, bool extractable, const Vector<String>& rawKeyUsages)
|
| {
|
| RefPtr<CryptoResultImpl> result = CryptoResultImpl::create();
|
| ScriptPromise promise = result->promise();
|
| @@ -261,10 +302,7 @@ ScriptPromise SubtleCrypto::unwrapKey(const String& rawFormat, ArrayBufferView*
|
| if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, UnwrapKey, result.get()))
|
| return promise;
|
|
|
| - const unsigned char* wrappedKeyData = static_cast<const unsigned char*>(wrappedKey->baseAddress());
|
| - unsigned wrappedKeyDataSize = wrappedKey->byteLength();
|
| -
|
| - blink::Platform::current()->crypto()->unwrapKey(format, wrappedKeyData, wrappedKeyDataSize, unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages, result->result());
|
| + blink::Platform::current()->crypto()->unwrapKey(format, wrappedKey.bytes, wrappedKey.size, unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages, result->result());
|
| return promise;
|
| }
|
|
|
|
|