Chromium Code Reviews| Index: Source/modules/crypto/SubtleCrypto.cpp |
| diff --git a/Source/modules/crypto/SubtleCrypto.cpp b/Source/modules/crypto/SubtleCrypto.cpp |
| index 84e0d868b0314332d7d63a5af6907075dd50b382..767f901298a252b2ae0d1ff288b49bad00708c04 100644 |
| --- a/Source/modules/crypto/SubtleCrypto.cpp |
| +++ b/Source/modules/crypto/SubtleCrypto.cpp |
| @@ -49,8 +49,14 @@ namespace WebCore { |
| namespace { |
| -// FIXME: Temporary |
| -PassRefPtr<CryptoOperation> dummyOperation(const Dictionary& rawAlgorithm, AlgorithmOperation operationType, ExceptionState& es) |
| +bool keyCanBeUsedForAlgorithm(const WebKit::WebCryptoKey& key, const WebKit::WebCryptoAlgorithm& algorithm, ExceptionState& es) |
| +{ |
| + // FIXME: Need to enforce that the key's algorithm matches the operation, |
| + // and that the key's usages allow it to be used with this operation. |
| + return true; |
| +} |
| + |
| +PassRefPtr<CryptoOperation> createCryptoOperation(const Dictionary& rawAlgorithm, Key* key, AlgorithmOperation operationType, ExceptionState& es) |
| { |
| WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto(); |
| if (!platformCrypto) { |
| @@ -62,9 +68,39 @@ PassRefPtr<CryptoOperation> dummyOperation(const Dictionary& rawAlgorithm, Algor |
| if (!normalizeAlgorithm(rawAlgorithm, operationType, algorithm, es)) |
| return 0; |
| + // All operations other than Digest require a valid Key. |
| + if (operationType != Digest) { |
| + if (!key) { |
| + es.throwDOMException(TypeError); |
| + return 0; |
| + } |
| + |
| + if (!keyCanBeUsedForAlgorithm(key->key(), algorithm, es)) { |
| + return 0; |
| + } |
| + } |
| + |
| RefPtr<CryptoOperationImpl> opImpl = CryptoOperationImpl::create(); |
| WebKit::WebCryptoOperationResult result(opImpl.get()); |
| - platformCrypto->digest(algorithm, result); |
| + |
| + switch (operationType) { |
| + case Encrypt: |
| + platformCrypto->encrypt(algorithm, key->key(), result); |
| + break; |
| + case Decrypt: |
| + platformCrypto->decrypt(algorithm, key->key(), result); |
| + break; |
| + case Sign: |
| + platformCrypto->sign(algorithm, key->key(), result); |
| + break; |
| + case Digest: |
| + platformCrypto->digest(algorithm, result); |
| + break; |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + return 0; |
| + } |
| + |
| if (opImpl->throwInitializationError(es)) |
| return 0; |
| return CryptoOperation::create(algorithm, opImpl.get()); |
| @@ -77,44 +113,30 @@ SubtleCrypto::SubtleCrypto() |
| ScriptWrappable::init(this); |
| } |
| -PassRefPtr<CryptoOperation> SubtleCrypto::encrypt(const Dictionary& rawAlgorithm, Key*, ExceptionState& es) |
| +PassRefPtr<CryptoOperation> SubtleCrypto::encrypt(const Dictionary& rawAlgorithm, Key* key, ExceptionState& es) |
| { |
| - return dummyOperation(rawAlgorithm, Encrypt, es); |
| + return createCryptoOperation(rawAlgorithm, key, Encrypt, es); |
| } |
| -PassRefPtr<CryptoOperation> SubtleCrypto::decrypt(const Dictionary& rawAlgorithm, Key*, ExceptionState& es) |
| +PassRefPtr<CryptoOperation> SubtleCrypto::decrypt(const Dictionary& rawAlgorithm, Key* key, ExceptionState& es) |
| { |
| - return dummyOperation(rawAlgorithm, Decrypt, es); |
| + return createCryptoOperation(rawAlgorithm, key, Decrypt, es); |
| } |
| -PassRefPtr<CryptoOperation> SubtleCrypto::sign(const Dictionary& rawAlgorithm, Key*, ExceptionState& es) |
| +PassRefPtr<CryptoOperation> SubtleCrypto::sign(const Dictionary& rawAlgorithm, Key* key, ExceptionState& es) |
| { |
| - return dummyOperation(rawAlgorithm, Sign, es); |
| + return createCryptoOperation(rawAlgorithm, key, Sign, es); |
| } |
| -PassRefPtr<CryptoOperation> SubtleCrypto::verifySignature(const Dictionary& rawAlgorithm, Key*, ExceptionState& es) |
| +PassRefPtr<CryptoOperation> SubtleCrypto::verifySignature(const Dictionary& rawAlgorithm, Key* key, ExceptionState& es) |
| { |
| - return dummyOperation(rawAlgorithm, Verify, es); |
| + // FIXME |
|
abarth-chromium
2013/07/31 00:59:59
Rather than an empty FIXME comment, you can call t
eroman
2013/07/31 01:23:16
Done.
|
| + return 0; |
| } |
| PassRefPtr<CryptoOperation> SubtleCrypto::digest(const Dictionary& rawAlgorithm, ExceptionState& es) |
| { |
| - WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto(); |
| - if (!platformCrypto) { |
| - es.throwDOMException(NotSupportedError); |
| - return 0; |
| - } |
| - |
| - WebKit::WebCryptoAlgorithm algorithm; |
| - if (!normalizeAlgorithm(rawAlgorithm, Digest, algorithm, es)) |
| - return 0; |
| - |
| - RefPtr<CryptoOperationImpl> opImpl = CryptoOperationImpl::create(); |
| - WebKit::WebCryptoOperationResult result(opImpl.get()); |
| - platformCrypto->digest(algorithm, result); |
| - if (opImpl->throwInitializationError(es)) |
| - return 0; |
| - return CryptoOperation::create(algorithm, opImpl.get()); |
| + return createCryptoOperation(rawAlgorithm, 0, Digest, es); |
| } |
| ScriptObject SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView* keyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages, ExceptionState& es) |