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

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

Issue 787123003: Refactor: Extract some duplicated code for verifying usages during import of asymmetric key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (status.IsError()) 227 if (status.IsError())
228 return status; 228 return status;
229 229
230 result->AssignKeyPair(public_key, private_key); 230 result->AssignKeyPair(public_key, private_key);
231 return Status::Success(); 231 return Status::Success();
232 } 232 }
233 233
234 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey( 234 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey(
235 blink::WebCryptoKeyFormat format, 235 blink::WebCryptoKeyFormat format,
236 blink::WebCryptoKeyUsageMask usages) const { 236 blink::WebCryptoKeyUsageMask usages) const {
237 switch (format) { 237 return VerifyUsagesBeforeImportAsymmetricKey(format, all_public_key_usages_,
238 case blink::WebCryptoKeyFormatSpki: 238 all_private_key_usages_, usages);
239 return CheckKeyCreationUsages(all_public_key_usages_, usages);
240 case blink::WebCryptoKeyFormatPkcs8:
241 return CheckKeyCreationUsages(all_private_key_usages_, usages);
242 case blink::WebCryptoKeyFormatJwk:
243 // The JWK could represent either a public key or private key. The usages
244 // must make sense for one of the two. The usages will be checked again by
245 // ImportKeyJwk() once the key type has been determined.
246 if (CheckKeyCreationUsages(all_private_key_usages_, usages).IsSuccess() ||
247 CheckKeyCreationUsages(all_public_key_usages_, usages).IsSuccess()) {
248 return Status::Success();
249 }
250 return Status::ErrorCreateKeyBadUsages();
251 default:
252 return Status::ErrorUnsupportedImportKeyFormat();
253 }
254 } 239 }
255 240
256 Status RsaHashedAlgorithm::ImportKeyPkcs8( 241 Status RsaHashedAlgorithm::ImportKeyPkcs8(
257 const CryptoData& key_data, 242 const CryptoData& key_data,
258 const blink::WebCryptoAlgorithm& algorithm, 243 const blink::WebCryptoAlgorithm& algorithm,
259 bool extractable, 244 bool extractable,
260 blink::WebCryptoKeyUsageMask usages, 245 blink::WebCryptoKeyUsageMask usages,
261 blink::WebCryptoKey* key) const { 246 blink::WebCryptoKey* key) const {
262 crypto::ScopedEVP_PKEY private_key; 247 crypto::ScopedEVP_PKEY private_key;
263 Status status = 248 Status status =
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 key->algorithm().rsaHashedParams()->publicExponent().size())) { 429 key->algorithm().rsaHashedParams()->publicExponent().size())) {
445 return Status::ErrorUnexpected(); 430 return Status::ErrorUnexpected();
446 } 431 }
447 432
448 return Status::Success(); 433 return Status::Success();
449 } 434 }
450 435
451 } // namespace webcrypto 436 } // namespace webcrypto
452 437
453 } // namespace content 438 } // 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