summaryrefslogtreecommitdiffabout
path: root/src/eyetil.cc
Unidiff
Diffstat (limited to 'src/eyetil.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--src/eyetil.cc10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/eyetil.cc b/src/eyetil.cc
index 2e6ab7e..11e2fb7 100644
--- a/src/eyetil.cc
+++ b/src/eyetil.cc
@@ -15,20 +15,20 @@
15#endif 15#endif
16 16
17binary_t& binary_t::from_hex(const std::string& h) { 17binary_t& binary_t::from_hex(const std::string& h) {
18 std::string::size_type hs = h.length(); 18 std::string::size_type hs = h.length();
19 if(hs&1) 19 if(hs&1)
20 throw std::runtime_error("odd number of characters in hexadecimal number"); 20 throw std::runtime_error("odd number of characters in hexadecimal number");
21 int rvs = hs>>1; 21 size_t rvs = hs>>1;
22 resize(rvs); 22 resize(rvs);
23 const unsigned char *hp = (const unsigned char*)h.data(); 23 const unsigned char *hp = (const unsigned char*)h.data();
24 iterator oi=begin(); 24 iterator oi=begin();
25 char t[3] = { 0,0,0 }; 25 char t[3] = { 0,0,0 };
26 for(int i=0;i<rvs;++i) { 26 for(size_t i=0;i<rvs;++i) {
27 t[0]=*(hp++); t[1]=*(hp++); 27 t[0]=*(hp++); t[1]=*(hp++);
28 *(oi++) = strtol(t,0,16); 28 *(oi++) = static_cast<binary_t::value_type>(0xff&strtol(t,0,16));
29 } 29 }
30 return *this; 30 return *this;
31} 31}
32 32
33binary_t& binary_t::from_data(const void *d,size_t s) { 33binary_t& binary_t::from_data(const void *d,size_t s) {
34 resize(s); 34 resize(s);
@@ -51,13 +51,13 @@ binary_t& binary_t::make_nonce() {
51 51
52std::string binary_t::hex() const { 52std::string binary_t::hex() const {
53 std::string rv; 53 std::string rv;
54 rv.reserve((size()<<1)+1); 54 rv.reserve((size()<<1)+1);
55 char t[3] = {0,0,0}; 55 char t[3] = {0,0,0};
56 for(const_iterator i=begin(),ie=end();i!=ie;++i) { 56 for(const_iterator i=begin(),ie=end();i!=ie;++i) {
57 int rc = snprintf(t,sizeof(t),"%02x",*i); 57 size_t rc = snprintf(t,sizeof(t),"%02x",*i);
58 assert(rc<sizeof(t)); 58 assert(rc<sizeof(t));
59 rv += t; 59 rv += t;
60 } 60 }
61 return rv; 61 return rv;
62} 62}
63 63
@@ -155,13 +155,13 @@ struct block512_t {
155 enum { words = 512 / sizeof(uint16_t) }; 155 enum { words = 512 / sizeof(uint16_t) };
156 uint16_t data[words]; 156 uint16_t data[words];
157 157
158 static uint16_t tcpcksum(block512_t& data) { 158 static uint16_t tcpcksum(block512_t& data) {
159 uint32_t sum = std::accumulate(data.data,data.data+words,0); 159 uint32_t sum = std::accumulate(data.data,data.data+words,0);
160 while(uint32_t hw = sum>>16) sum = (sum&0xffff)+hw; 160 while(uint32_t hw = sum>>16) sum = (sum&0xffff)+hw;
161 return ~sum; 161 return 0xffff&~sum;
162 } 162 }
163 163
164}; 164};
165#pragma pack() 165#pragma pack()
166 166
167binary_t integrity_digest(const void *ptr,size_t size,const std::string& ukey) { 167binary_t integrity_digest(const void *ptr,size_t size,const std::string& ukey) {