]>
cygwin.com Git - cygwin-apps/setup.git/blob - csu_util/MD5Sum.cc
2 * Copyright (c) 2004 Max Bowsher
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.
9 * A copy of the GNU General Public License can be found at
12 * Written by Max Bowsher
18 namespace libmd5_rfc
{
19 #include "../libmd5-rfc/md5.h"
22 MD5Sum::MD5Sum(const MD5Sum
& source
)
28 MD5Sum::operator= (const MD5Sum
& source
)
31 memcpy(digest
, source
.digest
, sizeof(digest
));
33 if (source
.internalData
)
35 internalData
= new libmd5_rfc::md5_state_s
;
36 *internalData
= *(source
.internalData
);
43 if (internalData
) delete internalData
;
47 MD5Sum::set(const unsigned char digest
[16])
49 memcpy(this->digest
, digest
, sizeof(this->digest
));
51 if (internalData
) delete internalData
;
57 if (internalData
) delete internalData
;
58 internalData
= new libmd5_rfc::md5_state_s
;
60 libmd5_rfc::md5_init(internalData
);
64 MD5Sum::append(const unsigned char* data
, int nbytes
)
67 throw new std::logic_error("MD5Sum::append() called on an object not "
68 "in the 'Accumulating' state");
69 libmd5_rfc::md5_append(internalData
, data
, nbytes
);
76 throw new std::logic_error("MD5Sum::finish() called on an object not "
77 "in the 'Accumulating' state");
78 libmd5_rfc::md5_finish(internalData
, digest
);
80 delete internalData
; internalData
= 0;
83 MD5Sum::operator std::string() const
88 for (int i
= 0; i
< 16; ++i
)
94 hexdigest
[hexdigit
] = (tmp
< 10) ? (tmp
+ '0') : (tmp
+ 'a' - 10);
96 tmp
= digest
[i
] & 0x0f;
97 hexdigest
[hexdigit
+ 1] = (tmp
< 10) ? (tmp
+ '0') : (tmp
+ 'a' - 10);
100 return std::string(hexdigest
);
104 MD5Sum::operator == (const MD5Sum
& other
) const
106 if (state
!= Set
|| other
.state
!= Set
)
107 throw new std::logic_error("MD5Sum comparison attempted on operands not "
108 "in the 'Set' state");
109 return (memcmp(digest
, other
.digest
, sizeof(digest
)) == 0);
This page took 0.038636 seconds and 5 git commands to generate.