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

Side by Side Diff: components/webcrypto/webcrypto_util.cc

Issue 1181413009: move KeyUsageAllows to more logical place(part2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove AUTHORS change because name is already there Created 5 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
« no previous file with comments | « components/webcrypto/webcrypto_util.h ('k') | no next file » | 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 "components/webcrypto/webcrypto_util.h" 5 #include "components/webcrypto/webcrypto_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/numerics/safe_math.h" 8 #include "base/numerics/safe_math.h"
9 #include "components/webcrypto/status.h" 9 #include "components/webcrypto/status.h"
10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" 10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 blink::WebCryptoNamedCurve named_curve) { 88 blink::WebCryptoNamedCurve named_curve) {
89 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( 89 return blink::WebCryptoAlgorithm::adoptParamsAndCreate(
90 id, new blink::WebCryptoEcKeyImportParams(named_curve)); 90 id, new blink::WebCryptoEcKeyImportParams(named_curve));
91 } 91 }
92 92
93 bool ContainsKeyUsages(blink::WebCryptoKeyUsageMask a, 93 bool ContainsKeyUsages(blink::WebCryptoKeyUsageMask a,
94 blink::WebCryptoKeyUsageMask b) { 94 blink::WebCryptoKeyUsageMask b) {
95 return (a & b) == b; 95 return (a & b) == b;
96 } 96 }
97 97
98 // TODO(eroman): Move this helper to WebCryptoKey.
99 bool KeyUsageAllows(const blink::WebCryptoKey& key,
100 const blink::WebCryptoKeyUsage usage) {
101 return ((key.usages() & usage) != 0);
102 }
103
104 // The WebCrypto spec defines the default value for the tag length, as well as 98 // The WebCrypto spec defines the default value for the tag length, as well as
105 // the allowed values for tag length. 99 // the allowed values for tag length.
106 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params, 100 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params,
107 unsigned int* tag_length_bits) { 101 unsigned int* tag_length_bits) {
108 *tag_length_bits = 128; 102 *tag_length_bits = 128;
109 if (params->hasTagLengthBits()) 103 if (params->hasTagLengthBits())
110 *tag_length_bits = params->optionalTagLengthBits(); 104 *tag_length_bits = params->optionalTagLengthBits();
111 105
112 if (*tag_length_bits != 32 && *tag_length_bits != 64 && 106 if (*tag_length_bits != 32 && *tag_length_bits != 64 &&
113 *tag_length_bits != 96 && *tag_length_bits != 104 && 107 *tag_length_bits != 96 && *tag_length_bits != 104 &&
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 *public_usages = combined_usages & all_public_usages; 313 *public_usages = combined_usages & all_public_usages;
320 *private_usages = combined_usages & all_private_usages; 314 *private_usages = combined_usages & all_private_usages;
321 315
322 if (*private_usages == 0) 316 if (*private_usages == 0)
323 return Status::ErrorCreateKeyEmptyUsages(); 317 return Status::ErrorCreateKeyEmptyUsages();
324 318
325 return Status::Success(); 319 return Status::Success();
326 } 320 }
327 321
328 } // namespace webcrypto 322 } // namespace webcrypto
OLDNEW
« no previous file with comments | « components/webcrypto/webcrypto_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698