PageRenderTime 39ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/mordor/streams/random.h

http://github.com/mozy/mordor
C Header | 43 lines | 25 code | 11 blank | 7 comment | 0 complexity | 62acb1079a7567d39fc98dcd4c492596 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #ifndef __MORDOR_RANDOM_STREAM_H__
  2. #define __MORDOR_RANDOM_STREAM_H__
  3. // Copyright (c) 2009 - Mozy, Inc.
  4. #include "stream.h"
  5. #ifdef WINDOWS
  6. #include <wincrypt.h>
  7. #endif
  8. namespace Mordor {
  9. /// a stream to generate random data
  10. /// uses CryptGenRandom() on WINDOWS; OpenSSL RAND_bytes elsewhere (seeded automatically by /dev/urandom)
  11. /// @note RandomStream is not guaranteed to be thread safety.
  12. /// On Windows platform, the thread safety depends on the cryptographic service provider implementation
  13. /// On Linux/MacOS platform, it depends on openssl thread safety. By default it isn't, use OpensslLockManager
  14. /// to ensure the thread safety.
  15. class RandomStream : public Stream
  16. {
  17. public:
  18. typedef boost::shared_ptr<RandomStream> ptr;
  19. RandomStream();
  20. ~RandomStream();
  21. bool supportsRead() { return true; }
  22. size_t read(void *buffer, size_t length);
  23. using Stream::read;
  24. bool supportsSeek() { return true; }
  25. long long seek(long long offset, Anchor anchor = BEGIN) { return 0; }
  26. private:
  27. #ifdef WINDOWS
  28. HCRYPTPROV m_hCP;
  29. #endif
  30. };
  31. }
  32. #endif // __MORDOR_RANDOM_STREAM_H__