xref: /aosp_15_r20/external/tink/cc/binary_keyset_reader.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
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_BINARY_KEYSET_READER_H_
18 #define TINK_BINARY_KEYSET_READER_H_
19 
20 #include <istream>
21 #include <memory>
22 #include <string>
23 
24 #include "absl/strings/string_view.h"
25 #include "tink/keyset_reader.h"
26 #include "tink/util/statusor.h"
27 #include "proto/tink.pb.h"
28 
29 namespace crypto {
30 namespace tink {
31 
32 // A KeysetReader that can read from some source cleartext or
33 // encrypted keysets in proto binary wire format, cf.
34 // https://developers.google.com/protocol-buffers/docs/encoding
35 class BinaryKeysetReader : public KeysetReader {
36  public:
37   static crypto::tink::util::StatusOr<std::unique_ptr<KeysetReader>> New(
38       std::unique_ptr<std::istream> keyset_stream);
39   static crypto::tink::util::StatusOr<std::unique_ptr<KeysetReader>> New(
40       absl::string_view serialized_keyset);
41 
42   crypto::tink::util::StatusOr<std::unique_ptr<google::crypto::tink::Keyset>>
43   Read() override;
44 
45   crypto::tink::util::StatusOr<
46     std::unique_ptr<google::crypto::tink::EncryptedKeyset>>
47   ReadEncrypted() override;
48 
49  private:
BinaryKeysetReader(absl::string_view serialized_keyset)50   explicit BinaryKeysetReader(absl::string_view serialized_keyset)
51       : serialized_keyset_(serialized_keyset) {}
52 
53   std::string serialized_keyset_;
54 };
55 
56 }  // namespace tink
57 }  // namespace crypto
58 
59 #endif  // TINK_BINARY_KEYSET_READER_H_
60