#[repr(C)]pub struct Keypair {
pub secret: SecretKey,
pub public: PublicKey,
}
Expand description
A public/secret long-term key pair.
This is an Ed25519 key pair.
Fields§
§secret: SecretKey
The secret half of the key pair. Keep private.
public: PublicKey
The public half of the key pair. Feel free to share.
Implementations§
Source§impl Keypair
impl Keypair
Sourcepub fn from_slice(s: &[u8]) -> Option<Keypair>
pub fn from_slice(s: &[u8]) -> Option<Keypair>
Deserialize a keypair from a byte slice.
The slice length must be 64; where the first 32 bytes are the secret key, and the second 32 bytes are the public key (libsodium’s standard layout).
Sourcepub fn from_base64(s: &str) -> Option<Keypair>
pub fn from_base64(s: &str) -> Option<Keypair>
Deserialize from the bas64 representation. Ignores optional .ed25519 suffix.
§Example
let s = "R6DKoOCt1Cj/IB2/ocvj2Eyp8AgmFdoJ9hH2TO4Tl8Yfapd5Lmw4pSpoY0WBEnqpHjz6UB4/QL2Wr0hWVAyi1w==.ed25519";
if let Some(keypair) = ssb_crypto::Keypair::from_base64(s) {
// let auth = keypair.sign("hello".to_bytes());
// ...
} else {
panic!()
}
Sourcepub fn as_base64(&self) -> String
pub fn as_base64(&self) -> String
Does not include “.ed25519” suffix or a sigil prefix.
§Example
let s = "R6DKoOCt1Cj/IB2/ocvj2Eyp8AgmFdoJ9hH2TO4Tl8Yfapd5Lmw4pSpoY0WBEnqpHjz6UB4/QL2Wr0hWVAyi1w==";
let kp = ssb_crypto::Keypair::from_base64(s).unwrap();
assert_eq!(kp.as_base64(), s);
Sourcepub fn from_seed(seed: &[u8]) -> Option<Keypair>
pub fn from_seed(seed: &[u8]) -> Option<Keypair>
Create a keypair from the given seed bytes. Slice length must be 32.
Sourcepub fn generate_with_rng<R>(r: &mut R) -> Keypair
pub fn generate_with_rng<R>(r: &mut R) -> Keypair
Generate a new random keypair using the given cryptographically-secure random number generator.
Trait Implementations§
impl FromBytes for Keypair
Auto Trait Implementations§
impl Freeze for Keypair
impl RefUnwindSafe for Keypair
impl Send for Keypair
impl Sync for Keypair
impl Unpin for Keypair
impl UnwindSafe for Keypair
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