RandomStream.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // RandomStream.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/RandomStream.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Crypt
  8. // Module: RandomStream
  9. //
  10. // Definition of class RandomInputStream.
  11. //
  12. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_RandomStream_INCLUDED
  18. #define Foundation_RandomStream_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/BufferedStreamBuf.h"
  21. #include <istream>
  22. namespace Poco {
  23. class Foundation_API RandomBuf: public BufferedStreamBuf
  24. /// This streambuf generates random data.
  25. /// On Windows NT, the cryptographic API is used.
  26. /// On Unix, /dev/random is used, if available.
  27. /// Otherwise, a random number generator, some
  28. /// more-or-less random data and a SHA-1 digest
  29. /// is used to generate random data.
  30. {
  31. public:
  32. RandomBuf();
  33. ~RandomBuf();
  34. int readFromDevice(char* buffer, std::streamsize length);
  35. };
  36. class Foundation_API RandomIOS: public virtual std::ios
  37. /// The base class for RandomInputStream.
  38. ///
  39. /// This class is needed to ensure the correct initialization
  40. /// order of the stream buffer and base classes.
  41. {
  42. public:
  43. RandomIOS();
  44. ~RandomIOS();
  45. RandomBuf* rdbuf();
  46. protected:
  47. RandomBuf _buf;
  48. };
  49. class Foundation_API RandomInputStream: public RandomIOS, public std::istream
  50. /// This istream generates random data
  51. /// using the RandomBuf.
  52. {
  53. public:
  54. RandomInputStream();
  55. ~RandomInputStream();
  56. };
  57. } // namespace Poco
  58. #endif // Foundation_RandomStream_INCLUDED