4
// $Id: //poco/1.3/Crypto/include/Poco/Crypto/CryptoStream.h#1 $
8
// Module: CryptoStream
10
// Definition of the CryptoStreamBuf, CryptoInputStream and CryptoOutputStream
13
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
16
// Permission is hereby granted, free of charge, to any person or organization
17
// obtaining a copy of the software and accompanying documentation covered by
18
// this license (the "Software") to use, reproduce, display, distribute,
19
// execute, and transmit the Software, and to prepare derivative works of the
20
// Software, and to permit third-parties to whom the Software is furnished to
21
// do so, all subject to the following:
23
// The copyright notices in the Software and this entire statement, including
24
// the above license grant, this restriction and the following disclaimer,
25
// must be included in all copies of the Software, in whole or in part, and
26
// all derivative works of the Software, unless such copies or derivative
27
// works are solely in the form of machine-executable object code generated by
28
// a source language processor.
30
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
33
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
34
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
35
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
36
// DEALINGS IN THE SOFTWARE.
40
#ifndef Crypto_CryptoStream_INCLUDED
41
#define Crypto_CryptoStream_INCLUDED
44
#include "Poco/Crypto/Crypto.h"
45
#include "Poco/BufferedStreamBuf.h"
46
#include "Poco/Buffer.h"
54
class CryptoTransform;
58
class Crypto_API CryptoStreamBuf : public Poco::BufferedStreamBuf
59
/// This stream buffer performs cryptographic transformation on the data
63
CryptoStreamBuf(std::istream& istr, CryptoTransform* pTransform, std::size_t bufferSize = 8192);
64
CryptoStreamBuf(std::ostream& ostr, CryptoTransform* pTransform,
65
std::size_t bufferSize = 8192);
67
virtual ~CryptoStreamBuf();
72
int readFromDevice(char* buffer, std::streamsize length);
73
int writeToDevice(const char* buffer, std::streamsize length);
76
CryptoTransform* _pTransform;
81
Poco::Buffer<unsigned char> _buffer;
83
CryptoStreamBuf(const CryptoStreamBuf&);
84
CryptoStreamBuf& operator = (const CryptoStreamBuf&);
88
class Crypto_API CryptoIOS : public virtual std::ios
89
/// The base class for CryptoInputStream and CryptoOutputStream.
91
/// This class is needed to ensure correct initialization order of the
92
/// stream buffer and base classes.
95
CryptoIOS(std::istream& istr, CryptoTransform* pTransform,
96
std::size_t bufferSize = 8192);
97
CryptoIOS(std::ostream& ostr, CryptoTransform* pTransform,
98
std::size_t bufferSize = 8192);
100
CryptoStreamBuf* rdbuf();
103
CryptoStreamBuf _buf;
107
class Crypto_API CryptoInputStream : public CryptoIOS, public std::istream
108
/// This stream transforms all data passing through it using the given
111
/// Use a CryptoTransform object provided by Cipher::createEncrytor() or
112
/// Cipher::createDecryptor() to create an encrypting or decrypting stream,
116
CryptoInputStream(std::istream& istr, CryptoTransform* pTransform, std::size_t bufferSize = 8192);
117
/// Create a new CryptoInputStream object. The CryptoInputStream takes the
118
/// ownership of the given CryptoTransform object.
120
CryptoInputStream(std::istream& istr, Cipher& cipher, std::size_t bufferSize = 8192);
121
/// Create a new encrypting CryptoInputStream object using the given cipher.
123
~CryptoInputStream();
127
class Crypto_API CryptoOutputStream : public CryptoIOS, public std::ostream
128
/// This stream transforms all data passing through it using the given
131
/// Use a CryptoTransform object provided by Cipher::createEncrytor() or
132
/// Cipher::createDecryptor() to create an encrypting or decrypting stream,
135
/// After all data has been passed through the stream, close() must be called
136
/// to ensure completion of cryptographic transformation.
139
CryptoOutputStream(std::ostream& ostr, CryptoTransform* pTransform, std::size_t bufferSize = 8192);
140
/// Create a new CryptoOutputStream object. The CryptoOutputStream takes the
141
/// ownership of the given CryptoTransform object.
143
CryptoOutputStream(std::ostream& ostr, Cipher& cipher, std::size_t bufferSize = 8192);
144
/// Create a new decrypting CryptoOutputStream object using the given cipher.
146
~CryptoOutputStream();
152
} } // namespace Poco::Crypto
155
#endif // Crypto_CryptoStream_INCLUDED