diff options
author | Michael Vogt <michael.vogt@ubuntu.com> | 2011-02-25 18:59:29 +0100 |
---|---|---|
committer | Michael Vogt <michael.vogt@ubuntu.com> | 2011-02-25 18:59:29 +0100 |
commit | 7ac56f8ffd5544c6c1f681f79cafbf72d37d0b82 (patch) | |
tree | b14e5e4c1a03be5ac2bd22e41ee74e3634e71923 /apt-pkg/contrib/sha2.h | |
parent | 84a0890e6ef49b5d41a0b9ff0b5a5fe95cca6f3e (diff) |
template based hashsum implementation
Diffstat (limited to 'apt-pkg/contrib/sha2.h')
-rw-r--r-- | apt-pkg/contrib/sha2.h | 70 |
1 files changed, 15 insertions, 55 deletions
diff --git a/apt-pkg/contrib/sha2.h b/apt-pkg/contrib/sha2.h index 5148b05c3..2c3fcae12 100644 --- a/apt-pkg/contrib/sha2.h +++ b/apt-pkg/contrib/sha2.h @@ -20,38 +20,21 @@ #include <stdint.h> #include "sha2_internal.h" +#include "hashsum_template.h" using std::string; using std::min; -// SHA512 class SHA512Summation; +class SHA256Summation; -class SHA512SumValue -{ - friend class SHA512Summation; - unsigned char Sum[64]; - - public: - - // Accessors - bool operator ==(const SHA512SumValue &rhs) const; - string Value() const; - inline void Value(unsigned char S[64]) - {for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];}; - inline operator string() const {return Value();}; - bool Set(string Str); - inline void Set(unsigned char S[64]) - {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];}; - - SHA512SumValue(string Str); - SHA512SumValue(); -}; +typedef HashSumValue<512> SHA512SumValue; +typedef HashSumValue<256> SHA256SumValue; -class SHA512Summation +class SHA256Summation { - SHA512_CTX ctx; - unsigned char Sum[64]; + SHA256_CTX ctx; + unsigned char Sum[32]; bool Done; public: @@ -61,39 +44,15 @@ class SHA512Summation bool AddFD(int Fd,unsigned long Size); inline bool Add(const unsigned char *Beg,const unsigned char *End) {return Add(Beg,End-Beg);}; - SHA512SumValue Result(); - - SHA512Summation(); -}; - -// SHA256 -class SHA256Summation; - -class SHA256SumValue -{ - friend class SHA256Summation; - unsigned char Sum[32]; + SHA256SumValue Result(); - public: - - // Accessors - bool operator ==(const SHA256SumValue &rhs) const; - string Value() const; - inline void Value(unsigned char S[32]) - {for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];}; - inline operator string() const {return Value();}; - bool Set(string Str); - inline void Set(unsigned char S[32]) - {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];}; - - SHA256SumValue(string Str); - SHA256SumValue(); + SHA256Summation(); }; -class SHA256Summation +class SHA512Summation { - SHA256_CTX ctx; - unsigned char Sum[32]; + SHA512_CTX ctx; + unsigned char Sum[64]; bool Done; public: @@ -103,9 +62,10 @@ class SHA256Summation bool AddFD(int Fd,unsigned long Size); inline bool Add(const unsigned char *Beg,const unsigned char *End) {return Add(Beg,End-Beg);}; - SHA256SumValue Result(); + SHA512SumValue Result(); - SHA256Summation(); + SHA512Summation(); }; + #endif |