| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |