RMS SDK for C++  0.2.1
A client library for using Microsoft RMS from Linux.
CachedBlock.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_CACHEDBLOCK_H_
10 #define _CRYPTO_STREAMS_LIB_CACHEDBLOCK_H_
11 
12 #include <memory>
13 #include <vector>
14 
15 namespace rmscrypto {
16 namespace api {
17 class SimpleProtectedStream;
18 
19 class CachedBlock {
20 public:
21 
22  CachedBlock(std::shared_ptr<SimpleProtectedStream>pSimple,
23  uint64_t u64BlockSize);
24 
25  uint64_t GetBlockSize();
26 
27  void UpdateBlock(uint64_t u64Position);
28 
29  uint64_t ReadFromBlock(uint8_t *pbBuffer,
30  uint64_t u64Position,
31  uint64_t u64Size);
32 
33  uint64_t WriteToBlock(const uint8_t *pbBuffer,
34  uint64_t u64Position,
35  uint64_t u64Size);
36 
37  void RewriteFinalBlock(uint64_t newSize);
38  bool Flush();
39  uint64_t GetSizeInternal() const;
40  void SizeInternal(uint64_t u64Size);
41 
42 private:
43 
44  uint32_t CalculateBlockNumber(uint64_t u64Position) const;
45 
46 private:
47 
48  std::shared_ptr<SimpleProtectedStream> m_pSimple;
49  uint64_t m_u64BlockSize;
50 
51  uint64_t m_u64CacheStart;
52  uint64_t m_u64CacheSize;
53  std::vector<uint8_t> m_cache;
54  bool m_bFinalBlockHasBeenWritten;
55  bool m_bWritePending;
56 };
57 } // namespace api
58 } // namespace rmscrypto
59 #endif // ifndef _CRYPTO_STREAMS_LIB_CACHEDBLOCK_H_
Definition: BlockBasedProtectedStream.cpp:13
Definition: CachedBlock.h:19