diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-06-03 14:30:42 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-06-03 14:30:42 +0100 |
| commit | c5b3d91fab31fde4c21e1cc5bb5adb1d6d26fcca (patch) | |
| tree | a88349c4c4e6e8304d92161529a5ca3dc5271a7b /src/lib/md5_digester.cc | |
| parent | fd26b3243015824bebe8ec41c6b4a0d81748e81a (diff) | |
Include audio mapping in the digest used to distinguish different
audio analyses so that the analyses are re-computed when the mapping
changes.
Reported-by: Matthias Damm
Diffstat (limited to 'src/lib/md5_digester.cc')
| -rw-r--r-- | src/lib/md5_digester.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/lib/md5_digester.cc b/src/lib/md5_digester.cc new file mode 100644 index 000000000..1244209bd --- /dev/null +++ b/src/lib/md5_digester.cc @@ -0,0 +1,63 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include <iomanip> +#include <sstream> +#include <openssl/md5.h> +#include "md5_digester.h" + +using std::string; +using std::stringstream; +using std::hex; +using std::setfill; +using std::setw; + +MD5Digester::MD5Digester () +{ + MD5_Init (&_context); +} + +MD5Digester::~MD5Digester () +{ + get (); +} + +void +MD5Digester::add (void const * data, size_t size) +{ + MD5_Update (&_context, data, size); +} + +string +MD5Digester::get () const +{ + if (!_digest) { + unsigned char digest[MD5_DIGEST_LENGTH]; + MD5_Final (digest, &_context); + + stringstream s; + for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) { + s << hex << setfill('0') << setw(2) << ((int) digest[i]); + } + + _digest = s.str (); + } + + return _digest.get (); +} |
