- changed Sha1CheckSum from hand-made class to instance of t_GenericIdType<> (should be backward compatible)

- updated ft/, p3msgservice and p3chatservice accordingly
- added a new class for Sha1Sum in t_GeneridIdType<>, and an additional template argument to make ids of identical size 
	incompatible.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7082 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-02-01 19:10:45 +00:00
parent 10bf083ca3
commit 235280399f
19 changed files with 67 additions and 441 deletions

View file

@ -217,7 +217,7 @@ bool setRawUFloat32(void *data,uint32_t size,uint32_t *offset,float f)
bool getRawSha1(void *data,uint32_t size,uint32_t *offset,Sha1CheckSum& cs)
{
uint32_t len = 20 ; // SHA1 length in bytes
uint32_t len = Sha1CheckSum::SIZE_IN_BYTES ; // SHA1 length in bytes = 20
/* check there is space for string */
if (size < *offset + len)
@ -227,18 +227,15 @@ bool getRawSha1(void *data,uint32_t size,uint32_t *offset,Sha1CheckSum& cs)
}
bool ok = true ;
ok = ok && getRawUInt32(data, size, offset, &cs.fourbytes[0]) ;
ok = ok && getRawUInt32(data, size, offset, &cs.fourbytes[1]) ;
ok = ok && getRawUInt32(data, size, offset, &cs.fourbytes[2]) ;
ok = ok && getRawUInt32(data, size, offset, &cs.fourbytes[3]) ;
ok = ok && getRawUInt32(data, size, offset, &cs.fourbytes[4]) ;
cs = Sha1CheckSum(&((uint8_t*)data)[*offset]) ;
*offset += Sha1CheckSum::SIZE_IN_BYTES ;
return ok ;
}
bool setRawSha1(void *data,uint32_t size,uint32_t *offset,const Sha1CheckSum& cs)
{
uint32_t len = 20 ; // SHA1 length in bytes
uint32_t len = Sha1CheckSum::SIZE_IN_BYTES ; // SHA1 length in bytes
if (size < *offset + len)
{
@ -248,12 +245,9 @@ bool setRawSha1(void *data,uint32_t size,uint32_t *offset,const Sha1CheckSum& cs
bool ok = true ;
/* pack it in */
ok = ok && setRawUInt32(data, size, offset, cs.fourbytes[0]);
ok = ok && setRawUInt32(data, size, offset, cs.fourbytes[1]);
ok = ok && setRawUInt32(data, size, offset, cs.fourbytes[2]);
ok = ok && setRawUInt32(data, size, offset, cs.fourbytes[3]);
ok = ok && setRawUInt32(data, size, offset, cs.fourbytes[4]);
memcpy((void *) &(((uint8_t *) data)[*offset]), cs.toByteArray(), Sha1CheckSum::SIZE_IN_BYTES) ;
offset += Sha1CheckSum::SIZE_IN_BYTES ;
return true ;
}
bool getRawSSLId(void *data,uint32_t size,uint32_t *offset,SSLIdType& cs)

View file

@ -48,8 +48,6 @@
*
******************************************************************/
class Sha1CheckSum ;
bool getRawUInt8(void *data, uint32_t size, uint32_t *offset, uint8_t *out);
bool setRawUInt8(void *data, uint32_t size, uint32_t *offset, uint8_t in);

View file

@ -308,11 +308,14 @@ bool RsFileTransferSingleChunkCrcItem::serialise(void *data, uint32_t& pktsize)
/* add mandatory parts first */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, hash);
ok &= setRawUInt32(data, tlvsize, &offset, chunk_number) ;
ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[0]) ;
ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[1]) ;
ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[2]) ;
ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[3]) ;
ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[4]) ;
setRawSha1(data,tlvsize,&offset,check_sum) ;
//ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[0]) ;
//ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[1]) ;
//ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[2]) ;
//ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[3]) ;
//ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[4]) ;
if (offset != tlvsize)
{
@ -776,11 +779,7 @@ RsFileTransferItem *RsFileTransferSerialiser::deserialise_RsFileTransferSingleCh
offset += 8;
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VALUE, item->hash); // file hash
ok &= getRawUInt32(data, rssize, &offset, &(item->chunk_number));
ok &= getRawUInt32(data, rssize, &offset, &(item->check_sum.fourbytes[0]));
ok &= getRawUInt32(data, rssize, &offset, &(item->check_sum.fourbytes[1]));
ok &= getRawUInt32(data, rssize, &offset, &(item->check_sum.fourbytes[2]));
ok &= getRawUInt32(data, rssize, &offset, &(item->check_sum.fourbytes[3]));
ok &= getRawUInt32(data, rssize, &offset, &(item->check_sum.fourbytes[4]));
getRawSha1(data,rssize,&offset,item->check_sum) ;
if (offset != rssize)
{