1//
2// DigestStream.h
3//
4// Library: Foundation
5// Package: Crypt
6// Module: DigestStream
7//
8// Definition of classes DigestInputStream and DigestOutputStream.
9//
10// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_DigestStream_INCLUDED
18#define Foundation_DigestStream_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include "Poco/BufferedStreamBuf.h"
23#include "Poco/DigestEngine.h"
24#include <istream>
25#include <ostream>
26
27
28namespace Poco {
29
30
31class Foundation_API DigestBuf: public BufferedStreamBuf
32 /// This streambuf computes a digest of all data going
33 /// through it.
34{
35public:
36 DigestBuf(DigestEngine& eng);
37 DigestBuf(DigestEngine& eng, std::istream& istr);
38 DigestBuf(DigestEngine& eng, std::ostream& ostr);
39 ~DigestBuf();
40 int readFromDevice(char* buffer, std::streamsize length);
41 int writeToDevice(const char* buffer, std::streamsize length);
42 void close();
43
44private:
45 DigestEngine& _eng;
46 std::istream* _pIstr;
47 std::ostream* _pOstr;
48 static const int BUFFER_SIZE;
49};
50
51
52class Foundation_API DigestIOS: public virtual std::ios
53 /// The base class for DigestInputStream and DigestOutputStream.
54 ///
55 /// This class is needed to ensure the correct initialization
56 /// order of the stream buffer and base classes.
57{
58public:
59 DigestIOS(DigestEngine& eng);
60 DigestIOS(DigestEngine& eng, std::istream& istr);
61 DigestIOS(DigestEngine& eng, std::ostream& ostr);
62 ~DigestIOS();
63 DigestBuf* rdbuf();
64
65protected:
66 DigestBuf _buf;
67};
68
69
70class Foundation_API DigestInputStream: public DigestIOS, public std::istream
71 /// This istream computes a digest of
72 /// all the data passing through it,
73 /// using a DigestEngine.
74{
75public:
76 DigestInputStream(DigestEngine& eng, std::istream& istr);
77 ~DigestInputStream();
78};
79
80
81class Foundation_API DigestOutputStream: public DigestIOS, public std::ostream
82 /// This ostream computes a digest of
83 /// all the data passing through it,
84 /// using a DigestEngine.
85 /// To ensure that all data has been incorporated
86 /// into the digest, call close() or flush() before
87 /// you obtain the digest from the digest engine.
88{
89public:
90 DigestOutputStream(DigestEngine& eng);
91 DigestOutputStream(DigestEngine& eng, std::ostream& ostr);
92 ~DigestOutputStream();
93 void close();
94};
95
96
97} // namespace Poco
98
99
100#endif // Foundation_DigestStream_INCLUDED
101