File: RandomStream.h

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (44 lines) | stat: -rw-r--r-- 783 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once

#include "Core/Io/Stream.h"

namespace ssl {

	/**
	 * A stream of cryptographically secure random numbers retrieved from the system.
	 *
	 * Uses CryptGenRandom on Windows, and /dev/urandom on Linux.
	 *
	 * Note: This stream is not buffered in any way, so it is a good idea to read from it in large
	 * chunks.
	 */
	class RandomStream : public IStream {
		STORM_CLASS;
	public:
		// Create.
		STORM_CTOR RandomStream();

		// Copy.
		RandomStream(const RandomStream &o);

		// Destroy.
		~RandomStream();

		// More data?
		Bool STORM_FN more() override;

		// Read data.
		Buffer STORM_FN read(Buffer to) override;

		// Close.
		void STORM_FN close() override;

	private:
		// Platform-dependent data.
		size_t data;

		// Initialize 'data'.
		void init();
	};

}