From 13355a7efefb5e2afb9e5be0c9617f2904b2af5c Mon Sep 17 00:00:00 2001 From: electron128 Date: Thu, 18 Jun 2015 13:45:08 +0000 Subject: [PATCH] changed Radix64::decode to return result as std::vector git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8520 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pgp/pgpkeyutil.cc | 10 +++------ libretroshare/src/pgp/rscertificate.cc | 10 ++++----- libretroshare/src/util/radix64.h | 12 +++++------ libretroshare/src/util/rsrecogn.cc | 29 ++++++++------------------ retroshare-nogui/src/ssh/rssshd.cc | 6 ++---- 5 files changed, 23 insertions(+), 44 deletions(-) diff --git a/libretroshare/src/pgp/pgpkeyutil.cc b/libretroshare/src/pgp/pgpkeyutil.cc index 770c3b51e..f415f8db9 100644 --- a/libretroshare/src/pgp/pgpkeyutil.cc +++ b/libretroshare/src/pgp/pgpkeyutil.cc @@ -29,16 +29,12 @@ bool PGPKeyManagement::createMinimalKey(const std::string& pgp_certificate,std:: // 1 - Convert armored key into binary key // - - char *keydata = NULL ; - size_t len = 0 ; - - Radix64::decode(radix_cert,keydata,len) ; + std::vector keydata = Radix64::decode(radix_cert) ; size_t new_len ; - findLengthOfMinimalKey((unsigned char *)keydata,len,new_len) ; + findLengthOfMinimalKey(keydata.data(), keydata.size(), new_len) ; - cleaned_certificate = makeArmouredKey((unsigned char*)keydata,new_len,version_string) ; + cleaned_certificate = makeArmouredKey(keydata.data(), new_len, version_string) ; return true ; } catch(std::exception& e) diff --git a/libretroshare/src/pgp/rscertificate.cc b/libretroshare/src/pgp/rscertificate.cc index cdd004fc0..21eaeee0e 100644 --- a/libretroshare/src/pgp/rscertificate.cc +++ b/libretroshare/src/pgp/rscertificate.cc @@ -251,12 +251,11 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code) #endif // 1 - decode the string. // - char *bf = NULL ; - size_t size ; - Radix64::decode(str,bf, size) ; + std::vector bf = Radix64::decode(str) ; + size_t size = bf.size(); bool checksum_check_passed = false ; - unsigned char *buf = (unsigned char *)bf ; + unsigned char *buf = bf.data() ; size_t total_s = 0 ; only_pgp = true ; uint8_t certificate_version = 0x00 ; @@ -348,7 +347,7 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code) err_code = CERTIFICATE_PARSING_ERROR_INVALID_CHECKSUM_SECTION ; return false ; } - uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC((unsigned char *)bf,size-5) ; + uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC(bf.data(),size-5) ; uint32_t certificate_crc = buf[0] + (buf[1] << 8) + (buf[2] << 16) ; if(computed_crc != certificate_crc) @@ -386,7 +385,6 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code) if(total_s != size) std::cerr << "(EE) Certificate contains trailing characters. Weird." << std::endl; - delete[] bf ; return true ; } catch(std::exception& e) diff --git a/libretroshare/src/util/radix64.h b/libretroshare/src/util/radix64.h index 5bb2092f7..0125fa5d7 100644 --- a/libretroshare/src/util/radix64.h +++ b/libretroshare/src/util/radix64.h @@ -3,11 +3,12 @@ #include #include #include +#include class Radix64 { - public: - static void decode(const std::string& buffer,char *& out, size_t& len) + public: + static std::vector decode(const std::string& buffer) { char val; int c = 0, c2;/* init c because gcc is not clever @@ -17,7 +18,7 @@ class Radix64 radix64_init(); - std::vector buf ; + std::vector buf ; idx = 0; val = 0; @@ -94,10 +95,7 @@ again: idx = idx; - len = buf.size() ; - out = new char[len] ; - - memcpy(out,&buf[0],len) ; + return buf; } /**************** diff --git a/libretroshare/src/util/rsrecogn.cc b/libretroshare/src/util/rsrecogn.cc index 069e33f33..6712608a4 100644 --- a/libretroshare/src/util/rsrecogn.cc +++ b/libretroshare/src/util/rsrecogn.cc @@ -57,16 +57,12 @@ static std::string RecognSigningKeys[NUM_RECOGN_SIGN_KEYS] = EVP_PKEY *RsRecogn::loadMasterKey() { /* load master signing key */ - size_t keylen; - char *keyptr; - - Radix64::decode(RecognKey, keyptr, keylen); + std::vector decoded = Radix64::decode(RecognKey); - const unsigned char *keyptr2 = (const unsigned char *) keyptr; - long keylen2 = keylen; + const unsigned char *keyptr2 = decoded.data(); + long keylen2 = decoded.size(); RSA *rsakey = d2i_RSAPublicKey(NULL, &(keyptr2), keylen2); - delete []keyptr; if (!rsakey) { @@ -102,16 +98,12 @@ bool RsRecogn::loadSigningKeys(std::map &signM for(int i = 0; i < NUM_RECOGN_SIGN_KEYS; i++) { - char *signerbuf; - size_t len; - Radix64::decode(RecognSigningKeys[i], signerbuf, len); + std::vector signerbuf = Radix64::decode(RecognSigningKeys[i]); - uint32_t pktsize = len; - RsItem *pktitem = recognSerialiser.deserialise(signerbuf, &pktsize); + uint32_t pktsize = signerbuf.size(); + RsItem *pktitem = recognSerialiser.deserialise(signerbuf.data(), &pktsize); RsGxsRecognSignerItem *item = dynamic_cast(pktitem); - delete []signerbuf; - if (!item) { #ifdef DEBUG_RECOGN @@ -527,16 +519,13 @@ std::string RsRecogn::getRsaKeyId(RSA *pubkey) RsGxsRecognTagItem *RsRecogn::extractTag(const std::string &encoded) { // Decode from Radix64 encoded Packet. - size_t buflen; - char *buffer; uint32_t pktsize; - Radix64::decode(encoded, buffer, buflen); - pktsize = buflen; + std::vector buffer = Radix64::decode(encoded); + pktsize = buffer.size(); RsGxsRecognSerialiser serialiser; - RsItem *item = serialiser.deserialise(buffer, &pktsize); - delete []buffer; + RsItem *item = serialiser.deserialise(buffer.data(), &pktsize); if (!item) { diff --git a/retroshare-nogui/src/ssh/rssshd.cc b/retroshare-nogui/src/ssh/rssshd.cc index 895cc318b..c4d8082aa 100644 --- a/retroshare-nogui/src/ssh/rssshd.cc +++ b/retroshare-nogui/src/ssh/rssshd.cc @@ -860,14 +860,12 @@ int GeneratePasswordHash(std::string saltBin, std::string password, std::string int CheckPasswordHash(std::string pwdHashRadix64, std::string password) { char output[1024]; - char *buf = NULL; - size_t len = 1024; - Radix64::decode(pwdHashRadix64, buf, len); + std::vector buf = Radix64::decode(pwdHashRadix64); + size_t len = buf.size(); for(unsigned int i = 0; (i < len) && (i < 1024); i++) { output[i] = buf[i]; } - delete []buf; #if 0 std::cerr << "CheckPasswordHash() Input: " << pwdHashRadix64;