RMS SDK for C++  0.2.1
A client library for using Microsoft RMS from Linux.
ProtectedFileStream.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_LIB_PROTECTEDFILESTREAM_H_
10 #define _RMS_LIB_PROTECTEDFILESTREAM_H_
11 
12 #include <CryptoAPI.h>
13 #include "UserPolicy.h"
14 #include "ModernAPIExport.h"
15 #include "CacheControl.h"
16 
17 namespace rmscore {
18 namespace pfile {
19 class PfileHeader;
20 } // namespace pfile
21 
22 namespace modernapi {
23 class ProtectedFileStream;
24 
29 struct DLL_PUBLIC_RMS GetProtectedFileStreamResult
30 {
31  GetUserPolicyResultStatus m_status;
32  std::shared_ptr<std::string> m_referrer;
33  std::shared_ptr<ProtectedFileStream> m_stream;
34 
35  GetProtectedFileStreamResult(GetUserPolicyResultStatus status,
36  std::shared_ptr<std::string> referrer,
37  std::shared_ptr<ProtectedFileStream> stream);
38 };
39 
47 class DLL_PUBLIC_RMS ProtectedFileStream : public rmscrypto::api::IStream {
48 public:
49 
50  virtual ~ProtectedFileStream();
51 
60  virtual std::shared_future<int64_t> ReadAsync(uint8_t *pbBuffer,
61  int64_t cbBuffer,
62  int64_t cbOffset,
63  std::launch launchType)
64  override;
65 
74  virtual std::shared_future<int64_t> WriteAsync(const uint8_t *cpbBuffer,
75  int64_t cbBuffer,
76  int64_t cbOffset,
77  std::launch launchType)
78  override;
79 
86  virtual std::future<bool> FlushAsync(std::launch launchType) override;
87 
94  virtual int64_t Read(uint8_t *pbBuffer,
95  int64_t cbBuffer)
96  override;
97 
104  virtual int64_t Write(const uint8_t *cpbBuffer,
105  int64_t cbBuffer)
106  override;
107 
114  virtual bool Flush() override;
115 
123  virtual rmscrypto::api::SharedStream Clone() override;
124 
129  virtual void Seek(uint64_t u64Position) override;
130 
135  virtual bool CanRead() const override;
136 
141  virtual bool CanWrite() const override;
142 
147  virtual uint64_t Position() override;
148 
153  virtual uint64_t Size() override;
154 
159  virtual void Size(uint64_t u64Value) override;
160 
178  static std::shared_ptr<GetProtectedFileStreamResult> Acquire(
179  rmscrypto::api::SharedStream stream,
180  const std::string & userId,
181  IAuthenticationCallback & authenticationCallback,
182  IConsentCallback & consentCallback,
183  PolicyAcquisitionOptions options,
184  ResponseCacheFlags cacheMask
185  = static_cast<ResponseCacheFlags>(RESPONSE_CACHE_INMEMORY |
186  RESPONSE_CACHE_ONDISK |
187  RESPONSE_CACHE_ENCRYPTED));
188 
201  static std::shared_ptr<ProtectedFileStream> Create(
202  std::shared_ptr<UserPolicy> policy,
203  rmscrypto::api::SharedStream stream,
204  const std::string & originalFileExtension);
205 
206  std::shared_ptr<UserPolicy> Policy() { return m_policy; }
207 
208  std::string OriginalFileExtension() { return m_originalFileExtension; }
209 
210 private:
211 
212  ProtectedFileStream(rmscrypto::api::SharedStream pImpl,
213  std::shared_ptr<UserPolicy> policy,
214  const std::string & originalFileExtension);
215 
216 
217  static ProtectedFileStream* CreateProtectedFileStream(
218  std::shared_ptr<UserPolicy> policy,
219  rmscrypto::api::SharedStream stream,
220  std::shared_ptr<pfile::PfileHeader> header);
221 
222 private:
223 
224  std::shared_ptr<UserPolicy> m_policy;
225  std::string m_originalFileExtension;
226  std::shared_ptr<IStream> m_pImpl;
227 
228 }; // class ProtectedFileStream
229 } // namespace modernapi
230 } // namespace rmscore
231 #endif // _RMS_LIB_PROTECTEDFILESTREAM_H_
Base interface for protected streams.
Definition: IStream.h:34
Definition: AuthenticationCallbackImpl.h:16
Implement this interface to provide an approach for getting an OAuth access token.
Definition: IAuthenticationCallback.h:25
Wraps a std::iostream to provide transparent encryption and decryption on read and write...
Definition: ProtectedFileStream.h:47
The result of the ProtectedFileStream::Acquire operation.
Definition: ProtectedFileStream.h:29
Callback to be provided by library user to notify app user of actions to be taken and request their c...
Definition: IConsentCallback.h:24