diff options
Diffstat (limited to 'src/no_std_identity.rs')
| -rw-r--r-- | src/no_std_identity.rs | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/src/no_std_identity.rs b/src/no_std_identity.rs index 2a0018e..aac3253 100644 --- a/src/no_std_identity.rs +++ b/src/no_std_identity.rs @@ -1,5 +1,8 @@ +use crate::{ + NameString, + crypto::{Keystore, PrivateKey, PublicKey, SharedSecret}, +}; use bytes::Bytes; -use crate::{NameString, crypto::{Keystore, PrivateKey, PublicKey, SharedSecret}}; use tinyvec::ArrayVec; #[derive(PartialEq, Clone, Debug)] @@ -17,7 +20,7 @@ impl Default for Identity { Self { private_key, hash_prefix, - secrets: Default::default() + secrets: Default::default(), } } } @@ -29,7 +32,13 @@ pub struct StaticKeystore { } impl Keystore for StaticKeystore { - fn decrypt_and_id_p2p(&self, _source: u8, _dest: u8, mac: u16, data: &Bytes) -> Option<(Bytes, u32, u32)> { + fn decrypt_and_id_p2p( + &self, + _source: u8, + _dest: u8, + mac: u16, + data: &Bytes, + ) -> Option<(Bytes, u32, u32)> { // Just brute-force all the secrets until one matches... for identity in self.identities.iter() { for (peer_prefix, secret) in identity.secrets.iter() { @@ -42,7 +51,12 @@ impl Keystore for StaticKeystore { None } - fn decrypt_and_id_group(&self, _group_hash_prefix: u8, mac: u16, data: &Bytes) -> Option<(Bytes, Option<NameString>)> { + fn decrypt_and_id_group( + &self, + _group_hash_prefix: u8, + mac: u16, + data: &Bytes, + ) -> Option<(Bytes, Option<NameString>)> { for group in self.groups.iter() { let result = group.mac_then_decrypt(mac, data); if let Some(result) = result { @@ -53,7 +67,13 @@ impl Keystore for StaticKeystore { None } - fn decrypt_anon(&self, _dest: u8, pub_key: &PublicKey, mac: u16, data: &Bytes) -> Option<(Bytes, u32)> { + fn decrypt_anon( + &self, + _dest: u8, + pub_key: &PublicKey, + mac: u16, + data: &Bytes, + ) -> Option<(Bytes, u32)> { // For each identity, create a shared secret against the provided public key and check it. for identity in self.identities.iter() { let secret = identity.private_key.create_secret(pub_key); @@ -77,7 +97,7 @@ impl StaticKeystoreInput { pub fn compile(self) -> StaticKeystore { let mut retval = StaticKeystore { identities: ArrayVec::new(), - groups: ArrayVec::new(), + groups: ArrayVec::new(), }; for identity_in in self.identities { @@ -85,7 +105,10 @@ impl StaticKeystoreInput { identity.private_key = identity_in; identity.hash_prefix = PublicKey::from(&identity.private_key).hash_prefix(); for contact_in in self.contacts.iter() { - identity.secrets.push((contact_in.hash_prefix(), identity.private_key.create_secret(&contact_in))); + identity.secrets.push(( + contact_in.hash_prefix(), + identity.private_key.create_secret(&contact_in), + )); } retval.identities.push(identity); @@ -102,7 +125,5 @@ impl StaticKeystoreInput { #[cfg(test)] mod tests { #[test] - fn test_compile() { - - } -}
\ No newline at end of file + fn test_compile() {} +} |
