RMS SDK for C++  0.2.1
A client library for using Microsoft RMS from Linux.
IStream.h
1 /*
2  * ======================================================================
3  * Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
4  * Licensed under the MIT License.
5  * See LICENSE.md in the project root for license information.
6  * ======================================================================
7  */
8 
9 #ifndef _RMS_CRYPTO_ISTREAM_H_
10 #define _RMS_CRYPTO_ISTREAM_H_
11 
12 #include <future>
13 #include <string>
14 #include <memory>
15 #include <vector>
16 #include "CryptoAPIExport.h"
17 
18 namespace rmscrypto {
19 namespace api {
20 class IStream;
21 typedef std::shared_ptr<IStream> SharedStream;
22 
34 class IStream {
35 public:
36 
37  // Async methods. Be sure buffer exists until result will be got from
38  // std::future
39  virtual std::shared_future<int64_t> ReadAsync(uint8_t *pbBuffer,
40  int64_t cbBuffer,
41  int64_t cbOffset,
42  std::launch launchType)
43  = 0;
44  virtual std::shared_future<int64_t> WriteAsync(const uint8_t *cpbBuffer,
45  int64_t cbBuffer,
46  int64_t cbOffset,
47  std::launch launchType)
48  = 0;
49  virtual std::future<bool> FlushAsync(std::launch launchType) = 0;
50 
51  // Sync methods
52  virtual int64_t Read(uint8_t *pbBuffer,
53  int64_t cbBuffer) = 0;
54  virtual int64_t Write(const uint8_t *cpbBuffer,
55  int64_t cbBuffer) = 0;
56  virtual bool Flush() = 0;
57 
58  virtual SharedStream Clone() = 0;
59 
60  virtual void Seek(uint64_t u64Position) = 0;
61  virtual bool CanRead() const = 0;
62  virtual bool CanWrite() const = 0;
63  virtual uint64_t Position() = 0;
64  virtual uint64_t Size() = 0;
65  virtual void Size(uint64_t u64Value) = 0;
66 
67  virtual std::vector<uint8_t> Read(uint64_t u64size)
68  {
69  std::vector<uint8_t> plainText;
70 
71  if (u64size > 0)
72  {
73  plainText.resize(u64size);
74  int actualSize =
75  static_cast<int>(Read(&plainText[0], static_cast<int>(plainText.size())));
76  plainText.resize(actualSize);
77  }
78  return plainText;
79  }
80 
81 protected:
82 
83  virtual ~IStream() {}
84 }; // class IStream
85 } // namespace api
86 } // namespace rmscrypto
87 #endif // _RMS_CRYPTO_ISTREAM_H_
Definition: BlockBasedProtectedStream.cpp:13
Base interface for protected streams.
Definition: IStream.h:34