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

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

Issue 512023002: Refactor the interface for generating keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Run git-cl format Created 6 years, 2 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
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 const CryptoData& data, 95 const CryptoData& data,
96 std::vector<uint8_t>* buffer) { 96 std::vector<uint8_t>* buffer) {
97 const AlgorithmImplementation* impl = NULL; 97 const AlgorithmImplementation* impl = NULL;
98 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); 98 Status status = GetAlgorithmImplementation(algorithm.id(), &impl);
99 if (status.IsError()) 99 if (status.IsError())
100 return status; 100 return status;
101 101
102 return impl->Digest(algorithm, data, buffer); 102 return impl->Digest(algorithm, data, buffer);
103 } 103 }
104 104
105 Status GenerateSecretKey(const blink::WebCryptoAlgorithm& algorithm, 105 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
106 bool extractable, 106 bool extractable,
107 blink::WebCryptoKeyUsageMask usage_mask, 107 blink::WebCryptoKeyUsageMask usage_mask,
108 blink::WebCryptoKey* key) { 108 GenerateKeyResult* result) {
109 const AlgorithmImplementation* impl = NULL; 109 const AlgorithmImplementation* impl = NULL;
110 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); 110 Status status = GetAlgorithmImplementation(algorithm.id(), &impl);
111 if (status.IsError()) 111 if (status.IsError())
112 return status; 112 return status;
113 113
114 status = impl->VerifyKeyUsagesBeforeGenerateKey(usage_mask); 114 return impl->GenerateKey(algorithm, extractable, usage_mask, result);
115 if (status.IsError())
116 return status;
117
118 return impl->GenerateSecretKey(algorithm, extractable, usage_mask, key);
119 }
120
121 Status GenerateKeyPair(const blink::WebCryptoAlgorithm& algorithm,
122 bool extractable,
123 blink::WebCryptoKeyUsageMask combined_usage_mask,
124 blink::WebCryptoKey* public_key,
125 blink::WebCryptoKey* private_key) {
126 const AlgorithmImplementation* impl = NULL;
127 Status status = GetAlgorithmImplementation(algorithm.id(), &impl);
128 if (status.IsError())
129 return status;
130
131 blink::WebCryptoKeyUsageMask public_usage_mask;
132 blink::WebCryptoKeyUsageMask private_usage_mask;
133 status = impl->VerifyKeyUsagesBeforeGenerateKeyPair(
134 combined_usage_mask, &public_usage_mask, &private_usage_mask);
135 if (status.IsError())
136 return status;
137
138 return impl->GenerateKeyPair(algorithm,
139 extractable,
140 public_usage_mask,
141 private_usage_mask,
142 public_key,
143 private_key);
144 } 115 }
145 116
146 // Note that this function may be called from the target Blink thread. 117 // Note that this function may be called from the target Blink thread.
147 Status ImportKey(blink::WebCryptoKeyFormat format, 118 Status ImportKey(blink::WebCryptoKeyFormat format,
148 const CryptoData& key_data, 119 const CryptoData& key_data,
149 const blink::WebCryptoAlgorithm& algorithm, 120 const blink::WebCryptoAlgorithm& algorithm,
150 bool extractable, 121 bool extractable,
151 blink::WebCryptoKeyUsageMask usage_mask, 122 blink::WebCryptoKeyUsageMask usage_mask,
152 blink::WebCryptoKey* key) { 123 blink::WebCryptoKey* key) {
153 const AlgorithmImplementation* impl = NULL; 124 const AlgorithmImplementation* impl = NULL;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 247
277 scoped_ptr<blink::WebCryptoDigestor> CreateDigestor( 248 scoped_ptr<blink::WebCryptoDigestor> CreateDigestor(
278 blink::WebCryptoAlgorithmId algorithm) { 249 blink::WebCryptoAlgorithmId algorithm) {
279 PlatformInit(); 250 PlatformInit();
280 return CreatePlatformDigestor(algorithm); 251 return CreatePlatformDigestor(algorithm);
281 } 252 }
282 253
283 } // namespace webcrypto 254 } // namespace webcrypto
284 255
285 } // namespace content 256 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/algorithm_dispatch.h ('k') | content/child/webcrypto/algorithm_implementation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698