diff --git a/.github/workflows/clippy.yaml b/.github/workflows/clippy.yaml deleted file mode 100644 index 9fbe9db..0000000 --- a/.github/workflows/clippy.yaml +++ /dev/null @@ -1,13 +0,0 @@ -on: [push] - -name: Clippy check -jobs: - clippy_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - run: rustup component add clippy - - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-features -- -D warnings diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml deleted file mode 100644 index 4abdd97..0000000 --- a/.github/workflows/rust.yaml +++ /dev/null @@ -1,16 +0,0 @@ - -name: Rust - -on: [push] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose diff --git a/.github/workflows/rustfmt.yaml b/.github/workflows/rustfmt.yaml deleted file mode 100644 index bc7edf4..0000000 --- a/.github/workflows/rustfmt.yaml +++ /dev/null @@ -1,15 +0,0 @@ -name: Rustfmt - -on: [push] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - name: Install rustfmt - run: rustup component add rustfmt - - name: Check style - run: cargo fmt --all -- --check --config=merge_imports=true diff --git a/Cargo.toml b/Cargo.toml index a4bd531..6c91f60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,14 +2,14 @@ name = "kuska-ssb" version = "0.2.0" authors = ["Dhole ", "Adria Massanet "] -edition = "2018" +edition = "2021" [lib] name = "kuska_ssb" [dependencies] -kuska-handshake = { git = "https://github.com/Kuska-ssb/handshake", branch = "master" , features=["sync","async_std"] } -sodiumoxide = { git = "https://github.com/Dhole/sodiumoxidez", branch = "extra" } +kuska-handshake = { version="0.2", features=["sync","async_std"] } +kuska-sodiumoxide = "0.2.5-0" base64 = "0.11.0" hex = "0.4.0" async-std = { version = "1.5.0", features=["unstable","attributes"] } diff --git a/examples/ssb-cli.rs b/examples/ssb-cli.rs index ea4cf95..cf34591 100644 --- a/examples/ssb-cli.rs +++ b/examples/ssb-cli.rs @@ -25,8 +25,8 @@ use kuska_ssb::{ rpc::{RecvMsg, RequestNo, RpcReader, RpcWriter}, }; +use kuska_sodiumoxide::crypto::sign::ed25519; use regex::Regex; -use sodiumoxide::crypto::sign::ed25519; use structopt::StructOpt; type Result = std::result::Result>; diff --git a/pre_commit.sh b/pre_commit.sh index 4da677f..05571d1 100755 --- a/pre_commit.sh +++ b/pre_commit.sh @@ -1,5 +1,5 @@ cargo test cargo fmt --all -cargo clippy +cargo clippy --all --all-features cargo +nightly udeps cargo audit diff --git a/src/api/dto/blobs.rs b/src/api/dto/blobs.rs index fdb17fa..14176bb 100644 --- a/src/api/dto/blobs.rs +++ b/src/api/dto/blobs.rs @@ -20,13 +20,13 @@ impl BlobsGetIn { max: None, } } - pub fn size(self: Self, size: u64) -> Self { + pub fn size(self, size: u64) -> Self { Self { size: Some(size), ..self } } - pub fn max(self: Self, max: u64) -> Self { + pub fn max(self, max: u64) -> Self { Self { max: Some(max), ..self diff --git a/src/api/dto/history_stream.rs b/src/api/dto/history_stream.rs index d64bba3..c0753b0 100644 --- a/src/api/dto/history_stream.rs +++ b/src/api/dto/history_stream.rs @@ -34,26 +34,26 @@ impl CreateHistoryStreamIn { limit: None, } } - pub fn after_seq(self: Self, seq: u64) -> Self { + pub fn after_seq(self, seq: u64) -> Self { Self { seq: Some(seq), ..self } } - pub fn live(self: Self, live: bool) -> Self { + pub fn live(self, live: bool) -> Self { Self { live: Some(live), ..self } } - pub fn keys_values(self: Self, keys: bool, values: bool) -> Self { + pub fn keys_values(self, keys: bool, values: bool) -> Self { Self { keys: Some(keys), values: Some(values), ..self } } - pub fn limit(self: Self, limit: i64) -> Self { + pub fn limit(self, limit: i64) -> Self { Self { limit: Some(limit), ..self diff --git a/src/api/dto/stream.rs b/src/api/dto/stream.rs index b1a8d05..e4bf235 100644 --- a/src/api/dto/stream.rs +++ b/src/api/dto/stream.rs @@ -67,57 +67,57 @@ impl Default for CreateStreamIn { } impl CreateStreamIn { - pub fn live(self: Self, live: bool) -> Self { + pub fn live(self, live: bool) -> Self { Self { live: Some(live), ..self } } - pub fn gt(self: Self, v: K) -> Self { + pub fn gt(self, v: K) -> Self { Self { gt: Some(v), ..self } } - pub fn gte(self: Self, v: K) -> Self { + pub fn gte(self, v: K) -> Self { Self { gte: Some(v), ..self } } - pub fn lt(self: Self, v: K) -> Self { + pub fn lt(self, v: K) -> Self { Self { lt: Some(v), ..self } } - pub fn lte(self: Self, v: K) -> Self { + pub fn lte(self, v: K) -> Self { Self { lte: Some(v), ..self } } - pub fn reverse(self: Self, reversed: bool) -> Self { + pub fn reverse(self, reversed: bool) -> Self { Self { reverse: Some(reversed), ..self } } - pub fn keys_values(self: Self, keys: bool, values: bool) -> Self { + pub fn keys_values(self, keys: bool, values: bool) -> Self { Self { keys: Some(keys), values: Some(values), ..self } } - pub fn encoding(self: Self, keys: String, values: String) -> Self { + pub fn encoding(self, keys: String, values: String) -> Self { Self { key_encoding: Some(keys), value_encoding: Some(values), ..self } } - pub fn limit(self: Self, limit: i64) -> Self { + pub fn limit(self, limit: i64) -> Self { Self { limit: Some(limit), ..self diff --git a/src/crypto/mod.rs b/src/crypto/mod.rs index 8cc6d6d..91abf2d 100644 --- a/src/crypto/mod.rs +++ b/src/crypto/mod.rs @@ -2,7 +2,7 @@ mod error; mod sodium; pub use error::{Error, Result}; +pub use kuska_sodiumoxide::crypto::{hash::sha256, sign::ed25519}; pub use sodium::{ ToSodiumObject, ToSsbId, CURVE_ED25519_SUFFIX, ED25519_SIGNATURE_SUFFIX, SHA256_SUFFIX, }; -pub use sodiumoxide::crypto::{hash::sha256, sign::ed25519}; diff --git a/src/crypto/sodium.rs b/src/crypto/sodium.rs index 57166b4..bd16503 100644 --- a/src/crypto/sodium.rs +++ b/src/crypto/sodium.rs @@ -1,4 +1,4 @@ -use sodiumoxide::crypto::{hash::sha256, sign::ed25519}; +use kuska_sodiumoxide::crypto::{hash::sha256, sign::ed25519}; use super::error::{Error, Result}; @@ -46,12 +46,12 @@ impl ToSodiumObject for str { let key_len = self.len() - CURVE_ED25519_SUFFIX.len(); let bytes = base64::decode(&self[..key_len])?; - ed25519::PublicKey::from_slice(&bytes).ok_or_else(|| Error::BadPublicKey) + ed25519::PublicKey::from_slice(&bytes).ok_or(Error::BadPublicKey) } fn to_ed25519_pk_no_suffix(self: &str) -> Result { let bytes = base64::decode(&self)?; - ed25519::PublicKey::from_slice(&bytes).ok_or_else(|| Error::BadPublicKey) + ed25519::PublicKey::from_slice(&bytes).ok_or(Error::BadPublicKey) } fn to_ed25519_sk(self: &str) -> Result { @@ -62,13 +62,13 @@ impl ToSodiumObject for str { let key_len = self.len() - CURVE_ED25519_SUFFIX.len(); let bytes = base64::decode(&self[..key_len])?; - ed25519::SecretKey::from_slice(&bytes).ok_or_else(|| Error::BadSecretKey) + ed25519::SecretKey::from_slice(&bytes).ok_or(Error::BadSecretKey) } fn to_ed25519_sk_no_suffix(self: &str) -> Result { - let bytes = base64::decode(&self[..])?; + let bytes = base64::decode(self)?; - ed25519::SecretKey::from_slice(&bytes).ok_or_else(|| Error::BadSecretKey) + ed25519::SecretKey::from_slice(&bytes).ok_or(Error::BadSecretKey) } fn to_sha256(self: &str) -> Result { diff --git a/src/discovery/lan.rs b/src/discovery/lan.rs index e5d8fa1..c216d05 100644 --- a/src/discovery/lan.rs +++ b/src/discovery/lan.rs @@ -71,7 +71,7 @@ impl LanBroadcast { pub fn parse(msg: &str) -> Option<(String, u32, ed25519::PublicKey)> { let parse_shs = |addr: &str| -> Result<_> { let captures = BROADCAST_REGEX - .captures(&addr) + .captures(addr) .ok_or(Error::InvalidBroadcastMessage)?; let ip = captures[1].to_string(); diff --git a/src/discovery/network.rs b/src/discovery/network.rs index 6f3205c..09e5b47 100644 --- a/src/discovery/network.rs +++ b/src/discovery/network.rs @@ -1,4 +1,4 @@ -use sodiumoxide::crypto::auth; +use kuska_sodiumoxide::crypto::auth; pub const SSB_NET_ID: &str = "d4a1cb88a66f02f8db635ce26441cc5dac1b08420ceaac230839b755845a9ffb"; pub fn ssb_net_id() -> auth::Key { diff --git a/src/discovery/pubs.rs b/src/discovery/pubs.rs index abbaaf5..34d0ac8 100644 --- a/src/discovery/pubs.rs +++ b/src/discovery/pubs.rs @@ -1,5 +1,5 @@ use crate::crypto::ToSodiumObject; -use sodiumoxide::crypto::sign::ed25519; +use kuska_sodiumoxide::crypto::sign::ed25519; use super::error::{Error, Result}; diff --git a/src/feed/base.rs b/src/feed/base.rs index 898752f..987b536 100644 --- a/src/feed/base.rs +++ b/src/feed/base.rs @@ -39,7 +39,7 @@ impl Feed { } } pub fn from_slice(s: &[u8]) -> Result { - let feed: Feed = serde_json::from_slice(&s)?; + let feed: Feed = serde_json::from_slice(s)?; let digest = format!("%{}.sha256", base64::encode(&ssb_sha256(&feed.value)?)); if digest != feed.key { diff --git a/src/feed/encoding.rs b/src/feed/encoding.rs index db8f94b..114fcfe 100644 --- a/src/feed/encoding.rs +++ b/src/feed/encoding.rs @@ -1,9 +1,9 @@ use super::error::Result; +use kuska_sodiumoxide::crypto::hash::sha256; use serde_json::Value; -use sodiumoxide::crypto::hash::sha256; pub fn ssb_sha256(v: &Value) -> Result { - let v8encoding = stringify_json(&v)? + let v8encoding = stringify_json(v)? .encode_utf16() .map(|ch_u16| (ch_u16 & 0xff) as u8) .collect::>(); @@ -27,7 +27,7 @@ pub fn stringify_json(v: &Value) -> Result { buffer.push_str(spaces(level + 1)); buffer.push_str(&serde_json::to_string(&key)?); buffer.push_str(": "); - append_json(buffer, level + 1, &value)?; + append_json(buffer, level + 1, value)?; if i < values.len() - 1 { buffer.push(','); } @@ -44,7 +44,7 @@ pub fn stringify_json(v: &Value) -> Result { buffer.push_str("[\n"); for (i, value) in values.iter().enumerate() { buffer.push_str(spaces(level + 1)); - append_json(buffer, level + 1, &value)?; + append_json(buffer, level + 1, value)?; if i < values.len() - 1 { buffer.push(','); } @@ -59,7 +59,7 @@ pub fn stringify_json(v: &Value) -> Result { } Value::Number(value) => { let mut as_str = value.to_string(); - if as_str.contains('e') && !as_str.contains("e-") { + if as_str.contains('e') && !as_str.contains("e-") && !as_str.contains("e+") { as_str = as_str.replace("e", "e+") } buffer.push_str(&as_str); @@ -74,7 +74,7 @@ pub fn stringify_json(v: &Value) -> Result { Ok(()) } let mut result = String::new(); - append_json(&mut result, 0, &v)?; + append_json(&mut result, 0, v)?; Ok(result) } diff --git a/src/feed/message.rs b/src/feed/message.rs index 1717ddc..c1f03be 100644 --- a/src/feed/message.rs +++ b/src/feed/message.rs @@ -1,14 +1,14 @@ use std::{str::FromStr, time::SystemTime}; +use kuska_sodiumoxide::crypto::sign::ed25519; use serde_json::Value; -use sodiumoxide::crypto::sign::ed25519; use super::{ error::{Error, Result}, ssb_sha256, stringify_json, }; use crate::{crypto::ToSodiumObject, keystore::OwnedIdentity}; -use sodiumoxide::crypto::hash::sha256; +use kuska_sodiumoxide::crypto::hash::sha256; const MSG_PREVIOUS: &str = "previous"; const MSG_AUTHOR: &str = "author"; @@ -23,7 +23,7 @@ macro_rules! cast { match $input { Some($pth(x)) => Ok(x), _ => Err(Error::InvalidJson), - }; + } }; } @@ -34,7 +34,7 @@ macro_rules! cast_opt { Some(Value::Null) => Ok(None), Some($pth(x)) => Ok(Some(x)), _ => Err(Error::InvalidJson), - }; + } }; } @@ -104,7 +104,7 @@ impl Message { } pub fn from_slice(s: &[u8]) -> Result { - Self::from_value(serde_json::from_slice(&s)?) + Self::from_value(serde_json::from_slice(s)?) } pub fn from_value(v: Value) -> Result { @@ -126,7 +126,7 @@ impl Message { let value = Value::Object(v); let signed_text = stringify_json(&value)?; - if !ed25519::verify_detached(&sig, &signed_text.as_ref(), &signer) { + if !ed25519::verify_detached(&sig, signed_text.as_ref(), &signer) { return Err(Error::InvalidSignature); } @@ -181,7 +181,7 @@ impl FromStr for Message { type Err = Error; fn from_str(s: &str) -> std::result::Result { - Message::from_value(serde_json::from_str::(&s)?) + Message::from_value(serde_json::from_str::(s)?) } } diff --git a/src/feed/privatebox.rs b/src/feed/privatebox.rs index 6ee2d8d..2359fea 100644 --- a/src/feed/privatebox.rs +++ b/src/feed/privatebox.rs @@ -1,6 +1,6 @@ use crate::crypto::ToSodiumObject; -use sodiumoxide::crypto::{ +use kuska_sodiumoxide::crypto::{ scalarmult::curve25519, secretbox, sign::{ed25519, SecretKey}, @@ -27,7 +27,7 @@ pub fn privatebox_cipher(plaintext: &str, recipients: &[&str]) -> Result let recipients = recipients?; - let recipients_ref: Vec<_> = recipients.iter().map(|r| r).collect(); + let recipients_ref: Vec<_> = recipients.iter().collect(); let ciphertext = cipher(plaintext.as_bytes(), &recipients_ref[..])?; @@ -38,7 +38,7 @@ pub fn privatebox_decipher(ciphertext: &str, sk: &SecretKey) -> Result Result Result RpcWriter { message, })?; - let is_stream = match rpc_type { - RpcType::Async => false, - _ => true, - }; + let is_stream = !matches!(rpc_type, RpcType::Async); let rpc_header = Header { req_no: -req_no,