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

Side by Side Diff: content/child/webcrypto/nss/rsa_key_nss.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
« no previous file with comments | « no previous file | content/child/webcrypto/openssl/ec_key_openssl.cc » ('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/nss/rsa_key_nss.h" 5 #include "content/child/webcrypto/nss/rsa_key_nss.h"
6 6
7 #include <secasn1.h> 7 #include <secasn1.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "content/child/webcrypto/crypto_data.h" 10 #include "content/child/webcrypto/crypto_data.h"
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 private_key_handle.release(), blink::WebCryptoKeyTypePrivate, extractable, 581 private_key_handle.release(), blink::WebCryptoKeyTypePrivate, extractable,
582 key_algorithm, private_usages); 582 key_algorithm, private_usages);
583 583
584 result->AssignKeyPair(public_key, private_key); 584 result->AssignKeyPair(public_key, private_key);
585 return Status::Success(); 585 return Status::Success();
586 } 586 }
587 587
588 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey( 588 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey(
589 blink::WebCryptoKeyFormat format, 589 blink::WebCryptoKeyFormat format,
590 blink::WebCryptoKeyUsageMask usages) const { 590 blink::WebCryptoKeyUsageMask usages) const {
591 switch (format) { 591 return VerifyUsagesBeforeImportAsymmetricKey(format, all_public_key_usages_,
592 case blink::WebCryptoKeyFormatSpki: 592 all_private_key_usages_, usages);
593 return CheckKeyCreationUsages(all_public_key_usages_, usages);
594 case blink::WebCryptoKeyFormatPkcs8:
595 return CheckKeyCreationUsages(all_private_key_usages_, usages);
596 case blink::WebCryptoKeyFormatJwk:
597 // The JWK could represent either a public key or private key. The usages
598 // must make sense for one of the two. The usages will be checked again by
599 // ImportKeyJwk() once the key type has been determined.
600 if (CheckKeyCreationUsages(all_private_key_usages_, usages).IsSuccess() ||
601 CheckKeyCreationUsages(all_public_key_usages_, usages).IsSuccess()) {
602 return Status::Success();
603 }
604 return Status::ErrorCreateKeyBadUsages();
605 default:
606 return Status::ErrorUnsupportedImportKeyFormat();
607 }
608 } 593 }
609 594
610 Status RsaHashedAlgorithm::ImportKeyPkcs8( 595 Status RsaHashedAlgorithm::ImportKeyPkcs8(
611 const CryptoData& key_data, 596 const CryptoData& key_data,
612 const blink::WebCryptoAlgorithm& algorithm, 597 const blink::WebCryptoAlgorithm& algorithm,
613 bool extractable, 598 bool extractable,
614 blink::WebCryptoKeyUsageMask usages, 599 blink::WebCryptoKeyUsageMask usages,
615 blink::WebCryptoKey* key) const { 600 blink::WebCryptoKey* key) const {
616 Status status = NssSupportsRsaPrivateKeyImport(); 601 Status status = NssSupportsRsaPrivateKeyImport();
617 if (status.IsError()) 602 if (status.IsError())
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 key->algorithm().rsaHashedParams()->publicExponent().size())) { 863 key->algorithm().rsaHashedParams()->publicExponent().size())) {
879 return Status::ErrorUnexpected(); 864 return Status::ErrorUnexpected();
880 } 865 }
881 866
882 return Status::Success(); 867 return Status::Success();
883 } 868 }
884 869
885 } // namespace webcrypto 870 } // namespace webcrypto
886 871
887 } // namespace content 872 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/webcrypto/openssl/ec_key_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698