1 // Copyright 2019 Google LLC 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_STREAMINGAEAD_SHARED_INPUT_STREAM_H_ 18 #define TINK_STREAMINGAEAD_SHARED_INPUT_STREAM_H_ 19 20 #include "tink/input_stream.h" 21 #include "tink/util/statusor.h" 22 23 namespace crypto { 24 namespace tink { 25 namespace streamingaead { 26 27 // An InputStream that wraps another InputStream as a non-owned pointer. 28 // The wrapper forwards all calls to the wrapped InputStream, 29 // which must remain alive as long as as the wrapper is in use. 30 class SharedInputStream : public crypto::tink::InputStream { 31 public: 32 // Constructs an InputStream that wraps 'input_stream', 33 // and will forward all the method calls to this wrapped stream. SharedInputStream(crypto::tink::InputStream * input_stream)34 explicit SharedInputStream( 35 crypto::tink::InputStream* input_stream) 36 : input_stream_(input_stream) {} 37 38 ~SharedInputStream() override = default; 39 Next(const void ** data)40 crypto::tink::util::StatusOr<int> Next(const void** data) override { 41 return input_stream_->Next(data); 42 } 43 BackUp(int count)44 void BackUp(int count) override { 45 input_stream_->BackUp(count); 46 } 47 Position()48 int64_t Position() const override { 49 return input_stream_->Position(); 50 } 51 52 private: 53 crypto::tink::InputStream* input_stream_; 54 }; 55 56 } // namespace streamingaead 57 } // namespace tink 58 } // namespace crypto 59 60 #endif // TINK_STREAMINGAEAD_SHARED_INPUT_STREAM_H_ 61