libsidplayfp 1.0.3
sidmd5.h
00001 /*
00002  * This file is part of libsidplayfp, a SID player engine.
00003  *
00004  * Copyright 2012-2013 Leandro Nini <drfiemost@users.sourceforge.net>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  */
00020 
00021 #ifndef SIDMD5_H
00022 #define SIDMD5_H
00023 
00024 #include <string>
00025 #include <sstream>
00026 #include <iomanip>
00027 
00028 #include "utils/MD5/MD5.h"
00029 
00034 class sidmd5
00035 {
00036 private:
00037     MD5 m_md5;
00038 
00039 public:
00041     void append(const void* data, int nbytes) { m_md5.append(data, nbytes); }
00042 
00044     void finish() { m_md5.finish(); }
00045 
00047     void reset() { m_md5.reset(); }
00048 
00050     std::string getDigest()
00051     {
00052         // Construct fingerprint.
00053         std::ostringstream ss;
00054         ss.fill('0');
00055         ss.flags(std::ios::hex);
00056 
00057         for (int di = 0; di < 16; ++di)
00058         {
00059             ss << std::setw(2) << (int) m_md5.getDigest()[di];
00060         }
00061 
00062         return ss.str();
00063     }
00064 };
00065     
00066 #endif