MCPcopy Create free account
hub / github.com/ValveSoftware/GameNetworkingSockets / CCryptoKeyBase

Class CCryptoKeyBase

src/common/keypair.h:43–105  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: Base class to encapsulate an crypto key (RSA, EC, ECDSA). This class cannot be instantiated directly, use one of the subclasses to indicate the intent of the key. -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

41// to indicate the intent of the key.
42//-----------------------------------------------------------------------------
43class CCryptoKeyBase
44{
45public:
46 virtual ~CCryptoKeyBase();
47
48 ECryptoKeyType GetKeyType() const { return m_eKeyType; }
49
50 // Return true if we're valid
51 virtual bool IsValid() const = 0;
52
53 // Free up memory and wipe any sensitive data
54 virtual void Wipe() = 0;
55
56 // Get raw data. Returns number of bytes populated into the buffer.
57 // If you pass NULL, the number of bytes required is returned.
58 virtual uint32 GetRawData( void *pData ) const = 0;
59
60 // Set raw data. Returns true on success. Regardless of the outcome,
61 // your buffer will be wiped.
62 bool SetRawDataAndWipeInput( void *pData, size_t cbData );
63
64 // Don't wipe the input. Use this when you know your key is not valuable,
65 // or are going to wipe it yourself
66 bool SetRawDataWithoutWipingInput( const void *pData, size_t cbData );
67
68 // Initialize a key object from a hex encoded string of the raw key bytes
69 bool SetFromHexEncodedString( const char *pchEncodedKey );
70 bool SetFromBase64EncodedString( const char *pchEncodedKey );
71
72 // Get raw data as a std::string
73 bool GetRawDataAsStdString( std::string *pResult ) const;
74
75 // Set raw data from a std::string. (Useful for dealing with protobuf)
76 // NOTE: DOES NOT WIPE THE INPUT
77 bool SetRawDataFromStdString( const std::string &s ) { return SetRawDataWithoutWipingInput( s.c_str(), s.length() ); }
78
79 // Load from some sort of formatted buffer. (Not the raw binary key data.)
80 virtual bool LoadFromAndWipeBuffer( void *pBuffer, size_t cBytes );
81
82 // Compare keys for equality, by comparing their raw data
83 bool operator==( const CCryptoKeyBase &rhs ) const;
84 bool operator!=( const CCryptoKeyBase &rhs ) const { return !operator==( rhs ); }
85
86 // Return true if our raw data matches the specified buffer.
87 bool BMatchesRawData( const void *pData, size_t cbData ) const;
88
89 // Make a copy of the key, by using the raw data functions
90 void CopyFrom( const CCryptoKeyBase &x );
91
92#ifdef DBGFLAG_VALIDATE
93 virtual void Validate( CValidator &validator, const char *pchName ) const = 0; // Validate our internal structures
94#endif // DBGFLAG_VALIDATE
95
96protected:
97 virtual bool SetRawData( const void *pData, size_t cbData ) = 0;
98 CCryptoKeyBase( ECryptoKeyType keyType ) : m_eKeyType( keyType ) {}
99
100 const ECryptoKeyType m_eKeyType;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected