| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 { | 168 { |
| 169 Vector<String> result; | 169 Vector<String> result; |
| 170 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { | 170 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { |
| 171 blink::WebCryptoKeyUsage usage = keyUsageMappings[i].value; | 171 blink::WebCryptoKeyUsage usage = keyUsageMappings[i].value; |
| 172 if (m_key.usages() & usage) | 172 if (m_key.usages() & usage) |
| 173 result.append(keyUsageToString(usage)); | 173 result.append(keyUsageToString(usage)); |
| 174 } | 174 } |
| 175 return result; | 175 return result; |
| 176 } | 176 } |
| 177 | 177 |
| 178 bool Key::canBeUsedForAlgorithm(const blink::WebCryptoAlgorithm& algorithm, Algo
rithmOperation op, ExceptionState& es) const | 178 bool Key::canBeUsedForAlgorithm(const blink::WebCryptoAlgorithm& algorithm, Algo
rithmOperation op, ExceptionState& exceptionState) const |
| 179 { | 179 { |
| 180 if (!(m_key.usages() & toKeyUsage(op))) { | 180 if (!(m_key.usages() & toKeyUsage(op))) { |
| 181 es.throwDOMException(NotSupportedError, "key.usages does not permit this
operation"); | 181 exceptionState.throwDOMException(NotSupportedError, "key.usages does not
permit this operation"); |
| 182 return false; | 182 return false; |
| 183 } | 183 } |
| 184 | 184 |
| 185 if (m_key.algorithm().id() != algorithm.id()) { | 185 if (m_key.algorithm().id() != algorithm.id()) { |
| 186 es.throwDOMException(NotSupportedError, "key.algorithm does not match th
at of operation"); | 186 exceptionState.throwDOMException(NotSupportedError, "key.algorithm does
not match that of operation"); |
| 187 return false; | 187 return false; |
| 188 } | 188 } |
| 189 | 189 |
| 190 // Verify that the algorithm-specific parameters for the key conform to the | 190 // Verify that the algorithm-specific parameters for the key conform to the |
| 191 // algorithm. | 191 // algorithm. |
| 192 | 192 |
| 193 if (m_key.algorithm().id() == blink::WebCryptoAlgorithmIdHmac) { | 193 if (m_key.algorithm().id() == blink::WebCryptoAlgorithmIdHmac) { |
| 194 blink::WebCryptoAlgorithmId keyHash; | 194 blink::WebCryptoAlgorithmId keyHash; |
| 195 blink::WebCryptoAlgorithmId algorithmHash; | 195 blink::WebCryptoAlgorithmId algorithmHash; |
| 196 if (!getHmacHashId(m_key.algorithm(), keyHash) || !getHmacHashId(algorit
hm, algorithmHash) || keyHash != algorithmHash) { | 196 if (!getHmacHashId(m_key.algorithm(), keyHash) || !getHmacHashId(algorit
hm, algorithmHash) || keyHash != algorithmHash) { |
| 197 es.throwDOMException(NotSupportedError, "key.algorithm does not matc
h that of operation (HMAC's hash differs)"); | 197 exceptionState.throwDOMException(NotSupportedError, "key.algorithm d
oes not match that of operation (HMAC's hash differs)"); |
| 198 return false; | 198 return false; |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 return true; | 202 return true; |
| 203 } | 203 } |
| 204 | 204 |
| 205 bool Key::parseFormat(const String& formatString, blink::WebCryptoKeyFormat& for
mat, ExceptionState& es) | 205 bool Key::parseFormat(const String& formatString, blink::WebCryptoKeyFormat& for
mat, ExceptionState& exceptionState) |
| 206 { | 206 { |
| 207 // There are few enough values that testing serially is fast enough. | 207 // There are few enough values that testing serially is fast enough. |
| 208 if (formatString == "raw") { | 208 if (formatString == "raw") { |
| 209 format = blink::WebCryptoKeyFormatRaw; | 209 format = blink::WebCryptoKeyFormatRaw; |
| 210 return true; | 210 return true; |
| 211 } | 211 } |
| 212 if (formatString == "pkcs8") { | 212 if (formatString == "pkcs8") { |
| 213 format = blink::WebCryptoKeyFormatPkcs8; | 213 format = blink::WebCryptoKeyFormatPkcs8; |
| 214 return true; | 214 return true; |
| 215 } | 215 } |
| 216 if (formatString == "spki") { | 216 if (formatString == "spki") { |
| 217 format = blink::WebCryptoKeyFormatSpki; | 217 format = blink::WebCryptoKeyFormatSpki; |
| 218 return true; | 218 return true; |
| 219 } | 219 } |
| 220 if (formatString == "jwk") { | 220 if (formatString == "jwk") { |
| 221 format = blink::WebCryptoKeyFormatJwk; | 221 format = blink::WebCryptoKeyFormatJwk; |
| 222 return true; | 222 return true; |
| 223 } | 223 } |
| 224 | 224 |
| 225 es.throwTypeError("Invalid keyFormat argument"); | 225 exceptionState.throwTypeError("Invalid keyFormat argument"); |
| 226 return false; | 226 return false; |
| 227 } | 227 } |
| 228 | 228 |
| 229 bool Key::parseUsageMask(const Vector<String>& usages, blink::WebCryptoKeyUsageM
ask& mask, ExceptionState& es) | 229 bool Key::parseUsageMask(const Vector<String>& usages, blink::WebCryptoKeyUsageM
ask& mask, ExceptionState& exceptionState) |
| 230 { | 230 { |
| 231 mask = 0; | 231 mask = 0; |
| 232 for (size_t i = 0; i < usages.size(); ++i) { | 232 for (size_t i = 0; i < usages.size(); ++i) { |
| 233 blink::WebCryptoKeyUsageMask usage = keyUsageStringToMask(usages[i]); | 233 blink::WebCryptoKeyUsageMask usage = keyUsageStringToMask(usages[i]); |
| 234 if (!usage) { | 234 if (!usage) { |
| 235 es.throwTypeError("Invalid keyUsages argument"); | 235 exceptionState.throwTypeError("Invalid keyUsages argument"); |
| 236 return false; | 236 return false; |
| 237 } | 237 } |
| 238 mask |= usage; | 238 mask |= usage; |
| 239 } | 239 } |
| 240 return true; | 240 return true; |
| 241 } | 241 } |
| 242 | 242 |
| 243 } // namespace WebCore | 243 } // namespace WebCore |
| OLD | NEW |