RMS SDK for C++  0.2.1
A client library for using Microsoft RMS from Linux.
SimpleProtectedStream.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 _CRYPTO_STREAMS_LIB_SIMPLEPROTECTEDSTREAM_H_
10 #define _CRYPTO_STREAMS_LIB_SIMPLEPROTECTEDSTREAM_H_
11 
12 #include "IStream.h"
13 #include "ICryptoProvider.h"
14 
15 namespace rmscrypto {
16 namespace api {
18  public std::enable_shared_from_this
19  <SimpleProtectedStream>{
20  friend class CachedBlock;
21 
22 public:
23 
24  SimpleProtectedStream(std::shared_ptr<ICryptoProvider>pCryptoProvider,
25  std::shared_ptr<IStream> pBackingStream,
26  uint64_t u64ContentStart,
27  uint64_t u64ContentSize);
28 
29  // IStream implementation
30  virtual std::shared_future<int64_t>ReadAsync(uint8_t *pbBuffer,
31  int64_t cbBuffer,
32  int64_t cbOffset,
33  std::launch launchType)
34  override;
35  virtual std::shared_future<int64_t>WriteAsync(const uint8_t *cpbBuffer,
36  int64_t cbBuffer,
37  int64_t cbOffset,
38  std::launch launchType)
39  override;
40  virtual std::future<bool>FlushAsync(std::launch launchType)
41  override;
42 
43  virtual int64_t Read(uint8_t *pbBuffer,
44  int64_t cbBuffer) override;
45  virtual int64_t Write(const uint8_t *cpbBuffer,
46  int64_t cbBuffer) override;
47  virtual bool Flush() override;
48 
49  virtual SharedStream Clone() override;
50 
51  virtual void Seek(uint64_t u64Position) override;
52  virtual bool CanRead() const override;
53  virtual bool CanWrite() const override;
54  virtual uint64_t Position() override;
55  virtual uint64_t Size() override;
56  virtual void Size(uint64_t u64Value) override;
57 
58  virtual ~SimpleProtectedStream() override;
59 
60  std::shared_future<int64_t>ReadInternalAsync(uint8_t *pbBuffer,
61  int64_t cbBuffer,
62  int64_t cbOffset,
63  std::launch launchType,
64  uint32_t u32StartingBlockNumber,
65  bool bIsFinal);
66  std::shared_future<int64_t>WriteInternalAsync(const uint8_t *cpbBuffer,
67  int64_t cbBuffer,
68  int64_t cbOffset,
69  std::launch launchType,
70  uint32_t u32StartingBlockNumber,
71  bool bIsFinal);
72 
73 private:
74 
75  uint64_t SizeInternal();
76  void SeekInternal(uint64_t u64Position);
77 
79  SimpleProtectedStream& operator=(const SimpleProtectedStream&) = delete;
80 
81 private:
82 
83  void AppendZeros(uint64_t u64Count);
84 
85 private:
86 
87  std::shared_ptr<std::mutex> m_locker;
88 
89  std::shared_ptr<ICryptoProvider> m_pCryptoProvider;
90  std::shared_ptr<IStream> m_pBackingStream;
91 
92  uint64_t m_u64ContentStart;
93  uint64_t m_u64ContentSize;
94  bool m_bIsPlainText;
95 };
96 } // namespace api
97 } // namespace rmscrypto
98 #endif // _CRYPTO_STREAMS_LIB_SIMPLEPROTECTEDSTREAM_H_
Definition: BlockBasedProtectedStream.cpp:13
Base interface for protected streams.
Definition: IStream.h:34
Definition: SimpleProtectedStream.h:17
Definition: CachedBlock.h:19