Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
596 changes: 503 additions & 93 deletions src/cipher.rs

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ use snow::{
};
use std::convert::TryInto;

/// Create a [`snow::Keypair`] from secret and public key bytes.
/// Note: `snow::Keypair` just holds `Vec<u8>`s. So we don't check the size. But giving it the
/// wrong size is bad.
pub fn snow_keypair_from_secret_and_public(secret: [u8; 32], public: [u8; 32]) -> snow::Keypair {
snow::Keypair {
private: secret.to_vec(),
public: public.to_vec(),
}
}

// NB: These values come from Javascript-side
//
// const [NS_INITIATOR, NS_RESPONDER] = crypto.namespace('hyperswarm/secret-stream', 2)
Expand Down
6 changes: 6 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ pub enum Error {
/// Error from [`std::io`]
#[error("{0}")]
StdIoError(#[from] std::io::Error),
/// Remote public key required for IK pattern
#[error("IK pattern requires remote public key")]
MissingRemoteKey,
/// Remote public key not expected for XX pattern
#[error("XX pattern does not use remote public key at initialization")]
UnexpectedRemoteKey,
}

impl From<crypto_secretstream::aead::Error> for Error {
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ mod crypto;
mod error;
pub mod state_machine;

pub use cipher::{Cipher, CipherIo, Event as CipherEvent};
pub use cipher::{Cipher, CipherIo, CipherTrait, Event as CipherEvent};
pub use crypto::snow_keypair_from_secret_and_public;
pub use error::Error;
pub use state_machine::{HandshakePattern, IK, XX};
Loading
Loading