1 // Copyright 2019 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_UTIL_FILE_RANDOM_ACCESS_STREAM_H_ 18 #define TINK_UTIL_FILE_RANDOM_ACCESS_STREAM_H_ 19 20 #include <memory> 21 22 #include "tink/random_access_stream.h" 23 #include "tink/util/buffer.h" 24 #include "tink/util/status.h" 25 #include "tink/util/statusor.h" 26 27 namespace crypto { 28 namespace tink { 29 namespace util { 30 31 // An RandomAccessStream that reads from a file descriptor. 32 // 33 // NOTE: This class in not available when building on Windows. 34 class FileRandomAccessStream : public crypto::tink::RandomAccessStream { 35 public: 36 // Constructs a FileRandomAccessStream that will read from the file specified 37 // via 'file_descriptor'. 38 // Takes the ownership of the file, and will close it upon destruction. 39 explicit FileRandomAccessStream(int file_descriptor); 40 41 ~FileRandomAccessStream() override; 42 43 crypto::tink::util::Status PRead(int64_t position, 44 int count, 45 Buffer* dest_buffer) override; 46 47 crypto::tink::util::StatusOr<int64_t> size() override; 48 49 private: 50 int fd_; 51 }; 52 53 } // namespace util 54 } // namespace tink 55 } // namespace crypto 56 57 #endif // TINK_UTIL_FILE_RANDOM_ACCESS_STREAM_H_ 58