diff options
author | madmaxoft <github@xoft.cz> | 2014-04-29 17:37:15 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-04-29 17:37:15 +0200 |
commit | 6cb2d2461f869d5c9d986cccec5edf1021878df2 (patch) | |
tree | 41445e9e4a1336026e905be5a20700b58511c58d /src/PolarSSL++/Sha1Checksum.h | |
parent | Moved cPublicKey to its separate file in PolarSSL++. (diff) | |
download | cuberite-6cb2d2461f869d5c9d986cccec5edf1021878df2.tar cuberite-6cb2d2461f869d5c9d986cccec5edf1021878df2.tar.gz cuberite-6cb2d2461f869d5c9d986cccec5edf1021878df2.tar.bz2 cuberite-6cb2d2461f869d5c9d986cccec5edf1021878df2.tar.lz cuberite-6cb2d2461f869d5c9d986cccec5edf1021878df2.tar.xz cuberite-6cb2d2461f869d5c9d986cccec5edf1021878df2.tar.zst cuberite-6cb2d2461f869d5c9d986cccec5edf1021878df2.zip |
Diffstat (limited to '')
-rw-r--r-- | src/PolarSSL++/Sha1Checksum.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/PolarSSL++/Sha1Checksum.h b/src/PolarSSL++/Sha1Checksum.h new file mode 100644 index 000000000..68fdbcf1b --- /dev/null +++ b/src/PolarSSL++/Sha1Checksum.h @@ -0,0 +1,52 @@ + +// Sha1Checksum.h + +// Declares the cSha1Checksum class representing the SHA-1 checksum calculator + + + + + +#pragma once + +#include "polarssl/sha1.h" + + + + + +/** Calculates a SHA1 checksum for data stream */ +class cSha1Checksum +{ +public: + typedef Byte Checksum[20]; // The type used for storing the checksum + + cSha1Checksum(void); + + /** Adds the specified data to the checksum */ + void Update(const Byte * a_Data, size_t a_Length); + + /** Calculates and returns the final checksum */ + void Finalize(Checksum & a_Output); + + /** Returns true if the object is accepts more input data, false if Finalize()-d (need to Restart()) */ + bool DoesAcceptInput(void) const { return m_DoesAcceptInput; } + + /** Converts a raw 160-bit SHA1 digest into a Java Hex representation + According to http://wiki.vg/wiki/index.php?title=Protocol_Encryption&oldid=2802 + */ + static void DigestToJava(const Checksum & a_Digest, AString & a_JavaOut); + + /** Clears the current context and start a new checksum calculation */ + void Restart(void); + +protected: + /** True if the object is accepts more input data, false if Finalize()-d (need to Restart()) */ + bool m_DoesAcceptInput; + + sha1_context m_Sha1; +} ; + + + + |