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

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

Issue 22849026: WebCrypto: Check for HmacKeyParams when seeing if a Key can be used for an Algorithm. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase onto master Created 7 years, 4 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/Key.cpp ('k') | no next file » | 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 237569fa18a9a75aac46b96d8d8de2c264a442f5..66545a1ab3e40bdbbdd97b4482903a5d9ec71472 100644
--- a/Source/modules/crypto/SubtleCrypto.cpp
+++ b/Source/modules/crypto/SubtleCrypto.cpp
@@ -41,7 +41,7 @@
#include "public/platform/Platform.h"
#include "public/platform/WebArrayBuffer.h"
#include "public/platform/WebCrypto.h"
-#include "public/platform/WebCryptoAlgorithmParams.h"
+#include "public/platform/WebCryptoAlgorithm.h"
#include "wtf/ArrayBufferView.h"
namespace WebCore {
@@ -117,56 +117,6 @@ private:
bool m_finished;
};
-WebKit::WebCryptoKeyUsageMask toKeyUsage(AlgorithmOperation operation)
-{
- switch (operation) {
- case Encrypt:
- return WebKit::WebCryptoKeyUsageEncrypt;
- case Decrypt:
- return WebKit::WebCryptoKeyUsageDecrypt;
- case Sign:
- return WebKit::WebCryptoKeyUsageSign;
- case Verify:
- return WebKit::WebCryptoKeyUsageVerify;
- case DeriveKey:
- return WebKit::WebCryptoKeyUsageDeriveKey;
- case WrapKey:
- return WebKit::WebCryptoKeyUsageWrapKey;
- case UnwrapKey:
- return WebKit::WebCryptoKeyUsageUnwrapKey;
- case Digest:
- case GenerateKey:
- case ImportKey:
- case NumberOfAlgorithmOperations:
- break;
- }
-
- ASSERT_NOT_REACHED();
- return 0;
-}
-
-bool keyCanBeUsedForAlgorithm(const WebKit::WebCryptoKey& key, const WebKit::WebCryptoAlgorithm& algorithm, AlgorithmOperation op)
-{
- if (!(key.usages() & toKeyUsage(op)))
- return false;
-
- if (key.algorithm().id() != algorithm.id())
- return false;
-
- if (key.algorithm().paramsType() == WebKit::WebCryptoAlgorithmParamsTypeNone)
- return true;
-
- // Verify that the algorithm-specific parameters for the key conform to the
- // algorithm.
-
- if (key.algorithm().paramsType() == WebKit::WebCryptoAlgorithmParamsTypeHmacParams) {
- return key.algorithm().hmacParams()->hash().id() == algorithm.hmacParams()->hash().id();
- }
-
- ASSERT_NOT_REACHED();
- return false;
-}
-
ScriptObject startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, AlgorithmOperation operationType, ArrayBufferView* signature, ArrayBufferView* dataBuffer, ExceptionState& es)
{
WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto();
@@ -186,10 +136,8 @@ ScriptObject startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, Algo
return ScriptObject();
}
- if (!keyCanBeUsedForAlgorithm(key->key(), algorithm, operationType)) {
- es.throwDOMException(NotSupportedError);
+ if (!key->canBeUsedForAlgorithm(algorithm, operationType, es))
return ScriptObject();
- }
}
// Only Verify takes a signature.
« no previous file with comments | « Source/modules/crypto/Key.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698