Skip to content

Commit ade402b

Browse files
committed
Fix all the warnings
1 parent c27a563 commit ade402b

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed

src/error.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1+
/// Error type for this crate
12
#[derive(Debug, thiserror::Error)]
23
pub enum Error {
4+
/// Error from the [`snow`] crate
35
#[error("Error from `snow`: {0}")]
46
Snow(#[from] snow::Error),
7+
/// Error from [`crypto_secretstream`] crate
58
#[error("Error from `crypto_secretstream`: {0}")]
69
SecretStream(crypto_secretstream::aead::Error),
10+
/// [`crate::sstream::statemachine::Manager`] handshake invalid state. TODO remove with
11+
/// statemachine?
712
#[error("Invalid Handshake State: {0}")]
813
InvalidHandshakeState(String),
9-
// TODO added by claude
10-
#[error("Invalid Encryption Statemachine State: {0}")]
11-
InvalidState(String),
12-
// TODO added by claude
13-
#[error("IoError: {0}")]
14-
IoError(String),
15-
// Missing IO
14+
/// Missing IO in [`crate::sstream::sm2::Machine`]
1615
#[error("Machine IO is not set.")]
1716
NoIoSetError,
17+
/// Error from [`std::io`]
1818
#[error("{0}")]
1919
StdIoError(#[from] std::io::Error),
2020
}

src/sstream/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ impl Debug for Ready {
146146
.finish()
147147
}
148148
}
149-
150149
pub mod hc_specific {
150+
//! Stuff for generating Hypercore specific things like Noise parameters, keys, etc
151151
use std::sync::LazyLock;
152152

153153
use snow::{
@@ -163,7 +163,6 @@ pub mod hc_specific {
163163
static NOISE_PARAMS: LazyLock<NoiseParams> = LazyLock::new(|| {
164164
NoiseParams::new(
165165
PARAM_STR.to_string(),
166-
//PARAMS.to_string(),
167166
BaseChoice::Noise,
168167
HandshakeChoice {
169168
pattern: HandshakePattern::IK,

src/sstream/sm2.rs

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Interface for an encrypted channel
12
use std::{
23
collections::VecDeque,
34
fmt::Debug,
@@ -198,15 +199,18 @@ impl SansIoMachine {
198199
Ok(made_progress.then_some(()))
199200
}
200201

202+
#[allow(unused, reason = "vectorized version of 'get_next_sendable_message'")]
201203
fn get_sendable_messages(&mut self) -> Result<Vec<Vec<u8>>, IoError> {
202204
self.poll_all_enc_dec()?;
203205
Ok(self.encrypted_tx.drain(..).collect())
204206
}
207+
205208
fn get_next_sendable_message(&mut self) -> Result<Option<Vec<u8>>, IoError> {
206209
self.poll_all_enc_dec()?;
207210
Ok(self.encrypted_tx.pop_front())
208211
}
209212

213+
#[allow(unused, reason = "vectorized version of 'receive_next'")]
210214
fn receive_next_messages(&mut self, encrypted_messages: Vec<Vec<u8>>) {
211215
self.encrypted_rx
212216
.extend(encrypted_messages.into_iter().map(Ok));
@@ -216,6 +220,7 @@ impl SansIoMachine {
216220
self.encrypted_rx.push_back(Ok(encrypted_msg));
217221
}
218222

223+
#[allow(unused, reason = "add a new plaintext message to send")]
219224
fn queue_msg(&mut self, msg: Vec<u8>) {
220225
self.plain_tx.push_back(msg);
221226
}
@@ -243,12 +248,17 @@ impl Debug for SansIoMachine {
243248
}
244249

245250
#[derive(Debug)]
251+
/// Encryption event
246252
pub enum Event {
253+
/// Data passed through the handshake payload
247254
HandshakePayload(Vec<u8>),
255+
/// Decrypted message
248256
Message(Vec<u8>),
257+
/// Error occured in encryption
249258
ErrStuff(IoError),
250259
}
251260

261+
/// Supertrait for duplex channel required by [`Machine`]
252262
pub trait MachineIo:
253263
Stream<Item = Result<Vec<u8>, IoError>> + Sink<Vec<u8>> + Send + Unpin + 'static
254264
{
@@ -277,6 +287,12 @@ impl Debug for Machine {
277287
}
278288

279289
impl Machine {
290+
/// Create a new [`Machine`]
291+
fn new(io: Option<Box<dyn MachineIo<Error = std::io::Error>>>, inner: SansIoMachine) -> Self {
292+
Self { io, inner }
293+
}
294+
295+
/// Create a new initiator
280296
pub fn new_dht_init(
281297
io: Option<Box<dyn MachineIo<Error = std::io::Error>>>,
282298
remote_pub_key: &[u8; PUBLIC_KEYLEN],
@@ -285,44 +301,38 @@ impl Machine {
285301
let ss = SecStream::new_initiator(remote_pub_key, prologue)?;
286302
let state = State::InitiatorStart(ss);
287303
let inner = SansIoMachine::new(state);
288-
Ok(Self { io, inner })
304+
Ok(Self::new(io, inner))
305+
}
306+
307+
/// Create a new initiator
308+
pub fn new_init(
309+
io: Box<dyn MachineIo<Error = std::io::Error>>,
310+
state: SecStream<Initiator<Start>>,
311+
) -> Self {
312+
Self::new(Some(io), SansIoMachine::new_init(state))
289313
}
290314

291-
fn new_dht_resp(
315+
/// Create a new responder from a private key
316+
pub fn resp_from_private(
292317
io: Option<Box<dyn MachineIo<Error = std::io::Error>>>,
293318
private: &[u8],
294319
) -> Result<Self, Error> {
295320
let ss = SecStream::new_responder(private)?;
296321
let state = State::RespStart(ss);
297322
let inner = SansIoMachine::new(state);
298-
Ok(Self { io, inner })
323+
Ok(Self::new(io, inner))
299324
}
300325

301-
fn new(io: Option<Box<dyn MachineIo<Error = std::io::Error>>>, inner: SansIoMachine) -> Self {
302-
Self { io, inner }
303-
}
304-
305-
fn new_init(
306-
io: Box<dyn MachineIo<Error = std::io::Error>>,
307-
state: SecStream<Initiator<Start>>,
308-
) -> Self {
309-
Self {
310-
io: Some(io),
311-
inner: SansIoMachine::new_init(state),
312-
}
313-
}
314-
315-
fn new_resp(
326+
/// Create a new responder
327+
pub fn new_resp(
316328
io: Box<dyn MachineIo<Error = std::io::Error>>,
317329
state: SecStream<Responder<Start>>,
318330
) -> Self {
319-
Self {
320-
io: Some(io),
321-
inner: SansIoMachine::new_resp(state),
322-
}
331+
Self::new(Some(io), SansIoMachine::new_resp(state))
323332
}
324333

325-
async fn complete_handshake(&mut self) -> Result<(), IoError> {
334+
/// Wait for handshake to complete
335+
pub async fn complete_handshake(&mut self) -> Result<(), IoError> {
326336
use futures::SinkExt;
327337
use futures::StreamExt;
328338

0 commit comments

Comments
 (0)