Bartosz Przydatek | 5181246 | 2017-06-13 18:03:45 +0200 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | // |
| 15 | /////////////////////////////////////////////////////////////////////////////// |
| 16 | |
| 17 | #ifndef TINK_CLEARTEXT_KEYSET_HANDLE_H_ |
| 18 | #define TINK_CLEARTEXT_KEYSET_HANDLE_H_ |
| 19 | |
| 20 | #include <istream> |
kste | 16006b3 | 2022-07-26 05:50:39 -0700 | [diff] [blame] | 21 | #include <memory> |
Bartosz Przydatek | 5181246 | 2017-06-13 18:03:45 +0200 | [diff] [blame] | 22 | #include <sstream> |
kste | 16006b3 | 2022-07-26 05:50:39 -0700 | [diff] [blame] | 23 | #include <string> |
Bartosz Przydatek | 5181246 | 2017-06-13 18:03:45 +0200 | [diff] [blame] | 24 | |
kste | 16006b3 | 2022-07-26 05:50:39 -0700 | [diff] [blame] | 25 | #include "absl/container/flat_hash_map.h" |
Bartosz Przydatek | 3cd6269 | 2018-03-16 12:45:04 -0700 | [diff] [blame] | 26 | #include "tink/keyset_handle.h" |
| 27 | #include "tink/keyset_reader.h" |
| 28 | #include "tink/util/statusor.h" |
Bartosz Przydatek | ecabde7 | 2017-06-20 12:02:21 +0200 | [diff] [blame] | 29 | #include "proto/tink.pb.h" |
Bartosz Przydatek | 5181246 | 2017-06-13 18:03:45 +0200 | [diff] [blame] | 30 | |
| 31 | namespace crypto { |
| 32 | namespace tink { |
| 33 | |
| 34 | // Creates keyset handles from cleartext keysets. This API allows |
| 35 | // loading cleartext keysets, thus its usage should be restricted. |
| 36 | class CleartextKeysetHandle { |
| 37 | public: |
kste | 16006b3 | 2022-07-26 05:50:39 -0700 | [diff] [blame] | 38 | // Creates a KeysetHandle with a keyset obtained via `reader`. Optionally |
| 39 | // allows to pass monitoring_annotations to attach additional data to the |
| 40 | // resulting KeysetHandle, which will be used for monitoring. |
Bartosz Przydatek | 9fb5613 | 2017-10-03 19:29:41 +0200 | [diff] [blame] | 41 | static crypto::tink::util::StatusOr<std::unique_ptr<KeysetHandle>> Read( |
kste | 16006b3 | 2022-07-26 05:50:39 -0700 | [diff] [blame] | 42 | std::unique_ptr<KeysetReader> reader, |
| 43 | const absl::flat_hash_map<std::string, std::string>& |
| 44 | monitoring_annotations = {}); |
Bartosz Przydatek | 9fb5613 | 2017-10-03 19:29:41 +0200 | [diff] [blame] | 45 | |
cinlin | 40b3c02 | 2022-05-11 09:01:21 -0700 | [diff] [blame] | 46 | // Writes the keyset in the given `keyset_handle` to the `writer` which must |
candrian | 91fb708 | 2019-03-19 14:15:30 -0700 | [diff] [blame] | 47 | // be non-null. |
| 48 | static crypto::tink::util::Status Write(KeysetWriter* writer, |
| 49 | const KeysetHandle& keyset_handle); |
| 50 | |
thaidn | 450a82a | 2019-03-15 14:50:14 -0700 | [diff] [blame] | 51 | // Creates a KeysetHandle object for the given 'keyset'. |
| 52 | static std::unique_ptr<KeysetHandle> GetKeysetHandle( |
| 53 | const google::crypto::tink::Keyset& keyset); |
| 54 | |
Bartosz Przydatek | 8fa13a6 | 2018-05-24 05:27:36 -0700 | [diff] [blame] | 55 | // Returns a Keyset-proto from the given 'keyset_handle'. |
| 56 | static const google::crypto::tink::Keyset& GetKeyset( |
| 57 | const KeysetHandle& keyset_handle); |
| 58 | |
Bartosz Przydatek | 5181246 | 2017-06-13 18:03:45 +0200 | [diff] [blame] | 59 | private: |
Thai Duong | 92d5a7d | 2017-06-22 16:11:23 -0700 | [diff] [blame] | 60 | CleartextKeysetHandle() {} |
Bartosz Przydatek | 5181246 | 2017-06-13 18:03:45 +0200 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } // namespace tink |
| 64 | } // namespace crypto |
| 65 | |
| 66 | #endif // TINK_CLEARTEXT_KEYSET_HANDLE_H_ |