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

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

Issue 377723002: Fixes for re-enabling more MSVC level 4 warnings: content/ edition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « content/child/webcrypto/jwk.cc ('k') | content/common/child_process_host_impl.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/shared_crypto.h" 5 #include "content/child/webcrypto/shared_crypto.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/child/webcrypto/crypto_data.h" 8 #include "content/child/webcrypto/crypto_data.h"
9 #include "content/child/webcrypto/jwk.h" 9 #include "content/child/webcrypto/jwk.h"
10 #include "content/child/webcrypto/platform_crypto.h" 10 #include "content/child/webcrypto/platform_crypto.h"
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 // Returns Status::Success() if |usages| is a valid set of key usages for 477 // Returns Status::Success() if |usages| is a valid set of key usages for
478 // |algorithm| and |key_type|. Otherwise returns an error. 478 // |algorithm| and |key_type|. Otherwise returns an error.
479 // In the case of JWK format the check is incomplete for asymmetric algorithms. 479 // In the case of JWK format the check is incomplete for asymmetric algorithms.
480 Status BestEffortCheckKeyUsagesForImport(blink::WebCryptoAlgorithmId algorithm, 480 Status BestEffortCheckKeyUsagesForImport(blink::WebCryptoAlgorithmId algorithm,
481 blink::WebCryptoKeyFormat format, 481 blink::WebCryptoKeyFormat format,
482 blink::WebCryptoKeyUsageMask usages) { 482 blink::WebCryptoKeyUsageMask usages) {
483 if (!IsAlgorithmAsymmetric(algorithm)) 483 if (!IsAlgorithmAsymmetric(algorithm))
484 return CheckKeyUsages(algorithm, blink::WebCryptoKeyTypeSecret, usages); 484 return CheckKeyUsages(algorithm, blink::WebCryptoKeyTypeSecret, usages);
485 485
486 // Try to infer the key type given the import format. 486 // Try to infer the key type given the import format.
487 blink::WebCryptoKeyType key_type;
488 bool key_type_known = false;
489
490 switch (format) { 487 switch (format) {
491 case blink::WebCryptoKeyFormatRaw: 488 case blink::WebCryptoKeyFormatRaw:
492 // TODO(eroman): The spec defines Diffie-Hellman raw import for public 489 // TODO(eroman): The spec defines Diffie-Hellman raw import for public
493 // keys, so this will need to be updated in the future when DH is 490 // keys, so this will need to be updated in the future when DH is
494 // implemented. 491 // implemented.
495 return Status::ErrorUnexpected(); 492 return Status::ErrorUnexpected();
496 case blink::WebCryptoKeyFormatSpki: 493 case blink::WebCryptoKeyFormatSpki:
497 key_type = blink::WebCryptoKeyTypePublic; 494 return CheckKeyUsages(algorithm, blink::WebCryptoKeyTypePublic, usages);
498 key_type_known = true;
499 break;
500 case blink::WebCryptoKeyFormatPkcs8: 495 case blink::WebCryptoKeyFormatPkcs8:
501 key_type = blink::WebCryptoKeyTypePrivate; 496 return CheckKeyUsages(algorithm, blink::WebCryptoKeyTypePrivate, usages);
502 key_type_known = true;
503 break;
504 case blink::WebCryptoKeyFormatJwk: 497 case blink::WebCryptoKeyFormatJwk:
505 key_type_known = false;
506 break; 498 break;
507 default: 499 default:
508 return Status::ErrorUnexpected(); 500 return Status::ErrorUnexpected();
509 } 501 }
510 502
511 if (key_type_known)
512 return CheckKeyUsages(algorithm, key_type, usages);
513
514 // If the key type is not known, then the algorithm is asymmetric. Whether the 503 // If the key type is not known, then the algorithm is asymmetric. Whether the
515 // key data describes a public or private key isn't known yet. But it must at 504 // key data describes a public or private key isn't known yet. But it must at
516 // least be ONE of those two. 505 // least be ONE of those two.
517 DCHECK(IsAlgorithmAsymmetric(algorithm)); 506 DCHECK(IsAlgorithmAsymmetric(algorithm));
518 507
519 if (CheckKeyUsages(algorithm, blink::WebCryptoKeyTypePublic, usages) 508 if (CheckKeyUsages(algorithm, blink::WebCryptoKeyTypePublic, usages)
520 .IsError() && 509 .IsError() &&
521 CheckKeyUsages(algorithm, blink::WebCryptoKeyTypePrivate, usages) 510 CheckKeyUsages(algorithm, blink::WebCryptoKeyTypePrivate, usages)
522 .IsError()) { 511 .IsError()) {
523 return Status::ErrorCreateKeyBadUsages(); 512 return Status::ErrorCreateKeyBadUsages();
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 if (!ContainsKeyUsages(GetValidKeyUsagesForKeyType(algorithm, key_type), 935 if (!ContainsKeyUsages(GetValidKeyUsagesForKeyType(algorithm, key_type),
947 usages)) 936 usages))
948 return Status::ErrorCreateKeyBadUsages(); 937 return Status::ErrorCreateKeyBadUsages();
949 938
950 return Status::Success(); 939 return Status::Success();
951 } 940 }
952 941
953 } // namespace webcrypto 942 } // namespace webcrypto
954 943
955 } // namespace content 944 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/jwk.cc ('k') | content/common/child_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698