hl_sha1wrapper.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * hashlib++ - a simple hash library for C++
  3. *
  4. * Copyright (c) 2007-2010 Benjamin Grüdelbach
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1) Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * 2) Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in
  14. * the documentation and/or other materials provided with the
  15. * distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  21. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  24. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. //----------------------------------------------------------------------
  29. /**
  30. * @file hl_sha1wrapper.h
  31. * @brief This file contains the definition of the sha1wrapper
  32. * class.
  33. * @date Mo 17 Sep 2007
  34. */
  35. //----------------------------------------------------------------------
  36. //include protection
  37. #ifndef SHA1WRAPPER_H
  38. #define SHA1WRAPPER_H
  39. //----------------------------------------------------------------------
  40. //hashlib++ includes
  41. #include "hl_hashwrapper.h"
  42. #include "hl_sha1.h"
  43. //----------------------------------------------------------------------
  44. /**
  45. * @brief This class represents the SHA1 wrapper-class
  46. *
  47. * You can use this class to easily create a sha1 hash.
  48. * Just create an instance of sha1wrapper and call the
  49. * inherited memberfunctions getHashFromString()
  50. * and getHashFromFile() to create a hash based on a
  51. * string or a file.
  52. *
  53. * Have a look at the following example:
  54. *
  55. * @include sha1example.cpp
  56. *
  57. * sha1wrapper implements resetContext(), updateContext()
  58. * and hashIt() to create a hash.
  59. */
  60. class sha1wrapper : public hashwrapper
  61. {
  62. protected:
  63. /**
  64. * SHA1 access
  65. */
  66. SHA1 *sha1;
  67. /*
  68. * SHA1 context
  69. */
  70. HL_SHA1_CTX context;
  71. /**
  72. * @brief This method ends the hash process
  73. * and returns the hash as string.
  74. *
  75. * @return a hash as std::string
  76. */
  77. virtual std::string hashIt(void);
  78. /**
  79. * @brief This internal member-function
  80. * convertes the hash-data to a
  81. * std::string (HEX).
  82. *
  83. * @param data The hash-data to covert into HEX
  84. * @return the converted data as std::string
  85. */
  86. virtual std::string convToString(unsigned char *data);
  87. /**
  88. * @brief This method adds the given data to the
  89. * current hash context
  90. *
  91. * @param data The data to add to the current context
  92. * @param len The length of the data to add
  93. */
  94. virtual void updateContext(unsigned char *data, unsigned int len);
  95. /**
  96. * @brief This method resets the current hash context.
  97. * In other words: It starts a new hash process.
  98. */
  99. virtual void resetContext(void);
  100. /**
  101. * @brief This method should return the hash of the
  102. * test-string "The quick brown fox jumps over the lazy
  103. * dog"
  104. */
  105. virtual std::string getTestHash(void);
  106. public:
  107. /**
  108. * @brief default constructor
  109. */
  110. sha1wrapper();
  111. /**
  112. * @brief default destructor
  113. */
  114. virtual ~sha1wrapper();
  115. };
  116. //----------------------------------------------------------------------
  117. //end of include protection
  118. #endif
  119. //----------------------------------------------------------------------
  120. //EOF