1//
2// RandomStream.h
3//
4// Library: Foundation
5// Package: Crypt
6// Module: RandomStream
7//
8// Definition of class RandomInputStream.
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_RandomStream_INCLUDED
18#define Foundation_RandomStream_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include "Poco/BufferedStreamBuf.h"
23#include <istream>
24
25
26namespace Poco {
27
28
29class Foundation_API RandomBuf: public BufferedStreamBuf
30 /// This streambuf generates random data.
31 /// On Windows NT, the cryptographic API is used.
32 /// On Unix, /dev/random is used, if available.
33 /// Otherwise, a random number generator, some
34 /// more-or-less random data and a SHA-1 digest
35 /// is used to generate random data.
36{
37public:
38 RandomBuf();
39 ~RandomBuf();
40 int readFromDevice(char* buffer, std::streamsize length);
41};
42
43
44class Foundation_API RandomIOS: public virtual std::ios
45 /// The base class for RandomInputStream.
46 ///
47 /// This class is needed to ensure the correct initialization
48 /// order of the stream buffer and base classes.
49{
50public:
51 RandomIOS();
52 ~RandomIOS();
53 RandomBuf* rdbuf();
54
55protected:
56 RandomBuf _buf;
57};
58
59
60class Foundation_API RandomInputStream: public RandomIOS, public std::istream
61 /// This istream generates random data
62 /// using the RandomBuf.
63{
64public:
65 RandomInputStream();
66 ~RandomInputStream();
67};
68
69
70} // namespace Poco
71
72
73#endif // Foundation_RandomStream_INCLUDED
74