| 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_SECRET_KEY_UTIL_ | 5 #ifndef COMPONENTS_WEBCRYPTO_ALGORITHMS_SECRET_KEY_UTIL_ |
| 6 #define COMPONENTS_WEBCRYPTO_ALGORITHMS_SECRET_KEY_UTIL_ | 6 #define COMPONENTS_WEBCRYPTO_ALGORITHMS_SECRET_KEY_UTIL_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 // Creates a WebCrypto secret key given the raw data. The provided |key_data| | 35 // Creates a WebCrypto secret key given the raw data. The provided |key_data| |
| 36 // will be copied into the new key. This function does not do any validation | 36 // will be copied into the new key. This function does not do any validation |
| 37 // checks for the provided parameters. | 37 // checks for the provided parameters. |
| 38 Status CreateWebCryptoSecretKey(const CryptoData& key_data, | 38 Status CreateWebCryptoSecretKey(const CryptoData& key_data, |
| 39 const blink::WebCryptoKeyAlgorithm& algorithm, | 39 const blink::WebCryptoKeyAlgorithm& algorithm, |
| 40 bool extractable, | 40 bool extractable, |
| 41 blink::WebCryptoKeyUsageMask usages, | 41 blink::WebCryptoKeyUsageMask usages, |
| 42 blink::WebCryptoKey* key); | 42 blink::WebCryptoKey* key); |
| 43 | 43 |
| 44 // Checks that |actual_usages| is a non-empty subset of |all_possible_usages|. | |
| 45 Status CheckSecretKeyCreationUsages( | |
| 46 blink::WebCryptoKeyUsageMask all_possible_usages, | |
| 47 blink::WebCryptoKeyUsageMask actual_usages); | |
| 48 | |
| 49 // Writes a JWK-formatted symmetric key to |jwk_key_data|. | 44 // Writes a JWK-formatted symmetric key to |jwk_key_data|. |
| 50 // * raw_key_data: The actual key data | 45 // * raw_key_data: The actual key data |
| 51 // * algorithm: The JWK algorithm name (i.e. "alg") | 46 // * algorithm: The JWK algorithm name (i.e. "alg") |
| 52 // * extractable: The JWK extractability (i.e. "ext") | 47 // * extractable: The JWK extractability (i.e. "ext") |
| 53 // * usages: The JWK usages (i.e. "key_ops") | 48 // * usages: The JWK usages (i.e. "key_ops") |
| 54 void WriteSecretKeyJwk(const CryptoData& raw_key_data, | 49 void WriteSecretKeyJwk(const CryptoData& raw_key_data, |
| 55 const std::string& algorithm, | 50 const std::string& algorithm, |
| 56 bool extractable, | 51 bool extractable, |
| 57 blink::WebCryptoKeyUsageMask usages, | 52 blink::WebCryptoKeyUsageMask usages, |
| 58 std::vector<uint8_t>* jwk_key_data); | 53 std::vector<uint8_t>* jwk_key_data); |
| 59 | 54 |
| 60 // Parses a UTF-8 encoded JWK (key_data), and extracts the key material to | 55 // Parses a UTF-8 encoded JWK (key_data), and extracts the key material to |
| 61 // |*raw_key_data|. Returns Status::Success() on success, otherwise an error. | 56 // |*raw_key_data|. Returns Status::Success() on success, otherwise an error. |
| 62 // In order for this to succeed: | 57 // In order for this to succeed: |
| 63 // * expected_extractable must be consistent with the JWK's "ext", if | 58 // * expected_extractable must be consistent with the JWK's "ext", if |
| 64 // present. | 59 // present. |
| 65 // * expected_usages must be a subset of the JWK's "key_ops" if present. | 60 // * expected_usages must be a subset of the JWK's "key_ops" if present. |
| 66 Status ReadSecretKeyNoExpectedAlgJwk( | 61 Status ReadSecretKeyNoExpectedAlgJwk( |
| 67 const CryptoData& key_data, | 62 const CryptoData& key_data, |
| 68 bool expected_extractable, | 63 bool expected_extractable, |
| 69 blink::WebCryptoKeyUsageMask expected_usages, | 64 blink::WebCryptoKeyUsageMask expected_usages, |
| 70 std::vector<uint8_t>* raw_key_data, | 65 std::vector<uint8_t>* raw_key_data, |
| 71 JwkReader* jwk); | 66 JwkReader* jwk); |
| 72 | 67 |
| 73 } // namespace webcrypto | 68 } // namespace webcrypto |
| 74 | 69 |
| 75 #endif // COMPONENTS_WEBCRYPTO_ALGORITHMS_SECRET_KEY_UTIL_ | 70 #endif // COMPONENTS_WEBCRYPTO_ALGORITHMS_SECRET_KEY_UTIL_ |
| OLD | NEW |