libUTL++
MD5.h
1 #pragma once
2 
4 
5 #include <libutl/Object.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
13 #undef _A
14 #undef _B
15 #undef _C
16 #undef _D
17 
19 // MD5sum //////////////////////////////////////////////////////////////////////////////////////////
21 
29 
31 class MD5sum : public Object
32 {
34 
35 public:
36  MD5sum(const String& str)
37  {
38  set(str);
39  }
40 
41  MD5sum(const uint32_t* sum)
42  {
43  memcpy(_sum, sum, 16);
44  }
45 
46  virtual int compare(const Object& rhs) const;
47 
48  virtual void copy(const Object& rhs);
49 
50  virtual size_t hash(size_t size) const;
51 
52  virtual void serialize(Stream& stream, uint_t io, uint_t mode = ser_default);
53 
54  void set(const String& str);
55 
56  virtual String toString() const;
57 
58 private:
59  void
60  init()
61  {
62  memset(_sum, 0, 8);
63  }
64  void
65  deInit()
66  {
67  }
68 
69 private:
70  uint32_t _sum[4];
71 };
72 
74 // MD5 /////////////////////////////////////////////////////////////////////////////////////////////
76 
87 
89 class MD5 : public Object
90 {
92 
93 public:
94  virtual void copy(const Object& rhs);
95 
97  void add(byte_t ch);
98 
100  void add(const byte_t* array, size_t len);
101 
103  void clear();
104 
106  MD5sum get() const;
107 
109  static MD5sum compute(Stream& is);
110 
111 private:
112  void
113  init()
114  {
115  clear();
116  }
117  void
118  deInit()
119  {
120  }
121  void finish();
122  void doBlock(const byte_t* buf, size_t len);
123  static uint32_t revBE(uint32_t w);
124  static uint32_t revLE(uint32_t w);
125 
126 private:
127  uint32_t _A;
128  uint32_t _B;
129  uint32_t _C;
130  uint32_t _D;
131  uint32_t _len[2];
132  uint32_t _bufLen;
133  byte_t _buf[128];
134 };
135 
137 
138 UTL_NS_END;
String toString(const FwdIt &begin, const FwdIt &end, const String &sep, bool key=false)
Obtain a string representation of a sequence (via Object::toString()).
void serialize(bool &b, Stream &stream, uint_t io, uint_t mode=ser_default)
Serialize a boolean.
void deInit()
De-initialize UTL++.
default representation (via getSerializeMode())
Definition: util.h:75
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
unsigned char byte_t
Unsigned character.
Definition: types.h:31
Character string.
Definition: String.h:31
unsigned int uint32_t
Unsigned 32-bit integer.
Definition: types.h:115
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
Generate MD5 checksums.
Definition: MD5.h:89
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
Stream I/O abstraction.
Definition: Stream.h:68
Root of UTL++ class hierarchy.
Definition: Object.h:52
int compare(bool lhs, bool rhs)
Compare two boolean values.
void init()
Initialize UTL++.
Store MD5 checksum.
Definition: MD5.h:31