AWS SDK for C++  1.9.109
AWS SDK for C++
CryptoBuf.h
Go to the documentation of this file.
1 
5 #pragma once
6 
9 #include <ios>
10 
11 namespace Aws
12 {
13  namespace Utils
14  {
15  namespace Crypto
16  {
17  typedef std::mbstate_t FPOS_TYPE;
18  static const size_t DEFAULT_BUF_SIZE = 1024;
19  static const size_t PUT_BACK_SIZE = 1;
20 
24  enum class CipherMode
25  {
26  Encrypt,
27  Decrypt
28  };
29 
33  class AWS_CORE_API CryptoBuf : public std::streambuf
34  {
35  public:
36  CryptoBuf() = default;
37  virtual ~CryptoBuf() = default;
38  CryptoBuf(const CryptoBuf&) = delete;
39  CryptoBuf(CryptoBuf&& rhs) = delete;
43  virtual void Finalize() {}
44  };
45 
55  {
56  public:
63  SymmetricCryptoBufSrc(Aws::IStream& stream, SymmetricCipher& cipher, CipherMode cipherMode, size_t bufferSize = DEFAULT_BUF_SIZE);
64 
67 
70 
71  virtual ~SymmetricCryptoBufSrc() { FinalizeCipher(); }
72 
78  void Finalize() override { FinalizeCipher(); }
79 
80  protected:
81  pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out ) override;
82  pos_type seekpos(pos_type pos, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out ) override;
83 
84  private:
85  int_type underflow() override;
86  off_type ComputeAbsSeekPosition(off_type, std::ios_base::seekdir, std::fpos<FPOS_TYPE>);
87  void FinalizeCipher();
88 
89  CryptoBuffer m_isBuf;
90  SymmetricCipher& m_cipher;
91  Aws::IStream& m_stream;
92  CipherMode m_cipherMode;
93  bool m_isFinalized;
94  size_t m_bufferSize;
95  size_t m_putBack;
96  };
97 
106  {
107  public:
114  SymmetricCryptoBufSink(Aws::OStream& stream, SymmetricCipher& cipher, CipherMode cipherMode, size_t bufferSize = DEFAULT_BUF_SIZE, int16_t blockOffset = 0);
117 
123 
125 
133  void Finalize() override { FinalizeCiphersAndFlushSink(); }
134 
135  private:
136  int_type overflow(int_type ch) override;
137  int sync() override;
138  bool writeOutput(bool finalize);
139 
140  CryptoBuffer m_osBuf;
141  SymmetricCipher& m_cipher;
142  Aws::OStream& m_stream;
143  CipherMode m_cipherMode;
144  bool m_isFinalized;
145  int16_t m_blockOffset;
146  };
147  }
148  }
149 }
Aws::Utils::Crypto::SymmetricCryptoBufSrc::SymmetricCryptoBufSrc
SymmetricCryptoBufSrc(const SymmetricCryptoBufSrc &)=delete
Cipher.h
Aws::Utils::Crypto::SymmetricCryptoBufSrc::SymmetricCryptoBufSrc
SymmetricCryptoBufSrc(Aws::IStream &stream, SymmetricCipher &cipher, CipherMode cipherMode, size_t bufferSize=DEFAULT_BUF_SIZE)
Aws::Utils::Crypto::CipherMode
CipherMode
Definition: CryptoBuf.h:25
Aws::Utils::Crypto::SymmetricCryptoBufSrc
Definition: CryptoBuf.h:55
AWS_CORE_API
#define AWS_CORE_API
Definition: Core_EXPORTS.h:25
Aws::Utils::Crypto::FPOS_TYPE
std::mbstate_t FPOS_TYPE
Definition: CryptoBuf.h:17
Aws::Utils::Crypto::CryptoBuf::CryptoBuf
CryptoBuf()=default
Aws::Utils::Crypto::CryptoBuf
Definition: CryptoBuf.h:34
Aws::Utils::Crypto::SymmetricCryptoBufSink::SymmetricCryptoBufSink
SymmetricCryptoBufSink(SymmetricCryptoBufSink &&)=delete
Aws::Utils::Crypto::CryptoBuf::CryptoBuf
CryptoBuf(const CryptoBuf &)=delete
Aws::Utils::Crypto::SymmetricCryptoBufSink
Definition: CryptoBuf.h:106
Aws::IStream
std::basic_istream< char, std::char_traits< char > > IStream
Definition: AWSStreamFwd.h:20
Aws::Utils::Crypto::SymmetricCryptoBufSink::FinalizeCiphersAndFlushSink
void FinalizeCiphersAndFlushSink()
which
int which
Definition: cJSON.h:246
Aws::Utils::Crypto::PUT_BACK_SIZE
static const size_t PUT_BACK_SIZE
Definition: CryptoBuf.h:19
Aws::Utils::Crypto::SymmetricCipher
Definition: Cipher.h:28
Aws::Utils::Crypto::SymmetricCryptoBufSink::SymmetricCryptoBufSink
SymmetricCryptoBufSink(const SymmetricCryptoBufSink &)=delete
Aws::OStream
std::basic_ostream< char, std::char_traits< char > > OStream
Definition: AWSStreamFwd.h:21
Aws::Utils::Crypto::SymmetricCryptoBufSrc::operator=
SymmetricCryptoBufSrc & operator=(const SymmetricCryptoBufSrc &)=delete
Aws::Utils::Crypto::CryptoBuf::CryptoBuf
CryptoBuf(CryptoBuf &&rhs)=delete
Aws::Utils::Crypto::SymmetricCryptoBufSrc::seekpos
pos_type seekpos(pos_type pos, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out) override
Aws::Utils::Crypto::SymmetricCryptoBufSrc::Finalize
void Finalize() override
Definition: CryptoBuf.h:78
Aws::Utils::Crypto::SymmetricCryptoBufSrc::seekoff
pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out) override
Core_EXPORTS.h
Aws::Utils::CryptoBuffer
Definition: Array.h:229
Aws::Utils::Crypto::SymmetricCryptoBufSrc::SymmetricCryptoBufSrc
SymmetricCryptoBufSrc(SymmetricCryptoBufSrc &&)=delete
Aws::Utils::Crypto::CipherMode::Decrypt
@ Decrypt
Aws::Utils::Crypto::CryptoBuf::Finalize
virtual void Finalize()
Definition: CryptoBuf.h:43
Aws
Definition: AccessManagementClient.h:15
Aws::Utils::Crypto::SymmetricCryptoBufSink::operator=
SymmetricCryptoBufSink & operator=(const SymmetricCryptoBufSink &)=delete
Aws::Utils::Crypto::SymmetricCryptoBufSink::operator=
SymmetricCryptoBufSink & operator=(SymmetricCryptoBufSink &&)=delete
Aws::Utils::Crypto::CipherMode::Encrypt
@ Encrypt
Aws::Utils::Crypto::SymmetricCryptoBufSink::SymmetricCryptoBufSink
SymmetricCryptoBufSink(Aws::OStream &stream, SymmetricCipher &cipher, CipherMode cipherMode, size_t bufferSize=DEFAULT_BUF_SIZE, int16_t blockOffset=0)
Aws::Utils::Crypto::SymmetricCryptoBufSink::Finalize
void Finalize() override
Definition: CryptoBuf.h:133
Aws::Utils::Crypto::SymmetricCryptoBufSrc::~SymmetricCryptoBufSrc
virtual ~SymmetricCryptoBufSrc()
Definition: CryptoBuf.h:71
Aws::Utils::Crypto::CryptoBuf::~CryptoBuf
virtual ~CryptoBuf()=default
Aws::Utils::Crypto::SymmetricCryptoBufSrc::operator=
SymmetricCryptoBufSrc & operator=(SymmetricCryptoBufSrc &&)=delete
Aws::Utils::Crypto::DEFAULT_BUF_SIZE
static const size_t DEFAULT_BUF_SIZE
Definition: CryptoBuf.h:18
Aws::Utils::Crypto::SymmetricCryptoBufSink::~SymmetricCryptoBufSink
virtual ~SymmetricCryptoBufSink()