Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 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. |
| 13 | * |
| 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
Chaoyi Bian | 3e1eb16 | 2012-04-03 16:59:32 -0700 | [diff] [blame] | 19 | * Chaoyi Bian <bcy@pku.edu.cn> |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 21 | */ |
| 22 | |
| 23 | #include "sync-digest.h" |
| 24 | #include <string.h> |
| 25 | |
Alexander Afanasyev | d94542d | 2012-03-05 08:41:46 -0800 | [diff] [blame] | 26 | #include <boost/assert.hpp> |
Alexander Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 27 | #include <boost/throw_exception.hpp> |
| 28 | typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str; |
| 29 | typedef boost::error_info<struct tag_errmsg, int> errmsg_info_int; |
Alexander Afanasyev | df718f5 | 2012-03-02 00:23:04 -0800 | [diff] [blame] | 30 | |
Alexander Afanasyev | b080dbf | 2012-03-05 10:25:22 -0800 | [diff] [blame] | 31 | // for printing, may be disabled in optimized build |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 32 | |
| 33 | // #ifdef DIGEST_BASE64 |
| 34 | // #include <boost/archive/iterators/base64_from_binary.hpp> |
| 35 | // #include <boost/archive/iterators/binary_from_base64.hpp> |
| 36 | // #endif |
| 37 | |
Alexander Afanasyev | b080dbf | 2012-03-05 10:25:22 -0800 | [diff] [blame] | 38 | #include <boost/archive/iterators/transform_width.hpp> |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 39 | #include <boost/iterator/transform_iterator.hpp> |
| 40 | #include <boost/archive/iterators/dataflow_exception.hpp> |
Alexander Afanasyev | b080dbf | 2012-03-05 10:25:22 -0800 | [diff] [blame] | 41 | |
Alexander Afanasyev | df718f5 | 2012-03-02 00:23:04 -0800 | [diff] [blame] | 42 | using namespace boost; |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 43 | using namespace boost::archive::iterators; |
Alexander Afanasyev | b080dbf | 2012-03-05 10:25:22 -0800 | [diff] [blame] | 44 | using namespace std; |
| 45 | |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 46 | // Other options: VP_md2, EVP_md5, EVP_sha, EVP_sha1, EVP_sha256, EVP_dss, EVP_dss1, EVP_mdc2, EVP_ripemd160 |
Zhenkai Zhu | cbdf379 | 2012-04-09 14:10:30 -0700 | [diff] [blame] | 47 | #define HASH_FUNCTION EVP_sha256 |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 48 | #define HASH_FUNCTION_LEN 32 |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 49 | |
| 50 | |
| 51 | // #ifndef DIGEST_BASE64 |
| 52 | |
| 53 | template<class CharType> |
| 54 | struct hex_from_4_bit |
| 55 | { |
| 56 | typedef CharType result_type; |
| 57 | CharType operator () (CharType ch) const |
| 58 | { |
| 59 | const char *lookup_table = "0123456789abcdef"; |
| 60 | // cout << "New character: " << (int) ch << " (" << (char) ch << ")" << "\n"; |
| 61 | BOOST_ASSERT (ch < 16); |
| 62 | return lookup_table[static_cast<size_t>(ch)]; |
| 63 | } |
| 64 | }; |
| 65 | |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 66 | typedef transform_iterator<hex_from_4_bit<std::vector<uint8_t>::const_iterator::value_type>, |
| 67 | transform_width<std::vector<uint8_t>::const_iterator, 4, 8, std::vector<uint8_t>::const_iterator::value_type> > string_from_binary; |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 68 | |
| 69 | |
| 70 | template<class CharType> |
| 71 | struct hex_to_4_bit |
| 72 | { |
| 73 | typedef CharType result_type; |
| 74 | CharType operator () (CharType ch) const |
| 75 | { |
| 76 | const signed char lookup_table [] = { |
| 77 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, |
| 78 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, |
| 79 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, |
| 80 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, |
| 81 | -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, |
| 82 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, |
| 83 | -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, |
| 84 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 |
| 85 | }; |
| 86 | |
| 87 | // cout << "New character: " << hex << (int) ch << " (" << (char) ch << ")" << "\n"; |
| 88 | signed char value = -1; |
| 89 | if ((unsigned)ch < 128) |
| 90 | value = lookup_table [(unsigned)ch]; |
| 91 | if (value == -1) |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 92 | BOOST_THROW_EXCEPTION (Sync::Error::DigestCalculationError () << errmsg_info_int ((int)ch)); |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 93 | |
| 94 | return value; |
| 95 | } |
| 96 | }; |
| 97 | |
| 98 | typedef transform_width<transform_iterator<hex_to_4_bit<string::const_iterator::value_type>, string::const_iterator>, 8, 4> string_to_binary; |
| 99 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 100 | namespace Sync { |
| 101 | |
| 102 | Digest::Digest () |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 103 | { |
| 104 | m_context = EVP_MD_CTX_create (); |
| 105 | |
Alexander Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 106 | reset (); |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | Digest::~Digest () |
| 110 | { |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 111 | EVP_MD_CTX_destroy (m_context); |
| 112 | } |
| 113 | |
Alexander Afanasyev | b71beab | 2012-03-05 21:13:49 -0800 | [diff] [blame] | 114 | bool |
| 115 | Digest::empty () const |
| 116 | { |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 117 | return m_buffer.empty (); |
Alexander Afanasyev | b71beab | 2012-03-05 21:13:49 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Alexander Afanasyev | dd0eba7 | 2012-03-13 13:57:10 -0700 | [diff] [blame] | 120 | bool |
Alexander Afanasyev | 763855a | 2012-03-13 14:17:37 -0700 | [diff] [blame] | 121 | Digest::isZero () const |
Alexander Afanasyev | dd0eba7 | 2012-03-13 13:57:10 -0700 | [diff] [blame] | 122 | { |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 123 | if (m_buffer.empty ()) |
Alexander Afanasyev | dd0eba7 | 2012-03-13 13:57:10 -0700 | [diff] [blame] | 124 | BOOST_THROW_EXCEPTION (Error::DigestCalculationError () |
| 125 | << errmsg_info_str ("Digest has not been yet finalized")); |
| 126 | |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 127 | return (m_buffer.size () == 1 && m_buffer[0] == 0); |
Alexander Afanasyev | dd0eba7 | 2012-03-13 13:57:10 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 131 | void |
Alexander Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 132 | Digest::reset () |
| 133 | { |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 134 | m_buffer.clear (); |
Alexander Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 135 | |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 136 | int ok = EVP_DigestInit_ex (m_context, HASH_FUNCTION (), 0); |
Alexander Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 137 | if (!ok) |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 138 | BOOST_THROW_EXCEPTION (Error::DigestCalculationError () |
Alexander Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 139 | << errmsg_info_str ("EVP_DigestInit_ex returned error") |
| 140 | << errmsg_info_int (ok)); |
Alexander Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
| 144 | void |
| 145 | Digest::finalize () |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 146 | { |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 147 | if (!m_buffer.empty ()) return; |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 148 | |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 149 | m_buffer.resize (HASH_FUNCTION_LEN); |
| 150 | |
| 151 | unsigned int tmp; |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 152 | int ok = EVP_DigestFinal_ex (m_context, |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 153 | &m_buffer[0], &tmp); |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 154 | if (!ok) |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 155 | BOOST_THROW_EXCEPTION (Error::DigestCalculationError () |
Alexander Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 156 | << errmsg_info_str ("EVP_DigestFinal_ex returned error") |
| 157 | << errmsg_info_int (ok)); |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 158 | } |
Alexander Afanasyev | dd0eba7 | 2012-03-13 13:57:10 -0700 | [diff] [blame] | 159 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 160 | std::size_t |
Alexander Afanasyev | a585803 | 2012-03-09 15:55:10 -0800 | [diff] [blame] | 161 | Digest::getHash () const |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 162 | { |
Alexander Afanasyev | 763855a | 2012-03-13 14:17:37 -0700 | [diff] [blame] | 163 | if (isZero ()) return 0; |
Alexander Afanasyev | f07ab35 | 2012-03-13 12:57:46 -0700 | [diff] [blame] | 164 | |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 165 | if (sizeof (std::size_t) > m_buffer.size ()) |
Alexander Afanasyev | f07ab35 | 2012-03-13 12:57:46 -0700 | [diff] [blame] | 166 | { |
| 167 | BOOST_THROW_EXCEPTION (Error::DigestCalculationError () |
| 168 | << errmsg_info_str ("Hash is not zero and length is less than size_t") |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 169 | << errmsg_info_int (m_buffer.size ())); |
Alexander Afanasyev | f07ab35 | 2012-03-13 12:57:46 -0700 | [diff] [blame] | 170 | } |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 171 | |
| 172 | // just getting first sizeof(std::size_t) bytes |
| 173 | // not ideal, but should work pretty well |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 174 | return *(reinterpret_cast<const std::size_t*> (&m_buffer[0])); |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | bool |
Alexander Afanasyev | b71beab | 2012-03-05 21:13:49 -0800 | [diff] [blame] | 178 | Digest::operator == (const Digest &digest) const |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 179 | { |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 180 | if (m_buffer.empty ()) |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 181 | BOOST_THROW_EXCEPTION (Error::DigestCalculationError () |
Alexander Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 182 | << errmsg_info_str ("Digest1 is empty")); |
| 183 | |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 184 | if (digest.m_buffer.empty ()) |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 185 | BOOST_THROW_EXCEPTION (Error::DigestCalculationError () |
Alexander Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 186 | << errmsg_info_str ("Digest2 is empty")); |
| 187 | |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 188 | return m_buffer == digest.m_buffer; |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | |
Alexander Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 192 | void |
| 193 | Digest::update (const uint8_t *buffer, size_t size) |
| 194 | { |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 195 | // cout << "Update: " << (void*)buffer << " / size: " << size << "\n"; |
| 196 | |
Alexander Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 197 | // cannot update Digest when it has been finalized |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 198 | if (!m_buffer.empty ()) |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 199 | BOOST_THROW_EXCEPTION (Error::DigestCalculationError () |
Alexander Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 200 | << errmsg_info_str ("Digest has been already finalized")); |
Alexander Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 201 | |
| 202 | bool ok = EVP_DigestUpdate (m_context, buffer, size); |
| 203 | if (!ok) |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 204 | BOOST_THROW_EXCEPTION (Error::DigestCalculationError () |
Alexander Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 205 | << errmsg_info_str ("EVP_DigestUpdate returned error") |
| 206 | << errmsg_info_int (ok)); |
Alexander Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | |
Alexander Afanasyev | df718f5 | 2012-03-02 00:23:04 -0800 | [diff] [blame] | 210 | Digest & |
| 211 | Digest::operator << (const Digest &src) |
| 212 | { |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 213 | if (src.m_buffer.empty ()) |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 214 | BOOST_THROW_EXCEPTION (Error::DigestCalculationError () |
Alexander Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 215 | << errmsg_info_str ("Digest has not been yet finalized")); |
Alexander Afanasyev | df718f5 | 2012-03-02 00:23:04 -0800 | [diff] [blame] | 216 | |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 217 | update (&src.m_buffer[0], src.m_buffer.size ()); |
Alexander Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 218 | |
Alexander Afanasyev | df718f5 | 2012-03-02 00:23:04 -0800 | [diff] [blame] | 219 | return *this; |
| 220 | } |
| 221 | |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 222 | std::ostream & |
| 223 | operator << (std::ostream &os, const Digest &digest) |
Alexander Afanasyev | b080dbf | 2012-03-05 10:25:22 -0800 | [diff] [blame] | 224 | { |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 225 | BOOST_ASSERT (!digest.m_buffer.empty ()); |
Alexander Afanasyev | b080dbf | 2012-03-05 10:25:22 -0800 | [diff] [blame] | 226 | |
| 227 | ostreambuf_iterator<char> out_it (os); // ostream iterator |
| 228 | // need to encode to base64 |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 229 | copy (string_from_binary (digest.m_buffer.begin ()), |
| 230 | string_from_binary (digest.m_buffer.end ()), |
Alexander Afanasyev | b080dbf | 2012-03-05 10:25:22 -0800 | [diff] [blame] | 231 | out_it); |
| 232 | |
| 233 | return os; |
| 234 | } |
| 235 | |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 236 | std::istream & |
| 237 | operator >> (std::istream &is, Digest &digest) |
Alexander Afanasyev | b080dbf | 2012-03-05 10:25:22 -0800 | [diff] [blame] | 238 | { |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 239 | string str; |
| 240 | is >> str; // read string first |
Alexander Afanasyev | b71beab | 2012-03-05 21:13:49 -0800 | [diff] [blame] | 241 | |
| 242 | if (str.size () == 0) |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 243 | BOOST_THROW_EXCEPTION (Error::DigestCalculationError () |
Alexander Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 244 | << errmsg_info_str ("Input is empty")); |
Alexander Afanasyev | b71beab | 2012-03-05 21:13:49 -0800 | [diff] [blame] | 245 | |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 246 | // uint8_t padding = (3 - str.size () % 3) % 3; |
| 247 | // for (uint8_t i = 0; i < padding; i++) str.push_back ('='); |
| 248 | |
| 249 | // only empty digest object can be used for reading |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 250 | if (!digest.m_buffer.empty ()) |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 251 | BOOST_THROW_EXCEPTION (Error::DigestCalculationError () |
Alexander Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 252 | << errmsg_info_str ("Digest has been already finalized")); |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 253 | |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame^] | 254 | digest.m_buffer.clear (); |
| 255 | |
| 256 | copy (string_to_binary (str.begin ()), |
| 257 | string_to_binary (str.end ()), |
| 258 | std::back_inserter (digest.m_buffer)); |
Alexander Afanasyev | 2fc2d67 | 2012-03-05 16:57:39 -0800 | [diff] [blame] | 259 | |
| 260 | return is; |
Alexander Afanasyev | b080dbf | 2012-03-05 10:25:22 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 264 | } // Sync |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 265 | |