2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 using std::stringstream;
35 : _value (new uint8_t[ASDCP::KeyLen])
38 rng.FillRandom (_value, ASDCP::KeyLen);
41 Key::Key (uint8_t const * value)
42 : _value (new uint8_t[ASDCP::KeyLen])
44 memcpy (_value, value, ASDCP::KeyLen);
47 Key::Key (string value)
48 : _value (new uint8_t[ASDCP::KeyLen])
51 Kumu::hex2bin (value.c_str(), _value, ASDCP::KeyLen, &length);
54 Key::Key (Key const & other)
55 : _value (new uint8_t[ASDCP::KeyLen])
57 memcpy (_value, other._value, ASDCP::KeyLen);
66 Key::operator= (Key const & other)
72 memcpy (_value, other._value, ASDCP::KeyLen);
81 for (unsigned int i = 0; i < ASDCP::KeyLen; ++i) {
82 g << setw(2) << setfill('0') << std::hex << static_cast<int> (_value[i]);
89 dcp::operator== (Key const & a, Key const & b)
91 return memcmp (a.value(), b.value(), ASDCP::KeyLen) == 0;
95 dcp::operator!= (Key const & a, Key const & b)