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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 return nullptr; | 181 return nullptr; |
182 case WebKit::WebCryptoAlgorithmParamsTypeAesCbcParams: | 182 case WebKit::WebCryptoAlgorithmParamsTypeAesCbcParams: |
183 return parseAesCbcParams(raw); | 183 return parseAesCbcParams(raw); |
184 case WebKit::WebCryptoAlgorithmParamsTypeAesKeyGenParams: | 184 case WebKit::WebCryptoAlgorithmParamsTypeAesKeyGenParams: |
185 return parseAesKeyGenParams(raw); | 185 return parseAesKeyGenParams(raw); |
186 } | 186 } |
187 ASSERT_NOT_REACHED(); | 187 ASSERT_NOT_REACHED(); |
188 return nullptr; | 188 return nullptr; |
189 } | 189 } |
190 | 190 |
| 191 const AlgorithmInfo* algorithmInfo(const Dictionary& raw, ExceptionCode& ec) |
| 192 { |
| 193 String algorithmName; |
| 194 if (!raw.get("name", algorithmName)) { |
| 195 ec = NotSupportedError; |
| 196 return 0; |
| 197 } |
| 198 |
| 199 if (!algorithmName.containsOnlyASCII()) { |
| 200 ec = SyntaxError; |
| 201 return 0; |
| 202 } |
| 203 |
| 204 const AlgorithmInfo* info = AlgorithmRegistry::lookupAlgorithmByName(algorit
hmName); |
| 205 if (!info) { |
| 206 ec = NotSupportedError; |
| 207 return 0; |
| 208 } |
| 209 |
| 210 return info; |
| 211 } |
| 212 |
191 } // namespace | 213 } // namespace |
192 | 214 |
193 // FIXME: Throw the correct exception types! | 215 // FIXME: Throw the correct exception types! |
194 // This implementation corresponds with: | 216 // This implementation corresponds with: |
195 // http://www.w3.org/TR/WebCryptoAPI/#algorithm-normalizing-rules | 217 // http://www.w3.org/TR/WebCryptoAPI/#algorithm-normalizing-rules |
196 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We
bCryptoAlgorithm& algorithm, ExceptionCode& ec) | 218 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We
bCryptoAlgorithm& algorithm, ExceptionCode& ec) |
197 { | 219 { |
198 String algorithmName; | 220 const AlgorithmInfo* info = algorithmInfo(raw, ec); |
199 if (!raw.get("name", algorithmName)) { | 221 if (!info) |
200 ec = NotSupportedError; | |
201 return false; | 222 return false; |
202 } | |
203 | |
204 if (!algorithmName.containsOnlyASCII()) { | |
205 ec = SyntaxError; | |
206 return false; | |
207 } | |
208 | |
209 const AlgorithmInfo* info = AlgorithmRegistry::lookupAlgorithmByName(algorit
hmName); | |
210 if (!info) { | |
211 ec = NotSupportedError; | |
212 return false; | |
213 } | |
214 | 223 |
215 if (info->paramsForOperation[op] == UnsupportedOp) { | 224 if (info->paramsForOperation[op] == UnsupportedOp) { |
216 ec = NotSupportedError; | 225 ec = NotSupportedError; |
217 return false; | 226 return false; |
218 } | 227 } |
219 | 228 |
220 WebKit::WebCryptoAlgorithmParamsType paramsType = static_cast<WebKit::WebCry
ptoAlgorithmParamsType>(info->paramsForOperation[op]); | 229 WebKit::WebCryptoAlgorithmParamsType paramsType = static_cast<WebKit::WebCry
ptoAlgorithmParamsType>(info->paramsForOperation[op]); |
221 OwnPtr<WebKit::WebCryptoAlgorithmParams> params = parseAlgorithmParams(raw,
paramsType); | 230 OwnPtr<WebKit::WebCryptoAlgorithmParams> params = parseAlgorithmParams(raw,
paramsType); |
222 | 231 |
223 if (!params && paramsType != WebKit::WebCryptoAlgorithmParamsTypeNone) { | 232 if (!params && paramsType != WebKit::WebCryptoAlgorithmParamsTypeNone) { |
224 ec = NotSupportedError; | 233 ec = NotSupportedError; |
225 return false; | 234 return false; |
226 } | 235 } |
227 | 236 |
228 algorithm = WebKit::WebCryptoAlgorithm(info->algorithmId, info->algorithmNam
e, params.release()); | 237 algorithm = WebKit::WebCryptoAlgorithm(info->algorithmId, info->algorithmNam
e, params.release()); |
229 return true; | 238 return true; |
230 } | 239 } |
231 | 240 |
| 241 bool normalizeAlgorithmForImportKey(const Dictionary& raw, WebKit::WebCryptoAlgo
rithm& algorithm, ExceptionCode& ec) |
| 242 { |
| 243 const AlgorithmInfo* info = algorithmInfo(raw, ec); |
| 244 if (!info) |
| 245 return false; |
| 246 |
| 247 algorithm = WebKit::WebCryptoAlgorithm(info->algorithmId, info->algorithmNam
e, nullptr); |
| 248 return true; |
| 249 } |
| 250 |
232 } // namespace WebCore | 251 } // namespace WebCore |
OLD | NEW |