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