pub struct PrivateKey { /* private fields */ }Expand description
Private key for JWT signing.
Stores the cryptographic key material for signing JWTs. The key data is never exposed in Debug output for security.
Implementations§
Source§impl PrivateKey
impl PrivateKey
Sourcepub fn from_pem(pem: &str) -> Result<Self, ValidationError>
pub fn from_pem(pem: &str) -> Result<Self, ValidationError>
Create a private key from PEM-encoded string.
§Arguments
pem- PEM-encoded RSA private key
§Errors
Returns ValidationError if:
- PEM format is invalid
- Key type is not RSA
- Key data is corrupted
§Examples
let pem = r#"-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA...
-----END RSA PRIVATE KEY-----"#;
let key = PrivateKey::from_pem(pem).expect("Invalid PEM");Sourcepub fn from_pkcs8_der(der: &[u8]) -> Result<Self, ValidationError>
pub fn from_pkcs8_der(der: &[u8]) -> Result<Self, ValidationError>
Source§impl PrivateKey
impl PrivateKey
Sourcepub fn new(key_data: Vec<u8>, algorithm: KeyAlgorithm) -> Self
pub fn new(key_data: Vec<u8>, algorithm: KeyAlgorithm) -> Self
Create a new private key.
§Arguments
key_data- The raw key bytes (PEM or DER format)algorithm- The signing algorithm (typically RS256)
Sourcepub fn algorithm(&self) -> &KeyAlgorithm
pub fn algorithm(&self) -> &KeyAlgorithm
Get the signing algorithm.
Trait Implementations§
Source§impl Clone for PrivateKey
impl Clone for PrivateKey
Source§fn clone(&self) -> PrivateKey
fn clone(&self) -> PrivateKey
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PrivateKey
impl RefUnwindSafe for PrivateKey
impl Send for PrivateKey
impl Sync for PrivateKey
impl Unpin for PrivateKey
impl UnsafeUnpin for PrivateKey
impl UnwindSafe for PrivateKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more