OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |