summaryrefslogtreecommitdiffstats
path: root/libqpdf/qpdf/MD5.hh
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2008-04-29 14:55:25 +0200
committerJay Berkenbilt <ejb@ql.org>2008-04-29 14:55:25 +0200
commit9a0b88bf7777c153dc46ace22db74ef24d51583a (patch)
treef567ac1cf2bf5071a611eb49323a935b6ac938ff /libqpdf/qpdf/MD5.hh
downloadqpdf-9a0b88bf7777c153dc46ace22db74ef24d51583a.tar.zst
update release date to actual daterelease-qpdf-2.0
git-svn-id: svn+q:///qpdf/trunk@599 71b93d88-0707-0410-a8cf-f5a4172ac649
Diffstat (limited to 'libqpdf/qpdf/MD5.hh')
-rw-r--r--libqpdf/qpdf/MD5.hh73
1 files changed, 73 insertions, 0 deletions
diff --git a/libqpdf/qpdf/MD5.hh b/libqpdf/qpdf/MD5.hh
new file mode 100644
index 00000000..0ae15da9
--- /dev/null
+++ b/libqpdf/qpdf/MD5.hh
@@ -0,0 +1,73 @@
+
+#ifndef __MD5_HH__
+#define __MD5_HH__
+
+#include <string>
+#include <qpdf/QEXC.hh>
+
+class MD5
+{
+ public:
+ typedef unsigned char Digest[16];
+
+ MD5();
+ void reset();
+
+ // encodes string and finalizes
+ void encodeString(char const* input_string);
+
+ // encodes file and finalizes
+ void encodeFile(char const* filename, int up_to_size = -1)
+ throw(QEXC::System);
+
+ // appends string to current md5 object
+ void appendString(char const* input_string);
+
+ // appends arbitrary data to current md5 object
+ void encodeDataIncrementally(char const* input_data, int len);
+
+ // computes a raw digest
+ void digest(Digest);
+
+ // prints the digest to stdout terminated with \r\n (primarily for
+ // testing)
+ void print();
+
+ // returns the digest as a hexademical string
+ std::string unparse();
+
+ // Convenience functions
+ static std::string getDataChecksum(char const* buf, int len);
+ static std::string getFileChecksum(char const* filename, int up_to_size = -1);
+ static bool checkDataChecksum(char const* const checksum,
+ char const* buf, int len);
+ static bool checkFileChecksum(char const* const checksum,
+ char const* filename, int up_to_size = -1);
+
+ private:
+ // POINTER defines a generic pointer type
+ typedef void *POINTER;
+
+ // UINT2 defines a two byte word
+ typedef unsigned short int UINT2;
+
+ // UINT4 defines a four byte word
+ typedef unsigned long int UINT4;
+
+ void init();
+ void update(unsigned char *, unsigned int);
+ void final();
+
+ static void transform(UINT4 [4], unsigned char [64]);
+ static void encode(unsigned char *, UINT4 *, unsigned int);
+ static void decode(UINT4 *, unsigned char *, unsigned int);
+
+ UINT4 state[4]; // state (ABCD)
+ UINT4 count[2]; // number of bits, modulo 2^64 (lsb first)
+ unsigned char buffer[64]; // input buffer
+
+ bool finalized;
+ Digest digest_val;
+};
+
+#endif // __MD5_HH__