AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
CryptoBuf.h
1
5#pragma once
6
7#include <aws/core/utils/crypto/Cipher.h>
8#include <aws/core/Core_EXPORTS.h>
9#include <ios>
10
11namespace 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,
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
54 class AWS_CORE_API SymmetricCryptoBufSrc : public CryptoBuf
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
105 class AWS_CORE_API SymmetricCryptoBufSink : public CryptoBuf
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}
CryptoBuf(const CryptoBuf &)=delete
CryptoBuf(CryptoBuf &&rhs)=delete
virtual ~CryptoBuf()=default
SymmetricCryptoBufSink(Aws::OStream &stream, SymmetricCipher &cipher, CipherMode cipherMode, size_t bufferSize=DEFAULT_BUF_SIZE, int16_t blockOffset=0)
SymmetricCryptoBufSink(const SymmetricCryptoBufSink &)=delete
SymmetricCryptoBufSink & operator=(SymmetricCryptoBufSink &&)=delete
SymmetricCryptoBufSink(SymmetricCryptoBufSink &&)=delete
SymmetricCryptoBufSink & operator=(const SymmetricCryptoBufSink &)=delete
SymmetricCryptoBufSrc & operator=(const SymmetricCryptoBufSrc &)=delete
SymmetricCryptoBufSrc(Aws::IStream &stream, SymmetricCipher &cipher, CipherMode cipherMode, size_t bufferSize=DEFAULT_BUF_SIZE)
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
pos_type seekpos(pos_type pos, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out) override
SymmetricCryptoBufSrc(const SymmetricCryptoBufSrc &)=delete
SymmetricCryptoBufSrc & operator=(SymmetricCryptoBufSrc &&)=delete
SymmetricCryptoBufSrc(SymmetricCryptoBufSrc &&)=delete
std::mbstate_t FPOS_TYPE
Definition CryptoBuf.h:17
static const size_t PUT_BACK_SIZE
Definition CryptoBuf.h:19
static const size_t DEFAULT_BUF_SIZE
Definition CryptoBuf.h:18
std::basic_istream< char, std::char_traits< char > > IStream
std::basic_ostream< char, std::char_traits< char > > OStream