gloox  1.1-svn
sha.h
1 /*
2  Copyright (c) 2006-2009 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 #ifndef SHA_H__
14 #define SHA_H__
15 
16 #include "macros.h"
17 
18 #include <string>
19 
20 namespace gloox
21 {
22 
29  class GLOOX_API SHA
30  {
31 
32  public:
38  static const std::string sha1( const std::string& data );
39 
43  SHA();
44 
48  virtual ~SHA();
49 
53  void reset();
54 
58  void finalize();
59 
65  const std::string hex();
66 
72  const std::string binary();
73 
79  void feed( const unsigned char* data, unsigned length );
80 
85  void feed( const std::string& data );
86 
87  private:
88  void process();
89  void pad();
90  inline unsigned shift( int bits, unsigned word );
91  void init();
92 
93  unsigned H[5];
94  unsigned Length_Low;
95  unsigned Length_High;
96  unsigned char Message_Block[64];
97  int Message_Block_Index;
98  bool m_finished;
99  bool m_corrupted;
100 
101  };
102 
103 }
104 
105 #endif // SHA_H__