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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { 171 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) {
172 WebCryptoKeyUsage usage = keyUsageMappings[i].value; 172 WebCryptoKeyUsage usage = keyUsageMappings[i].value;
173 if (m_key.usages() & usage) 173 if (m_key.usages() & usage)
174 result.append(keyUsageToString(usage)); 174 result.append(keyUsageToString(usage));
175 } 175 }
176 return result; 176 return result;
177 } 177 }
178 178
179 bool CryptoKey::canBeUsedForAlgorithm(const WebCryptoAlgorithm& algorithm, WebCr yptoKeyUsage usage, CryptoResult* result) const 179 bool CryptoKey::canBeUsedForAlgorithm(const WebCryptoAlgorithm& algorithm, WebCr yptoKeyUsage usage, CryptoResult* result) const
180 { 180 {
181 if (!(m_key.usages() & usage)) { 181 // This order of tests on keys is done throughout the WebCrypto spec when
182 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key.usages d oes not permit this operation"); 182 // testing if a key can be used for an algorithm.
183 return false; 183 //
184 } 184 // For instance here are the steps as written for encrypt():
185 //
186 // https://w3c.github.io/webcrypto/Overview.html#dfn-SubtleCrypto-method-enc rypt
187 //
188 // (8) If the name member of normalizedAlgorithm is not equal to the name
189 // attribute of the [[algorithm]] internal slot of key then throw an
190 // InvalidAccessError.
191 //
192 // (9) If the [[usages]] internal slot of key does not contain an entry
193 // that is "encrypt", then throw an InvalidAccessError.
185 194
186 if (m_key.algorithm().id() != algorithm.id()) { 195 if (m_key.algorithm().id() != algorithm.id()) {
187 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key.algorith m does not match that of operation"); 196 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key.algorith m does not match that of operation");
188 return false; 197 return false;
189 } 198 }
190 199
200 if (!(m_key.usages() & usage)) {
201 result->completeWithError(WebCryptoErrorTypeInvalidAccess, "key.usages d oes not permit this operation");
202 return false;
203 }
204
191 return true; 205 return true;
192 } 206 }
193 207
194 bool CryptoKey::parseFormat(const String& formatString, WebCryptoKeyFormat& form at, CryptoResult* result) 208 bool CryptoKey::parseFormat(const String& formatString, WebCryptoKeyFormat& form at, CryptoResult* result)
195 { 209 {
196 // There are few enough values that testing serially is fast enough. 210 // There are few enough values that testing serially is fast enough.
197 if (formatString == "raw") { 211 if (formatString == "raw") {
198 format = WebCryptoKeyFormatRaw; 212 format = WebCryptoKeyFormatRaw;
199 return true; 213 return true;
200 } 214 }
(...skipping 22 matching lines...) Expand all
223 if (!usage) { 237 if (!usage) {
224 result->completeWithError(WebCryptoErrorTypeType, "Invalid keyUsages argument"); 238 result->completeWithError(WebCryptoErrorTypeType, "Invalid keyUsages argument");
225 return false; 239 return false;
226 } 240 }
227 mask |= usage; 241 mask |= usage;
228 } 242 }
229 return true; 243 return true;
230 } 244 }
231 245
232 } // namespace blink 246 } // namespace blink
OLDNEW
« 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