sha1.h
Go to the documentation of this file.
1 #ifndef cetlib_sha1_h
2 #define cetlib_sha1_h
3 
4 // ======================================================================
5 //
6 // sha1: Secure Hash Algorithm as defined in FIPS PUB 180-1, 1993-05-11
7 //
8 // ======================================================================
9 
10 #ifdef __APPLE__
11 #define COMMON_DIGEST_FOR_OPENSSL
12 #include <CommonCrypto/CommonDigest.h>
13 #undef COMMON_DIGEST_FOR_OPENSSL
14 #else
15 #include <openssl/sha.h>
16 #endif
17 #include <array>
18 #include <string>
19 
20 namespace cet {
21  class sha1;
22 }
23 
24 // ======================================================================
25 
26 class cet::sha1 {
27 public:
28  static std::size_t constexpr digest_sz{20};
29  using uchar = unsigned char;
30  using digest_t = std::array<uchar, digest_sz>;
31 
32  sha1();
33  explicit sha1(std::string const& mesg);
34  explicit sha1(char const mesg);
35 
36  void reset();
37 
38  sha1& operator<<(std::string const& mesg);
39  sha1& operator<<(char const mesg);
40  digest_t digest();
41 
42 private:
43  SHA_CTX context;
44 
45 }; // sha1
46 
47 // ======================================================================
48 
49 #endif /* cetlib_sha1_h */
50 
51 // Local variables:
52 // mode: c++
53 // End:
unsigned char uchar
Definition: sha1.h:29
std::string string
Definition: nybbler.cc:12
static std::size_t constexpr digest_sz
Definition: sha1.h:28
Definition: sha1.h:26
std::array< uchar, digest_sz > digest_t
Definition: sha1.h:30
sha1()
Definition: sha1.cc:5
SHA_CTX context
Definition: sha1.h:43
digest_t digest()
Definition: sha1.cc:45
sha1 & operator<<(std::string const &mesg)
Definition: sha1.cc:29
void reset()
Definition: sha1.cc:23