Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(654)

Side by Side Diff: Source/modules/crypto/NormalizeAlgorithm.cpp

Issue 19885002: WebCrypto: Add interfaces for importKey(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Move test stuff into MockWebCrypto Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 } // namespace 191 bool getAlgorithmInfo(const Dictionary& raw, const AlgorithmInfo*& info, Excepti onCode& ec)
abarth-chromium 2013/07/23 06:22:07 We generally try to avoid using "get" as a verb in
eroman 2013/07/23 23:29:02 Done.
192
193 // FIXME: Throw the correct exception types!
194 // This implementation corresponds with:
195 // http://www.w3.org/TR/WebCryptoAPI/#algorithm-normalizing-rules
196 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We bCryptoAlgorithm& algorithm, ExceptionCode& ec)
197 { 192 {
198 String algorithmName; 193 String algorithmName;
199 if (!raw.get("name", algorithmName)) { 194 if (!raw.get("name", algorithmName)) {
200 ec = NotSupportedError; 195 ec = NotSupportedError;
201 return false; 196 return false;
202 } 197 }
203 198
204 if (!algorithmName.containsOnlyASCII()) { 199 if (!algorithmName.containsOnlyASCII()) {
205 ec = SyntaxError; 200 ec = SyntaxError;
206 return false; 201 return false;
207 } 202 }
208 203
209 const AlgorithmInfo* info = AlgorithmRegistry::lookupAlgorithmByName(algorit hmName); 204 info = AlgorithmRegistry::lookupAlgorithmByName(algorithmName);
210 if (!info) { 205 if (!info) {
211 ec = NotSupportedError; 206 ec = NotSupportedError;
212 return false; 207 return false;
213 } 208 }
214 209
210 return true;
211 }
212
213 } // namespace
214
215 // FIXME: Throw the correct exception types!
216 // This implementation corresponds with:
217 // http://www.w3.org/TR/WebCryptoAPI/#algorithm-normalizing-rules
218 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We bCryptoAlgorithm& algorithm, ExceptionCode& ec)
219 {
220 const AlgorithmInfo* info;
abarth-chromium 2013/07/23 06:22:07 Please initialize scalars.
eroman 2013/07/23 23:29:02 Done.
221 if (!getAlgorithmInfo(raw, info, ec))
222 return false;
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;
244 if (!getAlgorithmInfo(raw, info, ec))
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698