pub struct CryptoKeyPair {
pub public_key_pem: String,
pub algorithm_id: String,
/* private fields */
}Expand description
Algorithm-agnostic key pair that works with any supported signature algorithm
This struct provides a unified interface for key management across different cryptographic algorithms (RSA, Ed25519, etc.).
The private key is stored in a Zeroizing<String> wrapper that automatically
clears memory when dropped, preventing key material from lingering in memory.
Fields§
§public_key_pem: StringThe public key in PEM format
algorithm_id: StringThe algorithm identifier (e.g., “RSA-SHA256”, “Ed25519”)
Implementations§
Source§impl CryptoKeyPair
impl CryptoKeyPair
Sourcepub fn private_key_pem(&self) -> &str
pub fn private_key_pem(&self) -> &str
Get a reference to the private key PEM
Sourcepub fn from_pem(
private_key_pem: String,
public_key_pem: String,
algorithm_id: &str,
) -> Self
pub fn from_pem( private_key_pem: String, public_key_pem: String, algorithm_id: &str, ) -> Self
Create from existing PEM keys
§Arguments
private_key_pem- The private key in PEM formatpublic_key_pem- The public key in PEM formatalgorithm_id- The algorithm identifier
Sourcepub fn load_from_files(
private_path: &Path,
public_path: &Path,
algorithm_id: &str,
) -> Result<Self>
pub fn load_from_files( private_path: &Path, public_path: &Path, algorithm_id: &str, ) -> Result<Self>
Load a key pair from files
On Unix, this checks that the private key file is not readable by group/other.
§Arguments
private_path- Path to the private key PEM filepublic_path- Path to the public key PEM filealgorithm_id- The algorithm identifier
Sourcepub fn save_to_files(
&self,
private_path: &Path,
public_path: &Path,
) -> Result<()>
pub fn save_to_files( &self, private_path: &Path, public_path: &Path, ) -> Result<()>
Save the key pair to files
Sourcepub fn verify(&self, data: &[u8], signature: &[u8]) -> Result<()>
pub fn verify(&self, data: &[u8], signature: &[u8]) -> Result<()>
Verify a signature using this key pair’s public key
Sourcepub fn get_algorithm(&self) -> Result<&'static dyn SignatureAlgorithm>
pub fn get_algorithm(&self) -> Result<&'static dyn SignatureAlgorithm>
Get the signature algorithm for this key pair
Sourcepub fn from_rsa_keypair(keypair: &KeyPair) -> Result<Self>
pub fn from_rsa_keypair(keypair: &KeyPair) -> Result<Self>
Convert a legacy RSA KeyPair to a CryptoKeyPair