summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/MD5.cpp
blob: d11ee1724c84bec94155dfe7573c645436ec6dcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// **********************************************************************
//
// Copyright (c) 2003-present ZeroC, Inc. All rights reserved.
//
// **********************************************************************

#include <Slice/MD5.h>
#include <Slice/MD5I.h>
#include <cstring>

using namespace std;

//
// This class is a C++ wrapper around the C implementation contained in
// MD5I.cpp, obtained from http://sourceforge.net/projects/libmd5-rfc/.
//

Slice::MD5::MD5()
{
    _state = new md5_state_s;
    md5_init(_state);
}

Slice::MD5::MD5(const unsigned char* data, int n)
{
    _state = new md5_state_s;
    md5_init(_state);
    update(data, n);
    finish();
}

Slice::MD5::~MD5()
{
    delete _state;
}

void
Slice::MD5::update(const unsigned char* data, int n)
{
    md5_append(_state, data, n);
}

void
Slice::MD5::finish()
{
    md5_finish(_state, _digest);
    md5_init(_state);
}

void
Slice::MD5::getDigest(unsigned char* digest) const
{
    memcpy(digest, _digest, sizeof(unsigned char) * 16);
}