1 // Copyright 2018 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_WRITER_H_ 18 #define TINK_BINARY_KEYSET_WRITER_H_ 19 20 #include <memory> 21 #include <ostream> 22 #include <utility> 23 24 #include "absl/strings/string_view.h" 25 #include "tink/keyset_writer.h" 26 #include "tink/util/status.h" 27 #include "tink/util/statusor.h" 28 #include "proto/tink.pb.h" 29 30 namespace crypto { 31 namespace tink { 32 33 // A KeysetWriter that can write to some destination cleartext 34 // or encrypted keysets in proto binary wire format, cf. 35 // https://developers.google.com/protocol-buffers/docs/encoding 36 class BinaryKeysetWriter : public KeysetWriter { 37 public: 38 static crypto::tink::util::StatusOr<std::unique_ptr<BinaryKeysetWriter>> New( 39 std::unique_ptr<std::ostream> destination_stream); 40 41 crypto::tink::util::Status 42 Write(const google::crypto::tink::Keyset& keyset) override; 43 44 crypto::tink::util::Status 45 Write(const google::crypto::tink::EncryptedKeyset& encrypted_keyset) override; 46 47 private: BinaryKeysetWriter(std::unique_ptr<std::ostream> destination_stream)48 explicit BinaryKeysetWriter(std::unique_ptr<std::ostream> destination_stream) 49 : destination_stream_(std::move(destination_stream)) {} 50 51 std::unique_ptr<std::ostream> destination_stream_; 52 }; 53 54 } // namespace tink 55 } // namespace crypto 56 57 #endif // TINK_BINARY_KEYSET_WRITER_H_ 58