~ubuntu-branches/ubuntu/quantal/poco/quantal

« back to all changes in this revision

Viewing changes to Crypto/include/Poco/Crypto/CryptoStream.h

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2008-11-15 11:39:15 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081115113915-7kauhm2c3m2i7oid
Tags: 1.3.3p1-2
* Fixed FTBFS with GCC 4.4 due to missing #include (Closes: #505619)
* Renamed 20_gcc43-missing-include.dpatch to 20_gcc44-missing-include.dpatch
* Downgraded dependencies on -dbg packages (Closes: #504342)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// CryptoStream.h
 
3
//
 
4
// $Id: //poco/1.3/Crypto/include/Poco/Crypto/CryptoStream.h#1 $
 
5
//
 
6
// Library: Crypto
 
7
// Package: CryptoCore
 
8
// Module:  CryptoStream
 
9
//
 
10
// Definition of the CryptoStreamBuf, CryptoInputStream and CryptoOutputStream
 
11
// classes.
 
12
//
 
13
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
 
14
// and Contributors.
 
15
//
 
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:
 
22
// 
 
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.
 
29
// 
 
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.
 
37
//
 
38
 
 
39
 
 
40
#ifndef Crypto_CryptoStream_INCLUDED
 
41
#define Crypto_CryptoStream_INCLUDED
 
42
 
 
43
 
 
44
#include "Poco/Crypto/Crypto.h"
 
45
#include "Poco/BufferedStreamBuf.h"
 
46
#include "Poco/Buffer.h"
 
47
#include <iostream>
 
48
 
 
49
 
 
50
namespace Poco {
 
51
namespace Crypto {
 
52
 
 
53
 
 
54
class CryptoTransform;
 
55
class Cipher;
 
56
 
 
57
 
 
58
class Crypto_API CryptoStreamBuf : public Poco::BufferedStreamBuf
 
59
        /// This stream buffer performs cryptographic transformation on the data
 
60
        /// going through it.
 
61
{
 
62
public:
 
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);
 
66
 
 
67
        virtual ~CryptoStreamBuf();
 
68
 
 
69
        void close();
 
70
 
 
71
protected:
 
72
        int readFromDevice(char* buffer, std::streamsize length);
 
73
        int writeToDevice(const char* buffer, std::streamsize length);
 
74
 
 
75
private:
 
76
        CryptoTransform* _pTransform;
 
77
        std::istream*    _pIstr;
 
78
        std::ostream*    _pOstr;
 
79
        bool                     _eof;
 
80
 
 
81
        Poco::Buffer<unsigned char> _buffer;
 
82
 
 
83
        CryptoStreamBuf(const CryptoStreamBuf&);
 
84
        CryptoStreamBuf& operator = (const CryptoStreamBuf&);
 
85
};
 
86
 
 
87
 
 
88
class Crypto_API CryptoIOS : public virtual std::ios
 
89
        /// The base class for CryptoInputStream and CryptoOutputStream.
 
90
        ///
 
91
        /// This class is needed to ensure correct initialization order of the
 
92
        /// stream buffer and base classes.
 
93
{
 
94
public:
 
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);
 
99
        ~CryptoIOS();
 
100
        CryptoStreamBuf* rdbuf();
 
101
 
 
102
protected:
 
103
        CryptoStreamBuf _buf;
 
104
};
 
105
 
 
106
 
 
107
class Crypto_API CryptoInputStream : public CryptoIOS, public std::istream
 
108
        /// This stream transforms all data passing through it using the given
 
109
        /// CryptoTransform.
 
110
        ///
 
111
        /// Use a CryptoTransform object provided by Cipher::createEncrytor() or
 
112
        /// Cipher::createDecryptor() to create an encrypting or decrypting stream,
 
113
        /// respectively.
 
114
{
 
115
public:
 
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.
 
119
 
 
120
        CryptoInputStream(std::istream& istr, Cipher& cipher, std::size_t bufferSize = 8192);
 
121
                /// Create a new encrypting CryptoInputStream object using the given cipher.
 
122
 
 
123
        ~CryptoInputStream();
 
124
};
 
125
 
 
126
 
 
127
class Crypto_API CryptoOutputStream : public CryptoIOS, public std::ostream
 
128
        /// This stream transforms all data passing through it using the given
 
129
        /// CryptoTransform.
 
130
        ///
 
131
        /// Use a CryptoTransform object provided by Cipher::createEncrytor() or
 
132
        /// Cipher::createDecryptor() to create an encrypting or decrypting stream,
 
133
        /// respectively.
 
134
        ///
 
135
        /// After all data has been passed through the stream, close() must be called
 
136
        /// to ensure completion of cryptographic transformation.
 
137
{
 
138
public:
 
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.
 
142
 
 
143
        CryptoOutputStream(std::ostream& ostr, Cipher& cipher, std::size_t bufferSize = 8192);
 
144
                /// Create a new decrypting CryptoOutputStream object using the given cipher.
 
145
 
 
146
        ~CryptoOutputStream();
 
147
 
 
148
        void close();
 
149
};
 
150
 
 
151
 
 
152
} } // namespace Poco::Crypto
 
153
 
 
154
 
 
155
#endif // Crypto_CryptoStream_INCLUDED