#[repr(C)]pub struct Pk { /* private fields */ }
Implementations
sourceimpl Pk
impl Pk
sourcepub fn from_private_key(key: &[u8], password: Option<&[u8]>) -> Result<Pk>
pub fn from_private_key(key: &[u8], password: Option<&[u8]>) -> Result<Pk>
Takes both DER and PEM forms of PKCS#1 or PKCS#8 encoded keys.
When calling on PEM-encoded data, key
must be NULL-terminated
sourcepub fn from_public_key(key: &[u8]) -> Result<Pk>
pub fn from_public_key(key: &[u8]) -> Result<Pk>
Takes both DER and PEM encoded SubjectPublicKeyInfo keys.
When calling on PEM-encoded data, key
must be NULL-terminated
pub fn generate_rsa<F: Random>(
rng: &mut F,
bits: u32,
exponent: u32
) -> Result<Pk>
pub fn generate_ec<F: Random>(rng: &mut F, curve: EcGroupId) -> Result<Pk>
sourcepub fn set_options(&mut self, options: Options)
pub fn set_options(&mut self, options: Options)
Panics if the options are not valid for this key type.
pub fn can_do(&self, t: Type) -> bool
pub fn check_pair(public: &Self, private: &Self) -> bool
pub fn len(&self) -> usize
pub fn pk_type(&self) -> Type
pub fn curve(&self) -> Result<EcGroupId>
pub fn name(&self) -> Result<&str>
pub fn decrypt<F: Random>(
&mut self,
cipher: &[u8],
plain: &mut [u8],
rng: &mut F
) -> Result<usize>
pub fn encrypt<F: Random>(
&mut self,
plain: &[u8],
cipher: &mut [u8],
rng: &mut F
) -> Result<usize>
sourcepub fn sign<F: Random>(
&mut self,
md: Type,
hash: &[u8],
sig: &mut [u8],
rng: &mut F
) -> Result<usize>
pub fn sign<F: Random>(
&mut self,
md: Type,
hash: &[u8],
sig: &mut [u8],
rng: &mut F
) -> Result<usize>
Sign the hash hash
of type md
, placing the signature in sig
. rng
must be a
cryptographically secure RNG.
For RSA signatures, the length of sig
must be greater than or equal to the RSA
modulus length, otherwise sign()
fails with Error::PkSigLenMismatch
.
For EC signatures, the length of sig
must be greater than or equal to ECDSA_MAX_LEN
,
otherwise sign()
fails with Error::PkSigLenMismatch
.
On success, returns the actual number of bytes written to sig
.
pub fn verify(&mut self, md: Type, hash: &[u8], sig: &[u8]) -> Result<()>
sourcepub fn agree<F: Random>(
&mut self,
other: &Pk,
shared: &mut [u8],
rng: &mut F
) -> Result<usize>
pub fn agree<F: Random>(
&mut self,
other: &Pk,
shared: &mut [u8],
rng: &mut F
) -> Result<usize>
Agree on a shared secret with another public key.