Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1326)

Unified Diff: Source/modules/crypto/SubtleCrypto.cpp

Issue 21561004: WebCrypto: Add crypto.subtle.verify() to the platform interfaces. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add missing file common.js Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/crypto/SubtleCrypto.h ('k') | Source/modules/crypto/SubtleCrypto.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/crypto/SubtleCrypto.cpp
diff --git a/Source/modules/crypto/SubtleCrypto.cpp b/Source/modules/crypto/SubtleCrypto.cpp
index 1b2ea95c5352620101ad5e6a78cae9099accc73f..e6fd1183f098dfa6933840a9e42a08764bd34b68 100644
--- a/Source/modules/crypto/SubtleCrypto.cpp
+++ b/Source/modules/crypto/SubtleCrypto.cpp
@@ -101,7 +101,7 @@ bool keyCanBeUsedForAlgorithm(const WebKit::WebCryptoKey& key, const WebKit::Web
return false;
}
-PassRefPtr<CryptoOperation> createCryptoOperation(const Dictionary& rawAlgorithm, Key* key, AlgorithmOperation operationType, ExceptionState& es)
+PassRefPtr<CryptoOperation> createCryptoOperation(const Dictionary& rawAlgorithm, Key* key, AlgorithmOperation operationType, ArrayBufferView* signature, ExceptionState& es)
{
WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto();
if (!platformCrypto) {
@@ -126,6 +126,12 @@ PassRefPtr<CryptoOperation> createCryptoOperation(const Dictionary& rawAlgorithm
}
}
+ // Only Verify takes a signature.
+ if (operationType == Verify && !signature) {
+ es.throwDOMException(TypeError);
+ return 0;
+ }
+
RefPtr<CryptoOperationImpl> opImpl = CryptoOperationImpl::create();
WebKit::WebCryptoOperationResult result(opImpl.get());
@@ -139,6 +145,9 @@ PassRefPtr<CryptoOperation> createCryptoOperation(const Dictionary& rawAlgorithm
case Sign:
platformCrypto->sign(algorithm, key->key(), result);
break;
+ case Verify:
+ platformCrypto->verifySignature(algorithm, key->key(), reinterpret_cast<const unsigned char*>(signature->baseAddress()), signature->byteLength(), result);
+ break;
case Digest:
platformCrypto->digest(algorithm, result);
break;
@@ -161,28 +170,27 @@ SubtleCrypto::SubtleCrypto()
PassRefPtr<CryptoOperation> SubtleCrypto::encrypt(const Dictionary& rawAlgorithm, Key* key, ExceptionState& es)
{
- return createCryptoOperation(rawAlgorithm, key, Encrypt, es);
+ return createCryptoOperation(rawAlgorithm, key, Encrypt, 0, es);
}
PassRefPtr<CryptoOperation> SubtleCrypto::decrypt(const Dictionary& rawAlgorithm, Key* key, ExceptionState& es)
{
- return createCryptoOperation(rawAlgorithm, key, Decrypt, es);
+ return createCryptoOperation(rawAlgorithm, key, Decrypt, 0, es);
}
PassRefPtr<CryptoOperation> SubtleCrypto::sign(const Dictionary& rawAlgorithm, Key* key, ExceptionState& es)
{
- return createCryptoOperation(rawAlgorithm, key, Sign, es);
+ return createCryptoOperation(rawAlgorithm, key, Sign, 0, es);
}
-PassRefPtr<CryptoOperation> SubtleCrypto::verifySignature(const Dictionary& rawAlgorithm, Key* key, ExceptionState& es)
+PassRefPtr<CryptoOperation> SubtleCrypto::verifySignature(const Dictionary& rawAlgorithm, Key* key, ArrayBufferView* signature, ExceptionState& es)
{
- // FIXME
- return 0;
+ return createCryptoOperation(rawAlgorithm, key, Verify, signature, es);
}
PassRefPtr<CryptoOperation> SubtleCrypto::digest(const Dictionary& rawAlgorithm, ExceptionState& es)
{
- return createCryptoOperation(rawAlgorithm, 0, Digest, es);
+ return createCryptoOperation(rawAlgorithm, 0, Digest, 0, es);
}
ScriptObject SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView* keyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages, ExceptionState& es)
« no previous file with comments | « Source/modules/crypto/SubtleCrypto.h ('k') | Source/modules/crypto/SubtleCrypto.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698