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

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

Issue 255453002: [refactor] Use a lookup table rather than binary search for algorithm normalization. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 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
Index: Source/modules/crypto/SubtleCrypto.cpp
diff --git a/Source/modules/crypto/SubtleCrypto.cpp b/Source/modules/crypto/SubtleCrypto.cpp
index 492bf904befa56a364c5cf855449f1af7d15816b..6d749022b6e169f70556aa978bee645b99d2ee3f 100644
--- a/Source/modules/crypto/SubtleCrypto.cpp
+++ b/Source/modules/crypto/SubtleCrypto.cpp
@@ -150,6 +150,9 @@ ScriptPromise SubtleCrypto::generateKey(const Dictionary& rawAlgorithm, bool ext
if (!parseAlgorithm(rawAlgorithm, GenerateKey, algorithm, result.get()))
return promise;
+ if (!verifyUsagesAreConsistentForAlgorithm(algorithm.id(), keyUsages, result.get()))
+ return promise;
+
blink::Platform::current()->crypto()->generateKey(algorithm, extractable, keyUsages, result->result());
return promise;
}
@@ -174,6 +177,9 @@ ScriptPromise SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView*
if (!parseAlgorithm(rawAlgorithm, ImportKey, algorithm, result.get()))
return promise;
+ if (!verifyUsagesAreConsistentForAlgorithm(algorithm.id(), keyUsages, 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());
@@ -258,6 +264,9 @@ ScriptPromise SubtleCrypto::unwrapKey(const String& rawFormat, ArrayBufferView*
if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, ImportKey, unwrappedKeyAlgorithm, result.get()))
return promise;
+ if (!verifyUsagesAreConsistentForAlgorithm(unwrappedKeyAlgorithm.id(), keyUsages, result.get()))
+ return promise;
+
if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, UnwrapKey, result.get()))
return promise;

Powered by Google App Engine
This is Rietveld 408576698