Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MD5.h
1 /*
2  * $Id$
3  * MD5 class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2009, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_CHECKSUM_MD5_H
23 #define ELM_CHECKSUM_MD5_H
24 
25 #include <elm/types.h>
26 #include <elm/string.h>
27 #include <elm/io.h>
28 #include <elm/io/InStream.h>
29 #include <elm/io/OutStream.h>
30 
31 namespace elm { namespace checksum {
32 
33 // MD5 class
34 class MD5: public io::OutStream {
35 public:
36  typedef unsigned char digest_t[16];
37 
38  MD5(void);
39  virtual ~MD5(void);
40  void digest(digest_t tab);
41  void print(io::Output& out);
42 
43  void put(const void *buffer, t::uint32 length);
44  void put(const cstring& str);
45  void put(const string& str);
46  void put(io::InStream& in);
47  void put(io::InStream& in, int length);
48 
49  inline MD5& operator<<(const char *str) { put(CString(str)); return *this; }
50  inline MD5& operator<<(const CString& str) { put(str); return *this; }
51  inline MD5& operator<<(const String& str) { put(str); return *this; }
52  template <class T> inline MD5& operator<<(const T& value) { put(&value, sizeof(T)); return *this; }
53 
54  // io::OutStream overload
55  virtual int write(const char *buffer, int size);
56  virtual int flush(void);
57  virtual cstring lastErrorMessage(void);
58 
59 private:
60  typedef t::uint32 md5_size;
61 
62  void finalize(void);
63  void update(void);
64  void encode(unsigned char *buf);
65  void addsize (unsigned char *M, md5_size index, md5_size oldlen);
66 
67  bool finalized;
68  struct {
69  t::uint32 A, B, C, D;
70  } regs;
71  unsigned char *buf;
72  md5_size size;
73  md5_size bits;
74  digest_t _digest;
75 };
76 
77 inline io::Output& operator<<(io::Output& out, MD5& md5) { md5.print(out); return out; }
78 
79 } } // elm::checksum
80 
81 #endif // ELM_CHECKSUM_MD5_H
82 
Definition: CString.h:17
Definition: Output.h:161
Definition: OutStream.h:30
sys::SystemInStream & in
Definition: system_SystemIO.cpp:95
MD5 & operator<<(const String &str)
Definition: MD5.h:51
Definition: MD5.h:34
void put(const void *buffer, t::uint32 length)
Definition: checksum_MD5.cpp:124
t::uint32 D
Definition: MD5.h:69
virtual cstring lastErrorMessage(void)
Definition: checksum_MD5.cpp:408
value_t value(CString name, int value)
Definition: rtti.h:40
MD5(void)
Definition: checksum_MD5.cpp:98
MD5 & operator<<(const CString &str)
Definition: MD5.h:50
sys::SystemOutStream & out
Definition: system_SystemIO.cpp:101
void digest(digest_t tab)
Definition: checksum_MD5.cpp:317
t::uint32 C
Definition: MD5.h:69
io::Output & operator<<(io::Output &out, MD5 &md5)
Definition: MD5.h:77
Definition: String.h:31
virtual int flush(void)
Definition: checksum_MD5.cpp:401
virtual ~MD5(void)
Definition: checksum_MD5.cpp:113
void print(io::Output &out)
Definition: checksum_MD5.cpp:327
MD5 & operator<<(const char *str)
Definition: MD5.h:49
virtual int write(const char *buffer, int size)
Definition: checksum_MD5.cpp:393
t::uint32 A
Definition: MD5.h:69
t::uint32 B
Definition: MD5.h:69
MD5 & operator<<(const T &value)
Definition: MD5.h:52
unsigned char digest_t[16]
Definition: MD5.h:36
Definition: InStream.h:30
uint32_t uint32
Definition: int.h:35