From d61c8ae013494dfddf3bb7401ecaadbda97b7e0b Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 2 Dec 2011 16:23:46 -0800 Subject: [PATCH] Add static has function to save a copy. Use <0 for 'whole object', not 0. --- Serializer.cpp | 13 +++++++++---- Serializer.h | 7 ++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Serializer.cpp b/Serializer.cpp index 9dea65629..68f4cef54 100644 --- a/Serializer.cpp +++ b/Serializer.cpp @@ -125,22 +125,27 @@ std::vector Serializer::getRaw(int offset, int length) const uint160 Serializer::getRIPEMD160(int size) const { uint160 ret; - if((size==0)||(size>mData.size())) size=mData.size(); + if((size<0)||(size>mData.size())) size=mData.size(); RIPEMD160(&(mData.front()), size, (unsigned char *) &ret); } uint256 Serializer::getSHA256(int size) const { uint256 ret; - if((size==0)||(size>mData.size())) size=mData.size(); + if((size<0)||(size>mData.size())) size=mData.size(); SHA256(&(mData.front()), size, (unsigned char *) &ret); } uint256 Serializer::getSHA512Half(int size) const +{ + return getSHA512Half(mData, size); +} + +uint256 Serializer::getSHA512Half(const std::vector& data, int size) { char buf[64]; - if((size==0)||(size>mData.size())) size=mData.size(); - SHA512(&(mData.front()), size, (unsigned char *) buf); + if((size<0)||(size>data.size())) size=data.size(); + SHA512(&(data.front()), size, (unsigned char *) buf); return * (uint256 *) buf; } diff --git a/Serializer.h b/Serializer.h index 0d5688d7e..bcf62dfe8 100644 --- a/Serializer.h +++ b/Serializer.h @@ -39,9 +39,10 @@ class Serializer std::vector getRaw(int offset, int length) const; // hash functions - uint160 getRIPEMD160(int size=0) const; - uint256 getSHA256(int size=0) const; - uint256 getSHA512Half(int size=0) const; + uint160 getRIPEMD160(int size=-1) const; + uint256 getSHA256(int size=-1) const; + uint256 getSHA512Half(int size=-1) const; + static uint256 getSHA512Half(const std::vector& data, int size=-1); // totality functions int getLength() const { return mData.size(); }