mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Safer rsids API
Deprecate unsafe costructor, substituted by fromBufferUnsafe which explicitely marked suggest the caller to pay attention. Use enum class for id types instead of constants Make size constants more private Use internal Id_t alias to avoid huge template lines Remove and deprecate oguly names in favor of consistent names
This commit is contained in:
parent
ccf7dc24b8
commit
7642216912
12 changed files with 337 additions and 267 deletions
|
@ -908,12 +908,14 @@ bool PGPHandler::checkAndImportKeyPair(ops_keyring_t *tmp_keyring, RsPgpId &impo
|
|||
return false ;
|
||||
}
|
||||
|
||||
if(pubkey == NULL || seckey == NULL || pubkey == seckey)
|
||||
if(pubkey == nullptr || seckey == nullptr || pubkey == seckey)
|
||||
{
|
||||
import_error = "File does not contain a public and a private key. Sorry." ;
|
||||
return false ;
|
||||
}
|
||||
if(memcmp(pubkey->fingerprint.fingerprint,seckey->fingerprint.fingerprint,PGP_KEY_FINGERPRINT_SIZE) != 0)
|
||||
if(memcmp( pubkey->fingerprint.fingerprint,
|
||||
seckey->fingerprint.fingerprint,
|
||||
RsPpgFingerprint::SIZE_IN_BYTES ) != 0)
|
||||
{
|
||||
import_error = "Public and private keys do nt have the same fingerprint. Sorry!" ;
|
||||
return false ;
|
||||
|
@ -940,7 +942,10 @@ bool PGPHandler::checkAndImportKeyPair(ops_keyring_t *tmp_keyring, RsPgpId &impo
|
|||
bool found = false ;
|
||||
|
||||
for(uint32_t i=0;i<result->valid_count;++i)
|
||||
if(!memcmp((unsigned char*)result->valid_sigs[i].signer_id,pubkey->key_id,PGP_KEY_ID_SIZE))
|
||||
if(!memcmp(
|
||||
static_cast<uint8_t*>(result->valid_sigs[i].signer_id),
|
||||
pubkey->key_id,
|
||||
RsPpgFingerprint::SIZE_IN_BYTES ))
|
||||
{
|
||||
found = true ;
|
||||
break ;
|
||||
|
@ -1087,7 +1092,10 @@ bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,RsPgpId&
|
|||
bool found = false ;
|
||||
|
||||
for(uint32_t i=0;i<result->valid_count;++i)
|
||||
if(!memcmp((unsigned char*)result->valid_sigs[i].signer_id,keydata->key_id,PGP_KEY_ID_SIZE))
|
||||
if(!memcmp(
|
||||
static_cast<uint8_t*>(result->valid_sigs[i].signer_id),
|
||||
keydata->key_id,
|
||||
RsPpgFingerprint::SIZE_IN_BYTES ))
|
||||
{
|
||||
found = true ;
|
||||
break ;
|
||||
|
@ -1164,7 +1172,9 @@ bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map<RsPgpId,PG
|
|||
}
|
||||
else
|
||||
{
|
||||
if(memcmp(existing_key->fingerprint.fingerprint, keydata->fingerprint.fingerprint,PGP_KEY_FINGERPRINT_SIZE))
|
||||
if(memcmp( existing_key->fingerprint.fingerprint,
|
||||
keydata->fingerprint.fingerprint,
|
||||
RsPpgFingerprint::SIZE_IN_BYTES ))
|
||||
{
|
||||
std::cerr << "(EE) attempt to merge key with identical id, but different fingerprint!" << std::endl;
|
||||
return false ;
|
||||
|
@ -1792,7 +1802,8 @@ bool PGPHandler::privateTrustCertificate(const RsPgpId& id,int trustlvl)
|
|||
|
||||
struct PrivateTrustPacket
|
||||
{
|
||||
unsigned char user_id[PGP_KEY_ID_SIZE] ; // pgp id in unsigned char format.
|
||||
/// pgp id in unsigned char format.
|
||||
unsigned char user_id[RsPgpId::SIZE_IN_BYTES];
|
||||
uint8_t trust_level ; // trust level. From 0 to 6.
|
||||
uint32_t time_stamp ; // last time the cert was ever used, in seconds since the epoch. 0 means not initialized.
|
||||
};
|
||||
|
@ -1854,9 +1865,12 @@ bool PGPHandler::locked_writePrivateTrustDatabase()
|
|||
}
|
||||
PrivateTrustPacket trustpacket ;
|
||||
|
||||
for(std::map<RsPgpId,PGPCertificateInfo>::iterator it = _public_keyring_map.begin();it!=_public_keyring_map.end() ;++it)
|
||||
for( std::map<RsPgpId,PGPCertificateInfo>::iterator it =
|
||||
_public_keyring_map.begin(); it!=_public_keyring_map.end(); ++it )
|
||||
{
|
||||
memcpy(trustpacket.user_id,RsPgpId(it->first).toByteArray(),PGP_KEY_ID_SIZE) ;
|
||||
memcpy( trustpacket.user_id,
|
||||
it->first.toByteArray(),
|
||||
RsPgpId::SIZE_IN_BYTES );
|
||||
trustpacket.trust_level = it->second._trustLvl ;
|
||||
trustpacket.time_stamp = it->second._time_stamp ;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue