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

Side by Side Diff: content/child/webcrypto/openssl/rsa_key_openssl.cc

Issue 786363002: Refactor: Extract common code for generating asymmetric keys to a helper. (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
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/openssl/rsa_key_openssl.h" 5 #include "content/child/webcrypto/openssl/rsa_key_openssl.h"
6 6
7 #include <openssl/evp.h> 7 #include <openssl/evp.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 extractable, usages, key); 150 extractable, usages, key);
151 } 151 }
152 152
153 } // namespace 153 } // namespace
154 154
155 Status RsaHashedAlgorithm::GenerateKey( 155 Status RsaHashedAlgorithm::GenerateKey(
156 const blink::WebCryptoAlgorithm& algorithm, 156 const blink::WebCryptoAlgorithm& algorithm,
157 bool extractable, 157 bool extractable,
158 blink::WebCryptoKeyUsageMask combined_usages, 158 blink::WebCryptoKeyUsageMask combined_usages,
159 GenerateKeyResult* result) const { 159 GenerateKeyResult* result) const {
160 Status status = CheckKeyCreationUsages( 160 blink::WebCryptoKeyUsageMask public_usages = 0;
161 all_public_key_usages_ | all_private_key_usages_, combined_usages); 161 blink::WebCryptoKeyUsageMask private_usages = 0;
162
163 Status status = GetUsagesForGenerateAsymmetricKey(
164 all_public_key_usages_, all_private_key_usages_, combined_usages,
165 &public_usages, &private_usages);
162 if (status.IsError()) 166 if (status.IsError())
163 return status; 167 return status;
164 168
165 const blink::WebCryptoKeyUsageMask public_usages =
166 combined_usages & all_public_key_usages_;
167 const blink::WebCryptoKeyUsageMask private_usages =
168 combined_usages & all_private_key_usages_;
169
170 if (private_usages == 0)
171 return Status::ErrorCreateKeyEmptyUsages();
172
173 const blink::WebCryptoRsaHashedKeyGenParams* params = 169 const blink::WebCryptoRsaHashedKeyGenParams* params =
174 algorithm.rsaHashedKeyGenParams(); 170 algorithm.rsaHashedKeyGenParams();
175 171
176 unsigned int public_exponent = 0; 172 unsigned int public_exponent = 0;
177 unsigned int modulus_length_bits = 0; 173 unsigned int modulus_length_bits = 0;
178 status = 174 status =
179 GetRsaKeyGenParameters(params, &public_exponent, &modulus_length_bits); 175 GetRsaKeyGenParameters(params, &public_exponent, &modulus_length_bits);
180 if (status.IsError()) 176 if (status.IsError())
181 return status; 177 return status;
182 178
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 key->algorithm().rsaHashedParams()->publicExponent().size())) { 440 key->algorithm().rsaHashedParams()->publicExponent().size())) {
445 return Status::ErrorUnexpected(); 441 return Status::ErrorUnexpected();
446 } 442 }
447 443
448 return Status::Success(); 444 return Status::Success();
449 } 445 }
450 446
451 } // namespace webcrypto 447 } // namespace webcrypto
452 448
453 } // namespace content 449 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/openssl/ec_key_openssl.cc ('k') | content/child/webcrypto/webcrypto_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698