Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
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 
elm::checksum::MD5::print
void print(io::Output &out)
Definition: checksum_MD5.cpp:328
elm::checksum::MD5::operator<<
MD5 & operator<<(const char *str)
Definition: MD5.h:49
elm::t::out
typename type_info< T >::out_t out
Definition: type_info.h:284
elm::checksum::MD5::operator<<
MD5 & operator<<(const String &str)
Definition: MD5.h:51
elm::checksum::MD5::digest_t
unsigned char digest_t[16]
Definition: MD5.h:36
elm::checksum::MD5::flush
virtual int flush(void)
Definition: checksum_MD5.cpp:403
elm::checksum::MD5::C
t::uint32 C
Definition: MD5.h:69
value
elm::CString
Definition: CString.h:17
elm::t::in
typename type_info< T >::in_t in
Definition: type_info.h:283
elm::checksum::operator<<
io::Output & operator<<(io::Output &out, MD5 &md5)
Definition: MD5.h:77
elm::checksum::MD5::operator<<
MD5 & operator<<(const T &value)
Definition: MD5.h:52
elm::checksum::MD5
Definition: MD5.h:34
elm
Definition: adapter.h:26
elm::checksum::MD5::put
void put(const void *buffer, t::uint32 length)
Definition: checksum_MD5.cpp:125
elm::checksum::MD5::lastErrorMessage
virtual cstring lastErrorMessage(void)
Definition: checksum_MD5.cpp:410
elm::checksum::MD5::~MD5
virtual ~MD5(void)
Definition: checksum_MD5.cpp:114
elm::io::OutStream
Definition: OutStream.h:30
elm::checksum::MD5::A
t::uint32 A
Definition: MD5.h:69
elm::checksum::MD5::D
t::uint32 D
Definition: MD5.h:69
elm::checksum::MD5::B
t::uint32 B
Definition: MD5.h:69
elm::t::uint32
unsigned int uint32
Definition: arch.h:31
elm::String
Definition: String.h:30
elm::checksum::MD5::digest
void digest(digest_t tab)
Definition: checksum_MD5.cpp:318
elm::checksum::MD5::operator<<
MD5 & operator<<(const CString &str)
Definition: MD5.h:50
elm::str
string str(const char *s)
Definition: String.h:150
elm::io::Output
Definition: Output.h:179
elm::checksum::MD5::MD5
MD5(void)
Definition: checksum_MD5.cpp:99
elm::checksum::MD5::write
virtual int write(const char *buffer, int size)
Definition: checksum_MD5.cpp:395
elm::io::InStream
Definition: InStream.h:29