aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_MD5.cc
blob: 0a2711b8e20e88b54852077dd9d9a59afc7287f9 (plain) (blame)
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

#include <qpdf/Pl_MD5.hh>

#include <qpdf/QEXC.hh>

Pl_MD5::Pl_MD5(char const* identifier, Pipeline* next) :
    Pipeline(identifier, next),
    in_progress(false)
{
}

Pl_MD5::~Pl_MD5()
{
}

void
Pl_MD5::write(unsigned char* buf, int len)
{
    if (! this->in_progress)
    {
	this->md5.reset();
	this->in_progress = true;
    }
    this->md5.encodeDataIncrementally((char*) buf, len);
    this->getNext()->write(buf, len);
}

void
Pl_MD5::finish()
{
    this->getNext()->finish();
    this->in_progress = false;
}

std::string
Pl_MD5::getHexDigest()
{
    if (this->in_progress)
    {
	throw QEXC::General("digest requested for in-progress MD5 Pipeline");
    }
    return this->md5.unparse();
}