#ifndef SECURE_RANDOM_H__
#define SECURE_RANDOM_H__

#include "maxon/interface.h"

namespace maxon
{

struct _SecureRandomProvider;
using SecureRandomProvider = Pointer<_SecureRandomProvider>;

//----------------------------------------------------------------------------------------
/// Class for generating cryptographically strong random sequences. The following systems are used:
/// - Windows: CryptGenRandom (http://msdn.microsoft.com/en-us/library/windows/desktop/aa379942(v=vs.85).aspx)
/// - Linux: \/dev/random
/// - MacOS: random (https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man3/random.3.html)
//----------------------------------------------------------------------------------------
class SecureRandom
{
	MAXON_INTERFACE_NONVIRTUAL(SecureRandom, MAXON_REFERENCE_NONE, "net.maxon.interface.securerandom");

public:
	//----------------------------------------------------------------------------------------
	/// Gets a provider for the CSPRNG.
	/// @return												The provider. If the return value is nullptr the function failed.
	//----------------------------------------------------------------------------------------
	static MAXON_METHOD SecureRandomProvider GetDefaultProvider();

	//----------------------------------------------------------------------------------------
	/// Gets a provider for the CSPRNG.
	/// @return												The provider. If the return value is nullptr the function failed.
	//----------------------------------------------------------------------------------------
	// static MAXON_METHOD void FreeProvider(SecureRandomProvider provider);

	//----------------------------------------------------------------------------------------
	/// Fills the buffer with cryptographically strong random bytes.
	/// example: SecureRandom::GetRandomNumber(provider, ToBlock<Byte>(certificateBuffer, SIZEOF(certificateBuffer)));
	/// @param[in] provider						The secure random provider.
	/// @param[in] buffer							A pointer to a buffer that is to be filled.
	/// @return												True, if the buffer was filled successfully, false otherwise.
	//----------------------------------------------------------------------------------------
	static MAXON_METHOD Bool GetRandomNumber(SecureRandomProvider provider, const Block<Byte>& buffer);
};

// include autogenerated headerfile here
#include "secure_random1.hxx"
// include autogenerated headerfile here
#include "secure_random2.hxx"

} // namespace maxon

#endif // SECURE_RANDOM_H__
