Skip to content

Commit

Permalink
chore: Allow exporting keys to slices for import
Browse files Browse the repository at this point in the history
  • Loading branch information
OtaK authored and augustocdias committed Aug 13, 2024
1 parent ab7d4a4 commit 020f919
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/internal/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,17 @@ impl PreKeyBundle {

pub fn verify(&self) -> PreKeyAuth {
match self.signature {
Some(ref sig) => if self
.identity_key
.public_key
.verify(sig, &self.public_key.pub_edward.0)
{
PreKeyAuth::Valid
} else {
PreKeyAuth::Invalid
},
Some(ref sig) => {
if self
.identity_key
.public_key
.verify(sig, &self.public_key.pub_edward.0)
{
PreKeyAuth::Valid
} else {
PreKeyAuth::Invalid
}
}
None => PreKeyAuth::Unknown,
}
}
Expand Down Expand Up @@ -442,6 +444,10 @@ impl SecretKey {
}
}

pub fn as_slice(&self) -> &[u8] {
self.sec_edward.0.as_slice()
}

pub fn shared_secret(&self, p: &PublicKey) -> Result<[u8; 32], Zero> {
ecdh::scalarmult(&self.sec_curve, &p.pub_curve)
.map(|ge| ge.0)
Expand Down Expand Up @@ -505,6 +511,10 @@ impl PublicKey {
sign::verify_detached(&s.sig, m, &self.pub_edward)
}

pub fn as_slice(&self) -> &[u8] {
self.pub_edward.0.as_slice()
}

pub fn fingerprint(&self) -> String {
fmt_hex(&self.pub_edward.0)
}
Expand Down

0 comments on commit 020f919

Please sign in to comment.