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

Unified Diff: third_party/WebKit/Source/modules/crypto/CryptoKey.cpp

Issue 2165713002: Change the error message in WebCrypto when using a key that has BOTH (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 | « third_party/WebKit/LayoutTests/crypto/subtle/rsa-oaep/key-manipulation-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/crypto/CryptoKey.cpp
diff --git a/third_party/WebKit/Source/modules/crypto/CryptoKey.cpp b/third_party/WebKit/Source/modules/crypto/CryptoKey.cpp
index b6a000942c8853e3e541bf855c5d05b3e9bb0548..c838d1e6810b9a4b6e73a9be4b5022173824830f 100644
--- a/third_party/WebKit/Source/modules/crypto/CryptoKey.cpp
+++ b/third_party/WebKit/Source/modules/crypto/CryptoKey.cpp
@@ -178,16 +178,30 @@ Vector<String> CryptoKey::usages() const
bool CryptoKey::canBeUsedForAlgorithm(const WebCryptoAlgorithm& algorithm, WebCryptoKeyUsage usage, CryptoResult* result) const
{
- if (!(m_key.usages() & usage)) {
- result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key.usages does not permit this operation");
- return false;
- }
+ // This order of tests on keys is done throughout the WebCrypto spec when
+ // testing if a key can be used for an algorithm.
+ //
+ // For instance here are the steps as written for encrypt():
+ //
+ // https://w3c.github.io/webcrypto/Overview.html#dfn-SubtleCrypto-method-encrypt
+ //
+ // (8) If the name member of normalizedAlgorithm is not equal to the name
+ // attribute of the [[algorithm]] internal slot of key then throw an
+ // InvalidAccessError.
+ //
+ // (9) If the [[usages]] internal slot of key does not contain an entry
+ // that is "encrypt", then throw an InvalidAccessError.
if (m_key.algorithm().id() != algorithm.id()) {
result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key.algorithm does not match that of operation");
return false;
}
+ if (!(m_key.usages() & usage)) {
+ result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key.usages does not permit this operation");
+ return false;
+ }
+
return true;
}
« no previous file with comments | « third_party/WebKit/LayoutTests/crypto/subtle/rsa-oaep/key-manipulation-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698