Changes CKeyPair::CopyFrom

1.) It doesn't return bool anymore.  It just considers failure fatal.  Very
    few call sites were checking it anyway, and all of the ones that were
    were just asserting anyway, not actually handling it.  Sort of a classic
    example of a funciton where you should not try to handle failure.

2.) If the source key is empty, that is no longer considered an error.  We
    just set the destination key to empty.  Given that nobody was previously
    handling this error anyway, except for the people checking and asserting,
    I think this is safe.
This commit is contained in:
Fletcher Dunn
2020-12-21 09:47:25 -08:00
parent f74eb18c67
commit 6d96dff9f7
4 changed files with 9 additions and 13 deletions
+4 -4
View File
@@ -88,8 +88,8 @@ public:
CECKeyExchangePublicKey() : CEC25519PublicKeyBase( k_ECryptoKeyTypeKeyExchangePublic ) { }
// Allow copying of public keys without a bunch of paranoia.
CECKeyExchangePublicKey( const CECKeyExchangePublicKey &x ) : CEC25519PublicKeyBase( k_ECryptoKeyTypeKeyExchangePublic ) { VerifyFatal( CopyFrom( x ) ); }
CECKeyExchangePublicKey & operator=(const CECKeyExchangePublicKey &x) { if ( this != &x ) { VerifyFatal( CopyFrom( x ) ); } return *this; }
CECKeyExchangePublicKey( const CECKeyExchangePublicKey &x ) : CEC25519PublicKeyBase( k_ECryptoKeyTypeKeyExchangePublic ) { CopyFrom( x ); }
CECKeyExchangePublicKey & operator=(const CECKeyExchangePublicKey &x) { if ( this != &x ) { CopyFrom( x ); } return *this; }
virtual ~CECKeyExchangePublicKey();
};
@@ -132,8 +132,8 @@ public:
CECSigningPublicKey() : CEC25519PublicKeyBase( k_ECryptoKeyTypeSigningPublic ) { }
// Allow copying of public keys without a bunch of paranoia.
CECSigningPublicKey( const CECSigningPublicKey &x ) : CEC25519PublicKeyBase( k_ECryptoKeyTypeSigningPublic ) { VerifyFatal( CopyFrom( x ) ); }
CECSigningPublicKey& operator=(const CECSigningPublicKey &x) { if ( this != &x ) { VerifyFatal( CopyFrom( x ) ); } return *this; }
CECSigningPublicKey( const CECSigningPublicKey &x ) : CEC25519PublicKeyBase( k_ECryptoKeyTypeSigningPublic ) { CopyFrom( x ); }
CECSigningPublicKey& operator=(const CECSigningPublicKey &x) { if ( this != &x ) { CopyFrom( x ); } return *this; }
virtual bool LoadFromAndWipeBuffer( void *pBuffer, size_t cBytes ) override;
+3 -7
View File
@@ -364,21 +364,17 @@ bool CCryptoKeyBase::operator==( const CCryptoKeyBase &rhs ) const
return memcmp( bufLHS.Base(), bufRHS.Base(), cbRawData ) == 0;
}
bool CCryptoKeyBase::CopyFrom( const CCryptoKeyBase &x )
void CCryptoKeyBase::CopyFrom( const CCryptoKeyBase &x )
{
Assert( m_eKeyType == x.m_eKeyType );
Wipe();
uint32 cbData = x.GetRawData( nullptr );
if ( cbData == 0 )
{
Assert( false );
return false;
}
return;
void *tmp = alloca( cbData );
VerifyFatal( x.GetRawData( tmp ) == cbData );
return SetRawDataAndWipeInput( tmp, cbData );
VerifyFatal( SetRawDataAndWipeInput( tmp, cbData ) );
}
bool CCryptoKeyBase::LoadFromAndWipeBuffer( void *pBuffer, size_t cBytes )
+1 -1
View File
@@ -84,7 +84,7 @@ public:
bool operator!=( const CCryptoKeyBase &rhs ) const { return !operator==( rhs ); }
// Make a copy of the key, by using the raw data functions
bool CopyFrom( const CCryptoKeyBase &x );
void CopyFrom( const CCryptoKeyBase &x );
#ifdef DBGFLAG_VALIDATE
virtual void Validate( CValidator &validator, const char *pchName ) const = 0; // Validate our internal structures
@@ -1134,7 +1134,7 @@ void CSteamNetworkConnectionBase::SetLocalCert( const CMsgSteamDatagramCertifica
// but we'll only keep this around for a brief time. It's possible for the
// interface to get a new cert (with a new private key) while we are starting this
// connection. We'll keep using the old one, which may be totally valid.
DbgVerify( m_keyPrivate.CopyFrom( keyPrivate ) );
m_keyPrivate.CopyFrom( keyPrivate );
// Save off the signed certificate
m_msgSignedCertLocal = msgSignedCert;