From 368a429846d3e4149e4fdf220a66b9ff71db044f Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 17 Aug 2016 09:40:16 +0200 Subject: [PATCH] fixed read_125Size and write_125Size according to RFC4880 --- libretroshare/src/pgp/pgpkeyutil.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libretroshare/src/pgp/pgpkeyutil.cc b/libretroshare/src/pgp/pgpkeyutil.cc index aedee9131..a019c95c8 100644 --- a/libretroshare/src/pgp/pgpkeyutil.cc +++ b/libretroshare/src/pgp/pgpkeyutil.cc @@ -248,16 +248,16 @@ uint64_t PGPKeyParser::read_KeyID(unsigned char *& data) uint32_t PGPKeyParser::write_125Size(unsigned char *data,uint32_t size) { - if(size < 0xC0)//192 To know if size is coded with One Char < 0xC0 + if(size < 192)//192 To know if size is coded with One Char < 0xC0 { data[0] = size ; return 1; } - if(size < 0x20C0)//8384 To know if size is coded with Two Chars < 0xE0 + if(size < 8384)//8384 To know if size is coded with Two Chars < 0xE0. See RFC4880 { - data[0] = (size >> 8) + 0xC0 ; - data[1] = (size & 0xFF) - 0xC0 ;//Warning data[1] could be "negative", recode it using 8bits type + data[1] = (size - 192) & 0xFF ;//Warning data[1] could be "negative", recode it using 8bits type + data[0] = ((size - 192 - data[1]) >> 8) + 192 ; return 2 ; } @@ -276,14 +276,14 @@ uint32_t PGPKeyParser::read_125Size(unsigned char *& data) uint8_t b1 = *data ; ++data ; - if(b1 < 0xC0)//192 Size is coded with One Char + if(b1 < 192) //192 Size is coded with One Char. See RFC4880 return b1 ; uint8_t b2 = *data ; ++data ; - if(b1 < 0xE0)//224 = 0xC0+0x20 Size is coded with Two Chars - return ((b1-0xC0) << 8) + uint8_t(b2 + 0xC0) ; //Use uint8_t because b2 could be "negative" as 0xC0 was added to it. + if(b1 < 224)//224 = 0xC0+0x20 Size is coded with Two Chars + return ((b1-192) << 8) + b2 + 192 ; // see RFC4880 if(b1 != 0xFF)// Else Coded with 4 Chars but first == 0xFF throw std::runtime_error("GPG parsing error") ;