Repo build was broken
+ Fix github actions + Update to last clippy checks + Update sodiumoxide dependency + Fix test_msg_with_float_mantissa test Co-authored-by: mycognosist <gnomad@cryptolab.net>
This commit is contained in:
parent
9411e72d86
commit
af1a18ad7e
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -2,14 +2,14 @@
|
|||
name = "kuska-ssb"
|
||||
version = "0.2.0"
|
||||
authors = ["Dhole <dhole@riseup.net>", "Adria Massanet <adria@codecontext.io>"]
|
||||
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"] }
|
||||
|
|
|
@ -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<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
cargo test
|
||||
cargo fmt --all
|
||||
cargo clippy
|
||||
cargo clippy --all --all-features
|
||||
cargo +nightly udeps
|
||||
cargo audit
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -67,57 +67,57 @@ impl<K> Default for CreateStreamIn<K> {
|
|||
}
|
||||
|
||||
impl<K> CreateStreamIn<K> {
|
||||
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
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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<ed25519::PublicKey> {
|
||||
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<ed25519::SecretKey> {
|
||||
|
@ -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<ed25519::SecretKey> {
|
||||
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<sha256::Digest> {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::crypto::ToSodiumObject;
|
||||
use sodiumoxide::crypto::sign::ed25519;
|
||||
use kuska_sodiumoxide::crypto::sign::ed25519;
|
||||
|
||||
use super::error::{Error, Result};
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ impl Feed {
|
|||
}
|
||||
}
|
||||
pub fn from_slice(s: &[u8]) -> Result<Self> {
|
||||
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 {
|
||||
|
|
|
@ -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<sha256::Digest> {
|
||||
let v8encoding = stringify_json(&v)?
|
||||
let v8encoding = stringify_json(v)?
|
||||
.encode_utf16()
|
||||
.map(|ch_u16| (ch_u16 & 0xff) as u8)
|
||||
.collect::<Vec<u8>>();
|
||||
|
@ -27,7 +27,7 @@ pub fn stringify_json(v: &Value) -> Result<String> {
|
|||
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<String> {
|
|||
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<String> {
|
|||
}
|
||||
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<String> {
|
|||
Ok(())
|
||||
}
|
||||
let mut result = String::new();
|
||||
append_json(&mut result, 0, &v)?;
|
||||
append_json(&mut result, 0, v)?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
|
|
|
@ -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> {
|
||||
Self::from_value(serde_json::from_slice(&s)?)
|
||||
Self::from_value(serde_json::from_slice(s)?)
|
||||
}
|
||||
|
||||
pub fn from_value(v: Value) -> Result<Self> {
|
||||
|
@ -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<Self, Self::Err> {
|
||||
Message::from_value(serde_json::from_str::<Value>(&s)?)
|
||||
Message::from_value(serde_json::from_str::<Value>(s)?)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String>
|
|||
|
||||
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<Option<St
|
|||
let msg = &ciphertext.as_bytes()[..ciphertext.len() - SUFFIX.len()];
|
||||
let msg = base64::decode(msg)?;
|
||||
|
||||
let plaintext = decipher(&msg, &sk)?.map(|msg| String::from_utf8_lossy(&msg).to_string());
|
||||
let plaintext = decipher(&msg, sk)?.map(|msg| String::from_utf8_lossy(&msg).to_string());
|
||||
|
||||
Ok(plaintext)
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ fn cipher(plaintext: &[u8], recipients: &[&ed25519::PublicKey]) -> Result<Box<[u
|
|||
let (h_pk, h_sk) = ed25519::gen_keypair();
|
||||
|
||||
// Generated random 32-byte secret key used to encrypt the message body
|
||||
let y = sodiumoxide::crypto::secretbox::gen_key();
|
||||
let y = kuska_sodiumoxide::crypto::secretbox::gen_key();
|
||||
|
||||
// Encrypt the plaintext with y, with a random nonce
|
||||
let nonce = secretbox::gen_nonce();
|
||||
|
@ -82,7 +82,7 @@ fn cipher(plaintext: &[u8], recipients: &[&ed25519::PublicKey]) -> Result<Box<[u
|
|||
buffer.extend_from_slice(&h_pk.to_curve25519()[..]);
|
||||
|
||||
for recipient in recipients {
|
||||
let key = curve25519::scalarmult(&h_sk_scalar, &recipient.to_curve25519())
|
||||
let key = curve25519::scalarmult(h_sk_scalar, &recipient.to_curve25519())
|
||||
.map_err(|_| Error::CryptoScalarMultFailed)?;
|
||||
|
||||
let key = secretbox::Key::from_slice(&key[..]).ok_or(Error::CryptoKeyFromGrupFailed)?;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::crypto::CURVE_ED25519_SUFFIX;
|
||||
use sodiumoxide::crypto::sign::ed25519;
|
||||
use kuska_sodiumoxide::crypto::sign::ed25519;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct OwnedIdentity {
|
||||
|
|
|
@ -279,10 +279,7 @@ impl<W: io::Write + Unpin> RpcWriter<W> {
|
|||
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,
|
||||
|
|
Loading…
Reference in New Issue