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& exceptionState) const | 178 bool Key::canBeUsedForAlgorithm(const blink::WebCryptoAlgorithm& algorithm, Algo
rithmOperation op, String& errorDetails) const |
179 { | 179 { |
180 if (!(m_key.usages() & toKeyUsage(op))) { | 180 if (!(m_key.usages() & toKeyUsage(op))) { |
181 exceptionState.throwDOMException(NotSupportedError, "key.usages does not
permit this operation"); | 181 errorDetails = "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 exceptionState.throwDOMException(NotSupportedError, "key.algorithm does
not match that of operation"); | 186 errorDetails = "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 // FIXME: Verify that this is complete. | 192 // FIXME: This is incomplete and not future proof. Operational parameters |
| 193 // should be enumerated when defining new parameters. |
193 | 194 |
194 if (m_key.algorithm().id() == blink::WebCryptoAlgorithmIdHmac) { | 195 if (m_key.algorithm().id() == blink::WebCryptoAlgorithmIdHmac) { |
195 blink::WebCryptoAlgorithmId keyHash; | 196 blink::WebCryptoAlgorithmId keyHash; |
196 blink::WebCryptoAlgorithmId algorithmHash; | 197 blink::WebCryptoAlgorithmId algorithmHash; |
197 if (!getHmacHashId(m_key.algorithm(), keyHash) || !getHmacHashId(algorit
hm, algorithmHash) || keyHash != algorithmHash) { | 198 if (!getHmacHashId(m_key.algorithm(), keyHash) || !getHmacHashId(algorit
hm, algorithmHash) || keyHash != algorithmHash) { |
198 exceptionState.throwDOMException(NotSupportedError, "key.algorithm d
oes not match that of operation (HMAC's hash differs)"); | 199 errorDetails = "key.algorithm does not match that of operation (HMAC
's hash differs)"; |
199 return false; | 200 return false; |
200 } | 201 } |
201 } | 202 } |
202 | 203 |
203 return true; | 204 return true; |
204 } | 205 } |
205 | 206 |
206 bool Key::parseFormat(const String& formatString, blink::WebCryptoKeyFormat& for
mat, ExceptionState& exceptionState) | 207 bool Key::parseFormat(const String& formatString, blink::WebCryptoKeyFormat& for
mat, ExceptionState& exceptionState) |
207 { | 208 { |
208 // There are few enough values that testing serially is fast enough. | 209 // There are few enough values that testing serially is fast enough. |
(...skipping 26 matching lines...) Expand all Loading... |
235 if (!usage) { | 236 if (!usage) { |
236 exceptionState.throwTypeError("Invalid keyUsages argument"); | 237 exceptionState.throwTypeError("Invalid keyUsages argument"); |
237 return false; | 238 return false; |
238 } | 239 } |
239 mask |= usage; | 240 mask |= usage; |
240 } | 241 } |
241 return true; | 242 return true; |
242 } | 243 } |
243 | 244 |
244 } // namespace WebCore | 245 } // namespace WebCore |
OLD | NEW |