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

Side by Side Diff: content/child/webcrypto/algorithm_dispatch.cc

Issue 794873002: Refactor: Remove switch statements on key format from algorithm_dispatch.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « no previous file | content/child/webcrypto/algorithm_implementation.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/webcrypto/algorithm_dispatch.h" 5 #include "content/child/webcrypto/algorithm_dispatch.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/child/webcrypto/algorithm_implementation.h" 8 #include "content/child/webcrypto/algorithm_implementation.h"
9 #include "content/child/webcrypto/algorithm_registry.h" 9 #include "content/child/webcrypto/algorithm_registry.h"
10 #include "content/child/webcrypto/crypto_data.h" 10 #include "content/child/webcrypto/crypto_data.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 Status ExportKeyDontCheckExtractability(blink::WebCryptoKeyFormat format, 53 Status ExportKeyDontCheckExtractability(blink::WebCryptoKeyFormat format,
54 const blink::WebCryptoKey& key, 54 const blink::WebCryptoKey& key,
55 std::vector<uint8_t>* buffer) { 55 std::vector<uint8_t>* buffer) {
56 const AlgorithmImplementation* impl = NULL; 56 const AlgorithmImplementation* impl = NULL;
57 Status status = GetAlgorithmImplementation(key.algorithm().id(), &impl); 57 Status status = GetAlgorithmImplementation(key.algorithm().id(), &impl);
58 if (status.IsError()) 58 if (status.IsError())
59 return status; 59 return status;
60 60
61 switch (format) { 61 return impl->ExportKey(format, key, buffer);
62 case blink::WebCryptoKeyFormatRaw:
63 return impl->ExportKeyRaw(key, buffer);
64 case blink::WebCryptoKeyFormatSpki:
65 return impl->ExportKeySpki(key, buffer);
66 case blink::WebCryptoKeyFormatPkcs8:
67 return impl->ExportKeyPkcs8(key, buffer);
68 case blink::WebCryptoKeyFormatJwk:
69 return impl->ExportKeyJwk(key, buffer);
70 default:
71 return Status::ErrorUnsupported();
72 }
73 } 62 }
74 63
75 } // namespace 64 } // namespace
76 65
77 Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, 66 Status Encrypt(const blink::WebCryptoAlgorithm& algorithm,
78 const blink::WebCryptoKey& key, 67 const blink::WebCryptoKey& key,
79 const CryptoData& data, 68 const CryptoData& data,
80 std::vector<uint8_t>* buffer) { 69 std::vector<uint8_t>* buffer) {
81 if (!KeyUsageAllows(key, blink::WebCryptoKeyUsageEncrypt)) 70 if (!KeyUsageAllows(key, blink::WebCryptoKeyUsageEncrypt))
82 return Status::ErrorUnexpected(); 71 return Status::ErrorUnexpected();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 blink::WebCryptoKey* key) { 130 blink::WebCryptoKey* key) {
142 const AlgorithmImplementation* impl = NULL; 131 const AlgorithmImplementation* impl = NULL;
143 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); 132 Status status = GetAlgorithmImplementation(algorithm.id(), &impl);
144 if (status.IsError()) 133 if (status.IsError())
145 return status; 134 return status;
146 135
147 status = impl->VerifyKeyUsagesBeforeImportKey(format, usages); 136 status = impl->VerifyKeyUsagesBeforeImportKey(format, usages);
148 if (status.IsError()) 137 if (status.IsError())
149 return status; 138 return status;
150 139
151 switch (format) { 140 return impl->ImportKey(format, key_data, algorithm, extractable, usages, key);
152 case blink::WebCryptoKeyFormatRaw:
153 return impl->ImportKeyRaw(key_data, algorithm, extractable, usages, key);
154 case blink::WebCryptoKeyFormatSpki:
155 return impl->ImportKeySpki(key_data, algorithm, extractable, usages, key);
156 case blink::WebCryptoKeyFormatPkcs8:
157 return impl->ImportKeyPkcs8(key_data, algorithm, extractable, usages,
158 key);
159 case blink::WebCryptoKeyFormatJwk:
160 return impl->ImportKeyJwk(key_data, algorithm, extractable, usages, key);
161 default:
162 return Status::ErrorUnsupported();
163 }
164 } 141 }
165 142
166 Status ExportKey(blink::WebCryptoKeyFormat format, 143 Status ExportKey(blink::WebCryptoKeyFormat format,
167 const blink::WebCryptoKey& key, 144 const blink::WebCryptoKey& key,
168 std::vector<uint8_t>* buffer) { 145 std::vector<uint8_t>* buffer) {
169 if (!key.extractable()) 146 if (!key.extractable())
170 return Status::ErrorKeyNotExtractable(); 147 return Status::ErrorKeyNotExtractable();
171 return ExportKeyDontCheckExtractability(format, key, buffer); 148 return ExportKeyDontCheckExtractability(format, key, buffer);
172 } 149 }
173 150
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 return false; 284 return false;
308 285
309 status = impl->DeserializeKeyForClone(algorithm, type, extractable, usages, 286 status = impl->DeserializeKeyForClone(algorithm, type, extractable, usages,
310 key_data, key); 287 key_data, key);
311 return status.IsSuccess(); 288 return status.IsSuccess();
312 } 289 }
313 290
314 } // namespace webcrypto 291 } // namespace webcrypto
315 292
316 } // namespace content 293 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/webcrypto/algorithm_implementation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698