| 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 #ifndef COMPONENTS_WEBCRYPTO_ALGORITHMS_UTIL_H_ | 5 #ifndef COMPONENTS_WEBCRYPTO_ALGORITHMS_UTIL_H_ |
| 6 #define COMPONENTS_WEBCRYPTO_ALGORITHMS_UTIL_H_ | 6 #define COMPONENTS_WEBCRYPTO_ALGORITHMS_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 // Rounds a bit count (up) to the nearest byte count. | 46 // Rounds a bit count (up) to the nearest byte count. |
| 47 // | 47 // |
| 48 // This is mathematically equivalent to (x + 7) / 8, however has no | 48 // This is mathematically equivalent to (x + 7) / 8, however has no |
| 49 // possibility of integer overflow. | 49 // possibility of integer overflow. |
| 50 template <typename T> | 50 template <typename T> |
| 51 T NumBitsToBytes(T x) { | 51 T NumBitsToBytes(T x) { |
| 52 return (x / 8) + (7 + (x % 8)) / 8; | 52 return (x / 8) + (7 + (x % 8)) / 8; |
| 53 } | 53 } |
| 54 | 54 |
| 55 enum class EmptyUsagePolicy { | |
| 56 // Allow keys to have empty usages. | |
| 57 ALLOW_EMPTY, | |
| 58 | |
| 59 // Do not allow keys to have empty usages. | |
| 60 REJECT_EMPTY, | |
| 61 }; | |
| 62 | |
| 63 // Verifies whether a key can be created using |actual_usages| when the | 55 // Verifies whether a key can be created using |actual_usages| when the |
| 64 // algorithm supports |all_possible_usages|. | 56 // algorithm supports |all_possible_usages|. |
| 65 Status CheckKeyCreationUsages(blink::WebCryptoKeyUsageMask all_possible_usages, | 57 Status CheckKeyCreationUsages(blink::WebCryptoKeyUsageMask all_possible_usages, |
| 66 blink::WebCryptoKeyUsageMask actual_usages, | 58 blink::WebCryptoKeyUsageMask actual_usages); |
| 67 EmptyUsagePolicy empty_usage_policy); | |
| 68 | 59 |
| 69 // TODO(eroman): This doesn't really belong in this file. Move it into Blink | 60 // TODO(eroman): This doesn't really belong in this file. Move it into Blink |
| 70 // instead. | 61 // instead. |
| 71 // | 62 // |
| 72 // Returns true if the set bits in b make up a subset of the set bits in a. | 63 // Returns true if the set bits in b make up a subset of the set bits in a. |
| 73 bool ContainsKeyUsages(blink::WebCryptoKeyUsageMask a, | 64 bool ContainsKeyUsages(blink::WebCryptoKeyUsageMask a, |
| 74 blink::WebCryptoKeyUsageMask b); | 65 blink::WebCryptoKeyUsageMask b); |
| 75 | 66 |
| 76 // Allocates a new BIGNUM given a std::string big-endian representation. | 67 // Allocates a new BIGNUM given a std::string big-endian representation. |
| 77 BIGNUM* CreateBIGNUM(const std::string& n); | 68 BIGNUM* CreateBIGNUM(const std::string& n); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 89 const CryptoData& data, | 80 const CryptoData& data, |
| 90 unsigned int tag_length_bytes, | 81 unsigned int tag_length_bytes, |
| 91 const CryptoData& iv, | 82 const CryptoData& iv, |
| 92 const CryptoData& additional_data, | 83 const CryptoData& additional_data, |
| 93 const EVP_AEAD* aead_alg, | 84 const EVP_AEAD* aead_alg, |
| 94 std::vector<uint8_t>* buffer); | 85 std::vector<uint8_t>* buffer); |
| 95 | 86 |
| 96 } // namespace webcrypto | 87 } // namespace webcrypto |
| 97 | 88 |
| 98 #endif // COMPONENTS_WEBCRYPTO_ALGORITHMS_UTIL_H_ | 89 #endif // COMPONENTS_WEBCRYPTO_ALGORITHMS_UTIL_H_ |
| OLD | NEW |