DigestStream.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // DigestStream.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/DigestStream.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Crypt
  8. // Module: DigestStream
  9. //
  10. // Definition of classes DigestInputStream and DigestOutputStream.
  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_DigestStream_INCLUDED
  18. #define Foundation_DigestStream_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/BufferedStreamBuf.h"
  21. #include "Poco/DigestEngine.h"
  22. #include <istream>
  23. #include <ostream>
  24. namespace Poco {
  25. class Foundation_API DigestBuf: public BufferedStreamBuf
  26. /// This streambuf computes a digest of all data going
  27. /// through it.
  28. {
  29. public:
  30. DigestBuf(DigestEngine& eng);
  31. DigestBuf(DigestEngine& eng, std::istream& istr);
  32. DigestBuf(DigestEngine& eng, std::ostream& ostr);
  33. ~DigestBuf();
  34. int readFromDevice(char* buffer, std::streamsize length);
  35. int writeToDevice(const char* buffer, std::streamsize length);
  36. void close();
  37. private:
  38. DigestEngine& _eng;
  39. std::istream* _pIstr;
  40. std::ostream* _pOstr;
  41. static const int BUFFER_SIZE;
  42. };
  43. class Foundation_API DigestIOS: public virtual std::ios
  44. /// The base class for DigestInputStream and DigestOutputStream.
  45. ///
  46. /// This class is needed to ensure the correct initialization
  47. /// order of the stream buffer and base classes.
  48. {
  49. public:
  50. DigestIOS(DigestEngine& eng);
  51. DigestIOS(DigestEngine& eng, std::istream& istr);
  52. DigestIOS(DigestEngine& eng, std::ostream& ostr);
  53. ~DigestIOS();
  54. DigestBuf* rdbuf();
  55. protected:
  56. DigestBuf _buf;
  57. };
  58. class Foundation_API DigestInputStream: public DigestIOS, public std::istream
  59. /// This istream computes a digest of
  60. /// all the data passing through it,
  61. /// using a DigestEngine.
  62. {
  63. public:
  64. DigestInputStream(DigestEngine& eng, std::istream& istr);
  65. ~DigestInputStream();
  66. };
  67. class Foundation_API DigestOutputStream: public DigestIOS, public std::ostream
  68. /// This ostream computes a digest of
  69. /// all the data passing through it,
  70. /// using a DigestEngine.
  71. /// To ensure that all data has been incorporated
  72. /// into the digest, call close() or flush() before
  73. /// you obtain the digest from the digest engine.
  74. {
  75. public:
  76. DigestOutputStream(DigestEngine& eng);
  77. DigestOutputStream(DigestEngine& eng, std::ostream& ostr);
  78. ~DigestOutputStream();
  79. void close();
  80. };
  81. } // namespace Poco
  82. #endif // Foundation_DigestStream_INCLUDED