Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
24a4a80
replace `sodiumoxide` with `chacha20` and `poly1305` crates
DougAnderson444 Aug 8, 2024
3f14392
make ssh-key optional
DougAnderson444 Aug 12, 2024
7071e29
start multisig patch
DougAnderson444 Aug 13, 2024
641bf17
place `ssh` behind feature flag
DougAnderson444 Aug 13, 2024
3ca44cc
Merge branch 'switch-chacha20' into feature-ssh
DougAnderson444 Aug 13, 2024
41929cc
use ed25519_dalek instead of ssh-key
DougAnderson444 Aug 13, 2024
3350013
make deps direct to douganderson444 repo branch
DougAnderson444 Aug 13, 2024
5295c02
update gh actions CI
DougAnderson444 Aug 25, 2024
2329d2d
`ssh-key` no-default-features for `wasm32-*` builds
DougAnderson444 Aug 25, 2024
343864e
rm dup runs-on
DougAnderson444 Aug 25, 2024
3746df5
Update rust.yml
DougAnderson444 Aug 25, 2024
d194cdd
allow manual github workflow dispatch
DougAnderson444 Aug 25, 2024
d514e91
add getrandom/js dep for CI build
DougAnderson444 Aug 25, 2024
d32aa65
switch back to cryptid repo
DougAnderson444 Aug 27, 2024
342359a
Merge remote-tracking branch 'upstream/main' into wasm32-pure-doug
DougAnderson444 Aug 27, 2024
84cc004
chacha20poly1305 is 32 byte key, 12 bytes nonce
DougAnderson444 Aug 27, 2024
f78c88d
rm println
DougAnderson444 Aug 27, 2024
ce8f2af
comment about why wasm feature is present
DougAnderson444 Aug 27, 2024
9e11324
fix comment typo
DougAnderson444 Aug 27, 2024
f9746b7
Merge remote-tracking branch 'upstream/main' into switch-chacha20
DougAnderson444 Aug 28, 2024
f5fde90
Revert "Merge remote-tracking branch 'upstream/main' into switch-chac…
DougAnderson444 Aug 28, 2024
3b89dc2
redo clippy fixes
DougAnderson444 Aug 28, 2024
f479bd4
use `from(mk: Multikey)`
DougAnderson444 Aug 30, 2024
b1b73aa
v1.0.7
DougAnderson444 Sep 6, 2024
182c01f
use matches!
DougAnderson444 Sep 6, 2024
4897852
use vec!, and other clippy and rustfmt chgs
DougAnderson444 Sep 6, 2024
6eb6665
add missing rustdoc comments
DougAnderson444 Sep 6, 2024
1fc668c
use `to_owned()`
DougAnderson444 Sep 6, 2024
0335c53
multikey from seed + test (Ed25519 only for now)
DougAnderson444 Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 60 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Rust
name: Rust

on:
workflow_dispatch:
push:
branches: [ "main" ]
pull_request:
Expand All @@ -11,12 +12,64 @@ env:

jobs:
build:
strategy:
matrix:
include:
# Linux (32-bit)
- target: i686-unknown-linux-gnu
platform: ubuntu-latest
rust: stable
deps: sudo apt update && sudo apt install gcc-multilib

runs-on: ubuntu-latest
# macOS (64-bit)
- target: x86_64-apple-darwin
platform: macos-latest
rust: stable

# Windows (64-bit)
- target: x86_64-pc-windows-msvc
platform: windows-latest
rust: stable
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- run: ${{ matrix.deps }}
- run: cargo build --target ${{ matrix.target }} --release --all-features

wasm_builds:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- 1.73.0 # MSRV
- stable
target:
- wasm32-wasi
- wasm32-unknown-unknown
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- run: cargo build --target ${{ matrix.target }} --features wasm

test:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- 1.73.0 # MSRV
- stable
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
- run: cargo test --verbose --release
- run: cargo test --all-features # debug build
- run: cargo test --release --all-features --all-targets
27 changes: 21 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license = "Apache-2.0"

[features]
default = ["serde"]
wasm = ["getrandom/js"] # needed for CI testing on wasm32-unknown-unknown

[dependencies]
bcrypt-pbkdf = "0.10"
Expand All @@ -21,20 +22,34 @@ k256 = "0.13"
multibase = { version = "1.0", git = "https://github.com/cryptidtech/rust-multibase.git" }
multicodec = { version = "1.0", git = "https://github.com/cryptidtech/rust-multicodec.git" }
multihash = { version = "1.0", git = "https://github.com/cryptidtech/multihash.git" }
multisig = { version = "1.0", git = "https://github.com/cryptidtech/multisig.git" }
multisig = { version = "^1.0", git = "https://github.com/cryptidtech/multisig.git" }
multitrait = { version = "1.0", git = "https://github.com/cryptidtech/multitrait.git" }
multiutil = { version = "1.0", git = "https://github.com/cryptidtech/multiutil.git" }
rand = "0.8"
sec1 = "0.7"
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"], optional = true }
sodiumoxide = "0.2"
ssh-key = { version = "0.6", features = ["alloc", "crypto", "ed25519"]}
ssh-encoding = "0.2"
serde = { version = "1.0", default-features = false, features = [
"alloc",
"derive",
], optional = true }
chacha20 = "0.9"
poly1305 = "0.8"
thiserror = "1.0"
typenum = "1.17"
unsigned-varint = { version = "0.8", features = ["std"]}
unsigned-varint = { version = "0.8", features = ["std"] }
vsss-rs = "3.4"
zeroize = "1.7"
ssh-encoding = { version = "0.2" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
ssh-key = { version = "0.6", default-features = false, features = [
"alloc",
"ecdsa",
"ed25519",
] }
getrandom = { version = "0.2", features = ["js"], optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ssh-key = { version = "0.6", features = ["alloc", "crypto", "ed25519"] }

[dev-dependencies]
serde_test = "1.0"
Expand Down
5 changes: 3 additions & 2 deletions src/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ mod tests {
.try_build()
.unwrap();

let nonce = hex::decode("00b61a43d4d1e8d7").unwrap();
// ChaCha needs 12 bytes of nonce iaw RFC8439
let nonce = hex::decode("00b61a43d4d1e8d700b61a43").unwrap();
// create a cipher multikey
let ciphermk = Builder::new(Codec::Chacha20Poly1305)
.with_nonce(&nonce)
Expand All @@ -110,7 +111,7 @@ mod tests {
.unwrap();

// generate a random secret key
let mut rng = rand::rngs::OsRng::default();
let mut rng = rand::rngs::OsRng;
let mk = mk::Builder::new_from_random_bytes(Codec::Ed25519Priv, &mut rng)
.unwrap()
.with_comment("test key")
Expand Down
51 changes: 44 additions & 7 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,7 @@ pub enum AttributesError {
pub enum ConversionsError {
/// Ssh key error
#[error(transparent)]
SshKey(#[from] ssh_key::Error),
/// Ssh key label error
#[error(transparent)]
SshKeyLabel(#[from] ssh_encoding::LabelError),
/// Ssh encoding error
#[error(transparent)]
SshEncoding(#[from] ssh_encoding::Error),
Ssh(#[from] SshErrors),
/// Public key operation failure
#[error("Public key error: {0}")]
PublicKeyFailure(String),
Expand All @@ -124,6 +118,49 @@ pub enum ConversionsError {
UnsupportedCodec(multicodec::Codec),
}

/// SSH Encoding Errors that cannot be handled by thiserror since they may not use the std feature
/// in the case of wasm32 target.
#[derive(Clone, Debug)]
pub enum SshErrors {
/// Error from [ssh_key::Error]
Key(ssh_key::Error),
/// Invalid label from [ssh_encoding::LabelError]
KeyLabel(ssh_encoding::LabelError),
/// Unexpected trailing data at end of message from [ssh_encoding::Error]
Encoding(ssh_encoding::Error),
}

/// Impl Display for EncodingError
impl std::fmt::Display for SshErrors {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SshErrors::Key(err) => write!(f, "{}", err),
SshErrors::KeyLabel(err) => write!(f, "{}", err),
SshErrors::Encoding(err) => write!(f, "{}", err),
}
}
}

impl std::error::Error for SshErrors {}

impl From<ssh_encoding::Error> for SshErrors {
fn from(err: ssh_encoding::Error) -> Self {
SshErrors::Encoding(err)
}
}

impl From<ssh_key::Error> for SshErrors {
fn from(err: ssh_key::Error) -> Self {
SshErrors::Key(err)
}
}

impl From<ssh_encoding::LabelError> for SshErrors {
fn from(err: ssh_encoding::LabelError) -> Self {
SshErrors::KeyLabel(err)
}
}

/// Cipher errors created by this library
#[derive(Clone, Debug, thiserror::Error)]
#[non_exhaustive]
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Idnetifier: Apache-2.0
//! multikey
//! Multikey Crate
#![warn(missing_docs)]
#![deny(
trivial_casts,
Expand Down Expand Up @@ -31,7 +31,7 @@ pub use views::{

/// Multikey type and functions
pub mod mk;
pub use mk::{KEY_CODECS, KEY_SHARE_CODECS, Builder, EncodedMultikey, Multikey};
pub use mk::{Builder, EncodedMultikey, Multikey, KEY_CODECS, KEY_SHARE_CODECS};

/// Nonce type
pub mod nonce;
Expand Down
Loading