blob: fd05451fd677655382ee25030ea3e981b6e6b637 [file] [log] [blame]
Bartosz Przydatek51812462017-06-13 18:03:45 +02001// 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>
kste16006b32022-07-26 05:50:39 -070021#include <memory>
Bartosz Przydatek51812462017-06-13 18:03:45 +020022#include <sstream>
kste16006b32022-07-26 05:50:39 -070023#include <string>
Bartosz Przydatek51812462017-06-13 18:03:45 +020024
kste16006b32022-07-26 05:50:39 -070025#include "absl/container/flat_hash_map.h"
Bartosz Przydatek3cd62692018-03-16 12:45:04 -070026#include "tink/keyset_handle.h"
27#include "tink/keyset_reader.h"
28#include "tink/util/statusor.h"
Bartosz Przydatekecabde72017-06-20 12:02:21 +020029#include "proto/tink.pb.h"
Bartosz Przydatek51812462017-06-13 18:03:45 +020030
31namespace crypto {
32namespace tink {
33
34// Creates keyset handles from cleartext keysets. This API allows
35// loading cleartext keysets, thus its usage should be restricted.
36class CleartextKeysetHandle {
37 public:
kste16006b32022-07-26 05:50:39 -070038 // 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 Przydatek9fb56132017-10-03 19:29:41 +020041 static crypto::tink::util::StatusOr<std::unique_ptr<KeysetHandle>> Read(
kste16006b32022-07-26 05:50:39 -070042 std::unique_ptr<KeysetReader> reader,
43 const absl::flat_hash_map<std::string, std::string>&
44 monitoring_annotations = {});
Bartosz Przydatek9fb56132017-10-03 19:29:41 +020045
cinlin40b3c022022-05-11 09:01:21 -070046 // Writes the keyset in the given `keyset_handle` to the `writer` which must
candrian91fb7082019-03-19 14:15:30 -070047 // be non-null.
48 static crypto::tink::util::Status Write(KeysetWriter* writer,
49 const KeysetHandle& keyset_handle);
50
thaidn450a82a2019-03-15 14:50:14 -070051 // Creates a KeysetHandle object for the given 'keyset'.
52 static std::unique_ptr<KeysetHandle> GetKeysetHandle(
53 const google::crypto::tink::Keyset& keyset);
54
Bartosz Przydatek8fa13a62018-05-24 05:27:36 -070055 // Returns a Keyset-proto from the given 'keyset_handle'.
56 static const google::crypto::tink::Keyset& GetKeyset(
57 const KeysetHandle& keyset_handle);
58
Bartosz Przydatek51812462017-06-13 18:03:45 +020059 private:
Thai Duong92d5a7d2017-06-22 16:11:23 -070060 CleartextKeysetHandle() {}
Bartosz Przydatek51812462017-06-13 18:03:45 +020061};
62
63} // namespace tink
64} // namespace crypto
65
66#endif // TINK_CLEARTEXT_KEYSET_HANDLE_H_