]> cygwin.com Git - cygwin-apps/setup.git/blob - csu_util/MD5Sum.h
2004-11-22 Max Bowsher <maxb@ukf.net>
[cygwin-apps/setup.git] / csu_util / MD5Sum.h
1 /*
2 * Copyright (c) 2004 Max Bowsher
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by Max Bowsher
13 */
14
15 #ifndef SETUP_MD5SUM_H
16 #define SETUP_MD5SUM_H
17
18 /*
19 * A C++ wrapper for the libmd5-rfc library, which additionally provides
20 * storage and comparison of MD5 checksums.
21 *
22 * An MD5Sum may be given a value in one of two ways:
23 * 1. md5->set()
24 * 2. md5->begin(); md5->append(); md5->finish();
25 *
26 * Once it has a value, md5->isSet() will return true,
27 */
28
29 #include <string>
30
31 namespace libmd5_rfc {
32 struct md5_state_s;
33 };
34
35 class MD5Sum
36 {
37 public:
38 MD5Sum() : state(Empty), internalData(0) {};
39 MD5Sum(const MD5Sum& source);
40 MD5Sum& operator= (const MD5Sum& source);
41 ~MD5Sum();
42
43 void set(const unsigned char digest[16]);
44 void begin();
45 void append(const unsigned char* data, int nbytes);
46 void finish();
47
48 bool isSet() const { return (state == Set); };
49 operator std::string() const;
50 std::string str() const { return (std::string)(*this); };
51 bool operator == (const MD5Sum& other) const;
52 bool operator != (const MD5Sum& other) const { return !(*this == other); };
53
54 private:
55 enum { Empty, Accumulating, Set } state;
56 unsigned char digest[16];
57 libmd5_rfc::md5_state_s* internalData;
58 };
59
60 #endif /* SETUP_MD5SUM_H */
This page took 0.040832 seconds and 5 git commands to generate.