to_public

Function to_public 

Source
pub fn to_public(key_data: &KeyData) -> Result<KeyData, KeyError>
Expand description

Derives a public key from a private key, or returns the key if it’s already public.

§Arguments

  • key_data - The key data to convert to public key format

§Returns

A KeyData containing the corresponding public key

§Errors

  • Returns KeyError::SecretKeyError if private key parsing fails

§Example

use atproto_identity::key::{generate_key, to_public, KeyType};

let private_key = generate_key(KeyType::P256Private)?;
let public_key = to_public(&private_key)?;
assert_eq!(*public_key.key_type(), KeyType::P256Public);

// Works with public keys too
let same_public_key = to_public(&public_key)?;
assert_eq!(public_key.bytes(), same_public_key.bytes());