Struct PrivateKeyImport
pub struct PrivateKeyImport {
key_data: PrivateKeyData,
}Expand description
The key data required when importing a secret key
Fields§
§key_data: PrivateKeyDataImplementations§
§impl PrivateKeyImport
impl PrivateKeyImport
pub fn new(
key_type: KeyType,
key_data: &[u8],
) -> Result<PrivateKeyImport, Error>
pub fn new( key_type: KeyType, key_data: &[u8], ) -> Result<PrivateKeyImport, Error>
Creates a new PrivateKeyImport
Accepts a KeyType (all except KeyType::Generic) and a bytes array representing a
matching PKCS#8 private key in ASN.1 DER-encoded format.
§Errors
Returns an error if
key_datacan not be deserialized to a respective private key format.- an RSA private key does not have prime P or prime Q.
- an RSA private key is shorter than [
MIN_RSA_BIT_LENGTH]. key_typeis the unsupportedKeyType::Generic.
§Examples
use ed25519_dalek::{SigningKey, pkcs8::EncodePrivateKey};
use rand::rngs::OsRng;
use signstar_crypto::key::{KeyType, PrivateKeyImport};
let key_data = {
let mut csprng = OsRng;
let signing_key: SigningKey = SigningKey::generate(&mut csprng);
signing_key.to_pkcs8_der()?.as_bytes().to_vec()
};
assert!(PrivateKeyImport::new(KeyType::Curve25519, &key_data).is_ok());pub fn from_pkcs8_pem(
key_type: KeyType,
key_data: &str,
) -> Result<PrivateKeyImport, Error>
pub fn from_pkcs8_pem( key_type: KeyType, key_data: &str, ) -> Result<PrivateKeyImport, Error>
Creates a new PrivateKeyImport
Accepts a KeyType (all except KeyType::Generic) and a string slice representing a
matching PKCS#8 private key in PEM-encoded format.
§Errors
Returns an error if
key_datacan not be deserialized to a respective private key format.- an RSA private key does not have prime P or prime Q.
- an RSA private key is shorter than [
MIN_RSA_BIT_LENGTH]. key_typeis the unsupportedKeyType::Generic.
§Examples
use std::ops::Deref;
use ed25519_dalek::{SigningKey, pkcs8::EncodePrivateKey, pkcs8::spki::der::pem::LineEnding};
use rand::rngs::OsRng;
use signstar_crypto::key::{KeyType, PrivateKeyImport};
let key_data = {
let mut csprng = OsRng;
let signing_key: SigningKey = SigningKey::generate(&mut csprng);
signing_key.to_pkcs8_pem(LineEnding::default())?
};
assert!(PrivateKeyImport::from_pkcs8_pem(KeyType::Curve25519, key_data.deref()).is_ok());pub fn from_rsa(
prime_p: Vec<u8>,
prime_q: Vec<u8>,
public_exponent: Vec<u8>,
) -> PrivateKeyImport
pub fn from_rsa( prime_p: Vec<u8>, prime_q: Vec<u8>, public_exponent: Vec<u8>, ) -> PrivateKeyImport
Create PrivateKeyImport object from raw, private RSA key parts.
The function takes two primes (p and q) and the public exponent,
which usually is 65537 ([0x01, 0x00, 0x01]).
§Examples
use signstar_crypto::key::PrivateKeyImport;
let prime_p = vec![7];
let prime_q = vec![11];
let public_exponent = vec![1, 0, 1];
let _import = PrivateKeyImport::from_rsa(prime_p, prime_q, public_exponent);pub fn from_raw_bytes(
ec: KeyType,
bytes: impl AsRef<[u8]>,
) -> Result<PrivateKeyImport, Error>
pub fn from_raw_bytes( ec: KeyType, bytes: impl AsRef<[u8]>, ) -> Result<PrivateKeyImport, Error>
Create PrivateKeyImport object from raw, private Elliptic Curve bytes.
The function takes two parameters:
- the type of elliptic curve,
- raw bytes in a curve-specific encoding
Elliptic curve keys require the bytes to be zero-padded to be of correct size.
This function automatically applies padding accordingly.
§Examples
use signstar_crypto::key::{KeyType, PrivateKeyImport};
let bytes = vec![0x00; 32];
let _import = PrivateKeyImport::from_raw_bytes(KeyType::Curve25519, bytes)?;pub fn key_type(&self) -> KeyType
pub fn key_type(&self) -> KeyType
Get the matching KeyType for the data contained in the PrivateKeyImport
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PrivateKeyImport
impl RefUnwindSafe for PrivateKeyImport
impl Send for PrivateKeyImport
impl Sync for PrivateKeyImport
impl Unpin for PrivateKeyImport
impl UnwindSafe for PrivateKeyImport
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
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.