Index: Source/modules/crypto/SubtleCrypto.cpp |
diff --git a/Source/modules/crypto/SubtleCrypto.cpp b/Source/modules/crypto/SubtleCrypto.cpp |
index bedab6a280d5e9f809633385a757fbcb35b76572..601d04bb8324df74846d3b6d6645f980c8439e14 100644 |
--- a/Source/modules/crypto/SubtleCrypto.cpp |
+++ b/Source/modules/crypto/SubtleCrypto.cpp |
@@ -38,6 +38,7 @@ |
#include "public/platform/Platform.h" |
#include "public/platform/WebCrypto.h" |
#include "public/platform/WebCryptoAlgorithm.h" |
+#include "public/platform/WebCryptoAlgorithmOperation.h" |
#include "wtf/ArrayBufferView.h" |
namespace WebCore { |
@@ -66,16 +67,25 @@ bool ensureNotNull(Key* key, const char* paramName, CryptoResult* result) |
return true; |
} |
-ScriptPromise startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, AlgorithmOperation operationType, const ArrayPiece& signature, const ArrayPiece& dataBuffer) |
+bool parseAlgorithm(const Dictionary& raw, blink::AlgorithmOperation op, blink::WebCryptoAlgorithm& algorithm, CryptoResult* result) |
+{ |
+ AlgorithmError error; |
+ bool success = normalizeAlgorithm(raw, op, algorithm, &error); |
+ if (!success) |
+ result->completeWithError(error.errorType, error.errorDetails); |
+ return success; |
+} |
+ |
+ScriptPromise startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, blink::AlgorithmOperation operationType, const ArrayPiece& signature, const ArrayPiece& dataBuffer) |
{ |
RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(); |
ScriptPromise promise = result->promise(); |
- bool requiresKey = operationType != Digest; |
+ bool requiresKey = operationType != blink::Digest; |
if (requiresKey && !ensureNotNull(key, "key", result.get())) |
return promise; |
- if (operationType == Verify && !ensureNotNull(signature, "signature", result.get())) |
+ if (operationType == blink::Verify && !ensureNotNull(signature, "signature", result.get())) |
return promise; |
if (!ensureNotNull(dataBuffer, "dataBuffer", result.get())) |
return promise; |
@@ -91,19 +101,19 @@ ScriptPromise startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, Alg |
unsigned dataSize = dataBuffer.byteLength(); |
switch (operationType) { |
- case Encrypt: |
+ case blink::Encrypt: |
blink::Platform::current()->crypto()->encrypt(algorithm, key->key(), data, dataSize, result->result()); |
break; |
- case Decrypt: |
+ case blink::Decrypt: |
blink::Platform::current()->crypto()->decrypt(algorithm, key->key(), data, dataSize, result->result()); |
break; |
- case Sign: |
+ case blink::Sign: |
blink::Platform::current()->crypto()->sign(algorithm, key->key(), data, dataSize, result->result()); |
break; |
- case Verify: |
+ case blink::Verify: |
blink::Platform::current()->crypto()->verifySignature(algorithm, key->key(), signature.bytes(), signature.byteLength(), data, dataSize, result->result()); |
break; |
- case Digest: |
+ case blink::Digest: |
blink::Platform::current()->crypto()->digest(algorithm, data, dataSize, result->result()); |
break; |
default: |
@@ -123,27 +133,27 @@ SubtleCrypto::SubtleCrypto() |
ScriptPromise SubtleCrypto::encrypt(const Dictionary& rawAlgorithm, Key* key, const ArrayPiece& data) |
{ |
- return startCryptoOperation(rawAlgorithm, key, Encrypt, ArrayPiece(), data); |
+ return startCryptoOperation(rawAlgorithm, key, blink::Encrypt, ArrayPiece(), data); |
} |
ScriptPromise SubtleCrypto::decrypt(const Dictionary& rawAlgorithm, Key* key, const ArrayPiece& data) |
{ |
- return startCryptoOperation(rawAlgorithm, key, Decrypt, ArrayPiece(), data); |
+ return startCryptoOperation(rawAlgorithm, key, blink::Decrypt, ArrayPiece(), data); |
} |
ScriptPromise SubtleCrypto::sign(const Dictionary& rawAlgorithm, Key* key, const ArrayPiece& data) |
{ |
- return startCryptoOperation(rawAlgorithm, key, Sign, ArrayPiece(), data); |
+ return startCryptoOperation(rawAlgorithm, key, blink::Sign, ArrayPiece(), data); |
} |
ScriptPromise SubtleCrypto::verifySignature(const Dictionary& rawAlgorithm, Key* key, const ArrayPiece& signature, const ArrayPiece& data) |
{ |
- return startCryptoOperation(rawAlgorithm, key, Verify, signature, data); |
+ return startCryptoOperation(rawAlgorithm, key, blink::Verify, signature, data); |
} |
ScriptPromise SubtleCrypto::digest(const Dictionary& rawAlgorithm, const ArrayPiece& data) |
{ |
- return startCryptoOperation(rawAlgorithm, 0, Digest, ArrayPiece(), data); |
+ return startCryptoOperation(rawAlgorithm, 0, blink::Digest, ArrayPiece(), data); |
} |
ScriptPromise SubtleCrypto::generateKey(const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) |
@@ -156,7 +166,7 @@ ScriptPromise SubtleCrypto::generateKey(const Dictionary& rawAlgorithm, bool ext |
return promise; |
blink::WebCryptoAlgorithm algorithm; |
- if (!parseAlgorithm(rawAlgorithm, GenerateKey, algorithm, result.get())) |
+ if (!parseAlgorithm(rawAlgorithm, blink::GenerateKey, algorithm, result.get())) |
return promise; |
blink::Platform::current()->crypto()->generateKey(algorithm, extractable, keyUsages, result->result()); |
@@ -180,7 +190,7 @@ ScriptPromise SubtleCrypto::importKey(const String& rawFormat, const ArrayPiece& |
return promise; |
blink::WebCryptoAlgorithm algorithm; |
- if (!parseAlgorithm(rawAlgorithm, ImportKey, algorithm, result.get())) |
+ if (!parseAlgorithm(rawAlgorithm, blink::ImportKey, algorithm, result.get())) |
return promise; |
blink::Platform::current()->crypto()->importKey(format, keyData.bytes(), keyData.byteLength(), algorithm, extractable, keyUsages, result->result()); |
@@ -224,7 +234,7 @@ ScriptPromise SubtleCrypto::wrapKey(const String& rawFormat, Key* key, Key* wrap |
return promise; |
blink::WebCryptoAlgorithm wrapAlgorithm; |
- if (!parseAlgorithm(rawWrapAlgorithm, WrapKey, wrapAlgorithm, result.get())) |
+ if (!parseAlgorithm(rawWrapAlgorithm, blink::WrapKey, wrapAlgorithm, result.get())) |
return promise; |
if (!key->extractable()) { |
@@ -232,7 +242,7 @@ ScriptPromise SubtleCrypto::wrapKey(const String& rawFormat, Key* key, Key* wrap |
return promise; |
} |
- if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, WrapKey, result.get())) |
+ if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, blink::WrapKey, result.get())) |
return promise; |
blink::Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKey->key(), wrapAlgorithm, result->result()); |
@@ -258,14 +268,14 @@ ScriptPromise SubtleCrypto::unwrapKey(const String& rawFormat, const ArrayPiece& |
return promise; |
blink::WebCryptoAlgorithm unwrapAlgorithm; |
- if (!parseAlgorithm(rawUnwrapAlgorithm, UnwrapKey, unwrapAlgorithm, result.get())) |
+ if (!parseAlgorithm(rawUnwrapAlgorithm, blink::UnwrapKey, unwrapAlgorithm, result.get())) |
return promise; |
blink::WebCryptoAlgorithm unwrappedKeyAlgorithm; |
- if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, ImportKey, unwrappedKeyAlgorithm, result.get())) |
+ if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, blink::ImportKey, unwrappedKeyAlgorithm, result.get())) |
return promise; |
- if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, UnwrapKey, result.get())) |
+ if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, blink::UnwrapKey, result.get())) |
return promise; |
blink::Platform::current()->crypto()->unwrapKey(format, wrappedKey.bytes(), wrappedKey.byteLength(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages, result->result()); |