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
This commit is contained in:
electron128 2015-06-18 13:45:08 +00:00
parent 6a924cb854
commit 13355a7efe
5 changed files with 23 additions and 44 deletions

View File

@ -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<uint8_t> 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)

View File

@ -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<uint8_t> 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)

View File

@ -3,11 +3,12 @@
#include <string>
#include <string.h>
#include <vector>
#include <stdint.h>
class Radix64
{
public:
static void decode(const std::string& buffer,char *& out, size_t& len)
static std::vector<uint8_t> 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<char> buf ;
std::vector<uint8_t> 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;
}
/****************

View File

@ -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;
std::vector<uint8_t> decoded = Radix64::decode(RecognKey);
Radix64::decode(RecognKey, keyptr, keylen);
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<RsGxsId, RsGxsRecognSignerItem *> &signM
for(int i = 0; i < NUM_RECOGN_SIGN_KEYS; i++)
{
char *signerbuf;
size_t len;
Radix64::decode(RecognSigningKeys[i], signerbuf, len);
std::vector<uint8_t> 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<RsGxsRecognSignerItem *>(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<uint8_t> 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)
{

View File

@ -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<uint8_t> 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;