libsidplayfp 2.15.0
sidmd5.h
1/*
2 * This file is part of libsidplayfp, a SID player engine.
3 *
4 * Copyright 2012-2015 Leandro Nini <drfiemost@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21#ifndef SIDMD5_H
22#define SIDMD5_H
23
24#include <string>
25#include <sstream>
26#include <iomanip>
27#include <memory>
28
29#include "utils/md5Factory.h"
30#include "utils/iMd5.h"
31
32#include "sidcxx11.h"
33
34namespace libsidplayfp
35{
36
41class sidmd5
42{
43private:
44 std::unique_ptr<iMd5> m_md5;
45
46public:
51 m_md5(md5Factory::get())
52 {}
53
57 void append(const void* data, int nbytes) { m_md5->append(data, nbytes); }
58
62 void finish() { m_md5->finish(); }
63
67 void reset() { m_md5->reset(); }
68
72 std::string getDigest()
73 {
74 const unsigned char* digest = m_md5->getDigest();
75 if (digest == nullptr)
76 return std::string();
77
78 // Construct fingerprint.
79 std::ostringstream ss;
80 ss.fill('0');
81 ss.flags(std::ios::hex);
82
83 for (int di = 0; di < 16; ++di)
84 {
85 ss << std::setw(2) << static_cast<int>(digest[di]);
86 }
87
88 return ss.str();
89 }
90};
91
92}
93
94#endif
Definition sidmd5.h:42
void append(const void *data, int nbytes)
Definition sidmd5.h:57
void reset()
Definition sidmd5.h:67
sidmd5()
Definition sidmd5.h:50
std::string getDigest()
Definition sidmd5.h:72
void finish()
Definition sidmd5.h:62