diff options
| author | s-ol <s+removethis@s-ol.nu> | 2026-03-28 22:35:26 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2026-03-28 22:38:32 +0000 |
| commit | b4bb62b7ca0be710a0a7d5484cb9d3371f24ec2a (patch) | |
| tree | 2cb6178dfa67f52f9be5bd7844969ca92e8cb4f8 | |
| parent | expose more fields (diff) | |
| download | meshcore-rs-dumb-no-std.tar.gz meshcore-rs-dumb-no-std.zip | |
no-std compatible cryptodumb-no-std
| -rw-r--r-- | Cargo.lock | 214 | ||||
| -rw-r--r-- | Cargo.toml | 12 | ||||
| -rw-r--r-- | src/crypto.rs | 5 | ||||
| -rw-r--r-- | src/lib.rs | 8 | ||||
| -rw-r--r-- | src/no_std_crypto.rs | 279 | ||||
| -rw-r--r-- | src/packet.rs | 10 | ||||
| -rw-r--r-- | src/packet_content.rs | 6 | ||||
| -rw-r--r-- | src/text.rs | 9 |
8 files changed, 235 insertions, 308 deletions
@@ -6,20 +6,26 @@ version = 4 name = "MeshCore" version = "0.0.1" dependencies = [ + "aes", "arraystring", "bytes", "cayenne_lpp", "chrono", "clap", "color-eyre", + "curve25519-dalek", + "ed25519-dalek", "hex", + "hmac", "pcap-file", "pcap-file-tokio", "pretty_env_logger", "serde", + "sha2", "tinyvec", "tokio", "toml", + "x25519-dalek", ] [[package]] @@ -38,6 +44,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] name = "aho-corasick" version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -144,6 +161,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] name = "byteorder" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -186,6 +212,16 @@ dependencies = [ ] [[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] name = "clap" version = "4.5.51" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -259,6 +295,52 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" [[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "curve25519-dalek" +version = "4.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest", + "fiat-crypto", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.109", +] + +[[package]] name = "derive-into-owned" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -270,6 +352,38 @@ dependencies = [ ] [[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e796c081cee67dc755e1a36a0a172b897fab85fc3f6bc48307991f64e4eca9" +dependencies = [ + "curve25519-dalek", + "ed25519", + "sha2", + "subtle", +] + +[[package]] name = "env_logger" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -299,6 +413,22 @@ dependencies = [ ] [[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] name = "gimli" version = "0.32.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -329,6 +459,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] name = "humantime" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -351,6 +490,15 @@ dependencies = [ ] [[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + +[[package]] name = "is-terminal" version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -540,6 +688,12 @@ dependencies = [ ] [[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] name = "redox_syscall" version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -584,12 +738,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" [[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + +[[package]] name = "serde" version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -629,6 +798,17 @@ dependencies = [ ] [[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] name = "sharded-slab" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -647,6 +827,12 @@ dependencies = [ ] [[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" + +[[package]] name = "smallvec" version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -669,6 +855,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] name = "syn" version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -877,6 +1069,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" [[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -985,3 +1183,19 @@ name = "winnow" version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" + +[[package]] +name = "x25519-dalek" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7e468321c81fb07fa7f4c636c3972b9100f0346e5b6a9f2bd0603a52f7ed277" +dependencies = [ + "curve25519-dalek", + "rand_core", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" @@ -21,13 +21,13 @@ arraystring = { version = "0.3.0", default-features = false } tinyvec = "1.10.0" # Crypto functions needed for packet signatures and (en|de)cryption -# sha2 = { version = "0.10", default-features = false } -# hmac = { version = "0.12", default-features = false } -# ed25519-dalek = { version = "2", features = ["hazmat", "rand_core"]} -# x25519-dalek = { version = "2", features = ["static_secrets"]} +sha2 = { version = "0.10", default-features = false } +hmac = { version = "0.12", default-features = false } +ed25519-dalek = { version = "2", default-features = false, features = ["hazmat"] } # features = ["hazmat", "rand_core"]} +x25519-dalek = { version = "2", default-features = false } # features = ["static_secrets"]} # rand = "0.8" -# curve25519-dalek = "4.1.3" -# aes = "0.8.4" +curve25519-dalek = "4.1.3" +aes = { version = "0.8", default-features = false } # log = { version = "0.4.28", default-features = false } # Dependencies needed only for the Packet Analyzer diff --git a/src/crypto.rs b/src/crypto.rs index acbb464..034e9cc 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -6,7 +6,7 @@ use aes::Aes128; use aes::cipher::{BlockDecrypt, BlockEncrypt, generic_array::GenericArray}; use bytes::{Buf, BufMut, Bytes, BytesMut}; use curve25519_dalek::MontgomeryPoint; -use ed25519_dalek::{VerifyingKey, hazmat::ExpandedSecretKey}; +use ed25519_dalek::{SigningKey, VerifyingKey, hazmat::ExpandedSecretKey}; use hmac::{Hmac, Mac}; use sha2::Sha256; @@ -82,6 +82,7 @@ impl Clone for PrivateKey { impl Default for PrivateKey { fn default() -> Self { + /* // To make a key whole-cloth, we need to start with a SigningKey made // using a good RNG. Then we can use that to make an ExpandedSecretKey. use ed25519_dalek::SigningKey; @@ -95,6 +96,8 @@ impl Default for PrivateKey { // Then, there are only a few constructors for making an ExpandedSecretKey. // Meshcore uses this kind of key, so it's what we need in this application, // but it's an uncommon formulation. + */ + let signing_key = SigningKey::from_bytes(&[0u8; 32]); let esk = ExpandedSecretKey::from(&signing_key.to_bytes()); Self(esk) } @@ -1,13 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] pub mod crypto; -#[cfg(not(feature = "std"))] -pub mod no_std_crypto; -#[cfg(not(feature = "std"))] -pub use no_std_crypto as crypto; - pub mod string_helper; #[derive(Debug, PartialEq)] @@ -24,7 +18,7 @@ pub mod std_identity; // This version of identity is no-std #[cfg(not(feature = "std"))] -pub(crate) mod no_std_identity; +pub mod no_std_identity; pub mod ack; pub mod advert; diff --git a/src/no_std_crypto.rs b/src/no_std_crypto.rs deleted file mode 100644 index 31f4626..0000000 --- a/src/no_std_crypto.rs +++ /dev/null @@ -1,279 +0,0 @@ -use bytes::{Buf, BufMut, Bytes, BytesMut}; -use serde::{Deserialize, Serialize}; - -use crate::string_helper::NameString; - -pub trait Keystore { - fn decrypt_and_id_p2p( - &self, - source: u8, - _dest: u8, - mac: u16, - data: &Bytes, - ) -> Option<(Bytes, u32, u32)>; - - fn decrypt_and_id_group( - &self, - group_hash_prefix: u8, - mac: u16, - data: &Bytes, - ) -> Option<(Bytes, Option<NameString>)>; - - fn decrypt_anon( - &self, - dest: u8, - pub_key: &PublicKey, - mac: u16, - data: &Bytes, - ) -> Option<(Bytes, u32)>; -} - -#[derive(Debug, PartialEq)] -pub enum MeshcoreCryptoError { - KeyLengthError, - TryFromSliceError, - HexDecodeError, - KeyCreationError, -} - -impl core::error::Error for MeshcoreCryptoError {} - -impl core::fmt::Display for MeshcoreCryptoError { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - MeshcoreCryptoError::KeyLengthError => f.write_str("Key Length Error"), - MeshcoreCryptoError::TryFromSliceError => f.write_str("Try From Slice Error"), - MeshcoreCryptoError::HexDecodeError => f.write_str("Hex Decode Error"), - MeshcoreCryptoError::KeyCreationError => f.write_str("Key Creation Error"), - } - } -} - -#[derive(Serialize, Deserialize, Clone, PartialEq)] -pub struct PrivateKey(pub [u8; 32]); - -impl core::fmt::Debug for PrivateKey { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_tuple("PublicKey") - .field(&hex::encode(self.0)) - .finish() - } -} - -impl Default for PrivateKey { - fn default() -> Self { - Self([0; 32]) - } -} - -impl PrivateKey { - pub fn hash_prefix(&self) -> u32 { - // The has prefix is the beginning of the public key of the secret - let public_key = PublicKey::from(self); - public_key.hash_prefix() - } -} - -#[derive(Eq, Hash, Serialize, Deserialize, PartialEq, Clone)] -pub struct PublicKey(pub [u8; 32]); - -impl core::fmt::Debug for PublicKey { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_tuple("PublicKey") - .field(&hex::encode(self.0)) - .finish() - } -} - -impl PublicKey { - pub fn hash_prefix(&self) -> u32 { - let mut bytes = Bytes::copy_from_slice(&self.0); - bytes.get_u32() - } -} - -#[derive(Clone, Eq, Hash, PartialEq)] -pub struct SharedSecret([u8; 32]); - -impl core::fmt::Debug for SharedSecret { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_tuple("SharedSecret") - .field(&hex::encode(self.0)) - .finish() - } -} - -impl core::str::FromStr for SharedSecret { - type Err = MeshcoreCryptoError; - - fn from_str(s: &str) -> Result<Self, Self::Err> { - let mut array = [0_u8; 32]; - - // The provided group secrets are only 16 bytes, - // but they're zero-paded to be 32. So, we're - // going to get the hex from the string and copy it in. - if hex::decode_to_slice(s, &mut array[0..16]).is_err() { - return Err(MeshcoreCryptoError::TryFromSliceError); - } else { - Ok(SharedSecret(array)) - } - } -} - -impl TryFrom<Bytes> for SharedSecret { - type Error = MeshcoreCryptoError; - - fn try_from(value: Bytes) -> Result<Self, Self::Error> { - if let Some(arr) = value.first_chunk::<32>() { - // value.as_array::<32>() { - Ok(Self(*arr)) - } else { - Err(MeshcoreCryptoError::KeyLengthError) - } - } -} - -// This is kinda meaningless because a shared secret only works -// when it's connected to a key pair, but it needs to exist for -// Arrayvec. -impl Default for SharedSecret { - fn default() -> Self { - Self(Default::default()) - } -} - -impl SharedSecret { - fn get_key(&self) -> &[u8; 16] { - // Safety: The size of the slice ensures that this will never be wrong. - (&self.0[0..16]).try_into().unwrap() - } - - pub fn new_from_group_secret(bytes: Bytes) -> Self { - // The group secret is 16-bytes of key with the last 16-bytes set to zero. - let mut group_secret = BytesMut::from(bytes); - group_secret.reserve(16); - group_secret.put(&[0_u8; 16][..]); - - // group_secret.as_array::<32>(); - let slice = group_secret.first_chunk::<32>().unwrap(); - SharedSecret(slice.clone()) - } - - pub fn get_hmac(&self, _ciphertext: &Bytes) -> u16 { - // @TODO - 10 - } - - pub fn decrypt(&self, ciphertext: &Bytes) -> Bytes { - // @TODO - ciphertext.clone() - } - - pub fn encrypt(&self, plaintext: Bytes) -> Bytes { - // @TODO - plaintext - } - - pub fn hash_prefix(&self) -> u8 { - self.0[0] - } -} - -// This is just for creating placeholders -impl Default for PublicKey { - fn default() -> Self { - PublicKey(Default::default()) - } -} - -impl TryFrom<&[u8; 32]> for PublicKey { - type Error = MeshcoreCryptoError; - - fn try_from(value: &[u8; 32]) -> Result<Self, Self::Error> { - Ok(PublicKey(*value)) - } -} - -impl TryFrom<&[u8]> for PublicKey { - type Error = MeshcoreCryptoError; - - fn try_from(value: &[u8]) -> Result<Self, Self::Error> { - let bytes = Bytes::copy_from_slice(value); - Self::try_from(bytes) - } -} - -impl TryFrom<Bytes> for PublicKey { - type Error = MeshcoreCryptoError; - - fn try_from(value: Bytes) -> Result<Self, Self::Error> { - if let Some(arr) = value.first_chunk::<32>() { - Self::try_from(arr) - } else { - Err(MeshcoreCryptoError::KeyLengthError) - } - } -} - -impl core::str::FromStr for PublicKey { - type Err = MeshcoreCryptoError; - - fn from_str(hex_str: &str) -> Result<Self, Self::Err> { - if let Ok(hex) = hex::decode(hex_str) { - if let Ok(slice) = <[u8; 32]>::try_from(hex) { - Self::try_from(&slice) - } else { - Err(MeshcoreCryptoError::KeyLengthError) - } - } else { - Err(MeshcoreCryptoError::HexDecodeError) - } - } -} - -impl core::str::FromStr for PrivateKey { - type Err = MeshcoreCryptoError; - - fn from_str(hex_str: &str) -> Result<Self, Self::Err> { - if let Ok(hex) = hex::decode(hex_str) { - if let Ok(bytes) = <[u8; 32]>::try_from(hex) { - Ok(PrivateKey(bytes)) - } else { - Err(MeshcoreCryptoError::TryFromSliceError) - } - } else { - Err(MeshcoreCryptoError::HexDecodeError) - } - } -} - -impl From<&PrivateKey> for PublicKey { - fn from(key: &PrivateKey) -> Self { - Self(key.0.clone()) - } -} - -impl PrivateKey { - pub fn create_secret(&self, _other: &PublicKey) -> SharedSecret { - SharedSecret(self.0) - } -} - -impl SharedSecret { - pub fn mac_then_decrypt(&self, mac: u16, data: &Bytes) -> Option<Bytes> { - // Get the MAC of the message and key to check vailidity - let our_mac = self.get_hmac(&data); - if our_mac != mac { - return None; - } - - // Attempt to decrypt the packet itself - Some(self.decrypt(&data)) - } - - pub fn encrypt_then_mac(&self, data: Bytes) -> (u16, Bytes) { - let ciphertext = self.encrypt(data); - let mac = self.get_hmac(&ciphertext); - (mac, ciphertext) - } -} diff --git a/src/packet.rs b/src/packet.rs index 86537a7..b1be782 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -1,12 +1,11 @@ -#[cfg(feature = "std")] -use crate::std_identity::Keystore; - +extern crate alloc; +use alloc::borrow::ToOwned; use bytes::{Buf, Bytes}; use tinyvec::ArrayVec; +use crate::crypto::Keystore; use crate::packet_content::PacketContent; -#[cfg(feature = "std")] use crate::{ anon_req::ClearAnonRequest, request::ClearRequest, response::ClearResponse, text::ClearText, }; @@ -201,8 +200,7 @@ impl core::fmt::Display for Packet { } impl Packet { - #[cfg(feature = "std")] - pub fn try_decrypt(&mut self, keystore: &Keystore) -> bool { + pub fn try_decrypt<T: Keystore>(&mut self, keystore: &T) -> bool { match self.content { // Encrypted packet types PacketContent::Path(ref mut path) => path.cipher.try_decrypt(keystore), diff --git a/src/packet_content.rs b/src/packet_content.rs index a6fa914..5b762d7 100644 --- a/src/packet_content.rs +++ b/src/packet_content.rs @@ -11,8 +11,7 @@ use crate::{ }; use bytes::{Buf, Bytes}; -#[cfg(feature = "std")] -use crate::std_identity::Keystore; +use crate::crypto::Keystore; #[derive(PartialEq, Clone, core::fmt::Debug)] pub enum PacketContent { @@ -152,8 +151,7 @@ impl From<Bytes> for PeerToPeerCipher { } impl PeerToPeerCipher { - #[cfg(feature = "std")] - pub fn try_decrypt(&mut self, keystore: &Keystore) -> bool { + pub fn try_decrypt<T: Keystore>(&mut self, keystore: &T) -> bool { let decrypt = keystore.decrypt_and_id_p2p(self.source, self.destination, self.mac, &self.ciphertext); diff --git a/src/text.rs b/src/text.rs index 60d8869..e9efc2e 100644 --- a/src/text.rs +++ b/src/text.rs @@ -6,8 +6,7 @@ use crate::string_helper::{ MessageString, NameString, message_string_from_slice, name_string_from_slice, }; -#[cfg(feature = "std")] -use crate::std_identity::Keystore; +use crate::crypto::Keystore; #[derive(PartialEq, Debug, Clone)] pub struct Text { @@ -173,13 +172,13 @@ impl From<Bytes> for GroupText { } impl GroupText { - #[cfg(feature = "std")] - pub fn try_decrypt(&mut self, keysore: &Keystore) -> bool { + pub fn try_decrypt<T: Keystore>(&mut self, keysore: &T) -> bool { let decrypt_result = keysore.decrypt_and_id_group(self.hash, self.mac, &self.ciphertext); if let Some((cleartext, group)) = decrypt_result { let mut cleartext = ClearText::from(cleartext); - cleartext.crypto_recipient = group; + // @TODO: what? + // cleartext.crypto_recipient = group; self.cleartext = Some(cleartext); true } else { |
