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

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

Issue 507873002: Remove some duplicated code, and make rsa_key_nss.cc more closely match rsa_key_openssl.cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/webcrypto_util.h" 5 #include "content/child/webcrypto/webcrypto_util.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 base::ListValue* CreateJwkKeyOpsFromWebCryptoUsages( 128 base::ListValue* CreateJwkKeyOpsFromWebCryptoUsages(
129 blink::WebCryptoKeyUsageMask usage_mask) { 129 blink::WebCryptoKeyUsageMask usage_mask) {
130 base::ListValue* jwk_key_ops = new base::ListValue(); 130 base::ListValue* jwk_key_ops = new base::ListValue();
131 for (size_t i = 0; i < arraysize(kJwkWebCryptoUsageMap); ++i) { 131 for (size_t i = 0; i < arraysize(kJwkWebCryptoUsageMap); ++i) {
132 if (usage_mask & kJwkWebCryptoUsageMap[i].webcrypto_usage) 132 if (usage_mask & kJwkWebCryptoUsageMap[i].webcrypto_usage)
133 jwk_key_ops->AppendString(kJwkWebCryptoUsageMap[i].jwk_key_op); 133 jwk_key_ops->AppendString(kJwkWebCryptoUsageMap[i].jwk_key_op);
134 } 134 }
135 return jwk_key_ops; 135 return jwk_key_ops;
136 } 136 }
137 137
138 blink::WebCryptoAlgorithm GetInnerHashAlgorithm(
139 const blink::WebCryptoAlgorithm& algorithm) {
140 DCHECK(!algorithm.isNull());
141 switch (algorithm.paramsType()) {
142 case blink::WebCryptoAlgorithmParamsTypeHmacImportParams:
143 return algorithm.hmacImportParams()->hash();
144 case blink::WebCryptoAlgorithmParamsTypeHmacKeyGenParams:
145 return algorithm.hmacKeyGenParams()->hash();
146 case blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams:
147 return algorithm.rsaHashedImportParams()->hash();
148 case blink::WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams:
149 return algorithm.rsaHashedKeyGenParams()->hash();
150 default:
151 return blink::WebCryptoAlgorithm::createNull();
152 }
153 }
154
155 blink::WebCryptoAlgorithm CreateAlgorithm(blink::WebCryptoAlgorithmId id) { 138 blink::WebCryptoAlgorithm CreateAlgorithm(blink::WebCryptoAlgorithmId id) {
156 return blink::WebCryptoAlgorithm::adoptParamsAndCreate(id, NULL); 139 return blink::WebCryptoAlgorithm::adoptParamsAndCreate(id, NULL);
157 } 140 }
158 141
159 blink::WebCryptoAlgorithm CreateHmacImportAlgorithm( 142 blink::WebCryptoAlgorithm CreateHmacImportAlgorithm(
160 blink::WebCryptoAlgorithmId hash_id) { 143 blink::WebCryptoAlgorithmId hash_id) {
161 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id)); 144 DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id));
162 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( 145 return blink::WebCryptoAlgorithm::adoptParamsAndCreate(
163 blink::WebCryptoAlgorithmIdHmac, 146 blink::WebCryptoAlgorithmIdHmac,
164 new blink::WebCryptoHmacImportParams(CreateAlgorithm(hash_id))); 147 new blink::WebCryptoHmacImportParams(CreateAlgorithm(hash_id)));
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // avoid feeding OpenSSL data that will hang use a whitelist. 281 // avoid feeding OpenSSL data that will hang use a whitelist.
299 if (*public_exponent != 3 && *public_exponent != 65537) 282 if (*public_exponent != 3 && *public_exponent != 65537)
300 return Status::ErrorGenerateKeyPublicExponent(); 283 return Status::ErrorGenerateKeyPublicExponent();
301 284
302 return Status::Success(); 285 return Status::Success();
303 } 286 }
304 287
305 } // namespace webcrypto 288 } // namespace webcrypto
306 289
307 } // namespace content 290 } // namespace content
OLDNEW
« content/child/webcrypto/nss/rsa_key_nss.cc ('K') | « content/child/webcrypto/webcrypto_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698