mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-07-28 14:26:59 -07:00
stash
This commit is contained in:
@@ -20,7 +20,7 @@ impl<B: SplitByteSlice> RequestRef<B> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use zerocopy::AsBytes;
|
||||
/// use zerocopy::IntoBytes;
|
||||
///
|
||||
/// use rosenpass::api::{PingRequest, RequestRef, RequestMsgType};
|
||||
///
|
||||
|
||||
@@ -23,7 +23,7 @@ impl<B: SplitByteSlice> ResponseRef<B> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use zerocopy::AsBytes;
|
||||
/// use zerocopy::IntoBytes;
|
||||
///
|
||||
/// use rosenpass::api::{PingResponse, ResponseRef, ResponseMsgType};
|
||||
/// // Produce the original PingResponse
|
||||
|
||||
@@ -51,7 +51,7 @@ pub type MsgEnvelopeCookie = [u8; COOKIE_SIZE];
|
||||
///
|
||||
/// ```
|
||||
/// use rosenpass::msgs::{Envelope, InitHello};
|
||||
/// use zerocopy::{IntoBytes, FromBytes, Ref};
|
||||
/// use zerocopy::{FromZeros, IntoBytes, FromBytes, Ref};
|
||||
/// use memoffset::offset_of;
|
||||
///
|
||||
/// // Zero-initialization
|
||||
@@ -106,7 +106,7 @@ pub struct Envelope<M: IntoBytes + FromBytes> {
|
||||
///
|
||||
/// ```
|
||||
/// use rosenpass::msgs::{Envelope, InitHello};
|
||||
/// use zerocopy::{IntoBytes, FromBytes, Ref};
|
||||
/// use zerocopy::{FromZeros, IntoBytes, FromBytes, Ref};
|
||||
/// use memoffset::span_of;
|
||||
///
|
||||
/// // Zero initialization
|
||||
@@ -155,7 +155,7 @@ pub struct InitHello {
|
||||
///
|
||||
/// ```
|
||||
/// use rosenpass::msgs::{Envelope, RespHello};
|
||||
/// use zerocopy::{IntoBytes, FromBytes, Ref};
|
||||
/// use zerocopy::{FromZeros, IntoBytes, FromBytes, Ref};
|
||||
/// use memoffset::span_of;
|
||||
///
|
||||
/// // Zero initialization
|
||||
@@ -206,7 +206,7 @@ pub struct RespHello {
|
||||
///
|
||||
/// ```
|
||||
/// use rosenpass::msgs::{Envelope, InitConf};
|
||||
/// use zerocopy::{IntoBytes, FromBytes, Ref};
|
||||
/// use zerocopy::{IntoBytes, FromBytes, FromZeros, Ref};
|
||||
/// use memoffset::span_of;
|
||||
///
|
||||
/// // Zero initialization
|
||||
@@ -264,7 +264,7 @@ pub struct InitConf {
|
||||
///
|
||||
/// ```
|
||||
/// use rosenpass::msgs::{Envelope, EmptyData};
|
||||
/// use zerocopy::{IntoBytes, FromBytes, Ref};
|
||||
/// use zerocopy::{FromZeros, IntoBytes, FromBytes, Ref};
|
||||
/// use memoffset::span_of;
|
||||
///
|
||||
/// // Zero initialization
|
||||
|
||||
@@ -464,7 +464,7 @@ pub type KnownResponseHash = Public<16>;
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use zerocopy::FromZeroes;
|
||||
/// use zerocopy::FromZeros;
|
||||
/// use rosenpass::protocol::KnownResponseHasher;
|
||||
/// use rosenpass::msgs::{Envelope, InitConf};
|
||||
///
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::{borrow::BorrowMut, fmt::Display, net::SocketAddrV4, ops::DerefMut};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use serial_test::serial;
|
||||
use zerocopy::{AsBytes, FromBytes, FromZeroes};
|
||||
use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout};
|
||||
|
||||
use rosenpass_cipher_traits::primitives::Kem;
|
||||
use rosenpass_ciphers::StaticKem;
|
||||
@@ -538,10 +538,10 @@ fn init_conf_retransmission(protocol_version: ProtocolVersion) -> anyhow::Result
|
||||
srv.initiate_handshake(peer, buf.as_mut_slice())?
|
||||
.discard_result();
|
||||
let msg = truncating_cast_into::<Envelope<InitHello>>(buf.borrow_mut())?;
|
||||
Ok(msg.read())
|
||||
Ok(zerocopy::Ref::read(&msg))
|
||||
}
|
||||
|
||||
fn proc_msg<Rx: AsBytes + FromBytes, Tx: AsBytes + FromBytes>(
|
||||
fn proc_msg<Rx: IntoBytes + FromBytes + Immutable, Tx: IntoBytes + FromBytes + Immutable>(
|
||||
srv: &mut CryptoServer,
|
||||
rx: &Envelope<Rx>,
|
||||
) -> anyhow::Result<Envelope<Tx>> {
|
||||
@@ -551,7 +551,7 @@ fn init_conf_retransmission(protocol_version: ProtocolVersion) -> anyhow::Result
|
||||
.context("Failed to produce RespHello message")?
|
||||
.discard_result();
|
||||
let msg = truncating_cast_into::<Envelope<Tx>>(buf.borrow_mut())?;
|
||||
Ok(msg.read())
|
||||
Ok(zerocopy::Ref::read(&msg))
|
||||
}
|
||||
|
||||
fn proc_init_hello(
|
||||
@@ -582,17 +582,21 @@ fn init_conf_retransmission(protocol_version: ProtocolVersion) -> anyhow::Result
|
||||
}
|
||||
|
||||
// TODO: Implement Clone on our message types
|
||||
fn clone_msg<Msg: AsBytes + FromBytes>(msg: &Msg) -> anyhow::Result<Msg> {
|
||||
Ok(truncating_cast_into_nomut::<Msg>(msg.as_bytes())?.read())
|
||||
fn clone_msg<Msg: IntoBytes + FromBytes + Immutable + KnownLayout>(
|
||||
msg: &Msg,
|
||||
) -> anyhow::Result<Msg> {
|
||||
Ok(zerocopy::Ref::read(&truncating_cast_into_nomut::<Msg>(
|
||||
msg.as_bytes(),
|
||||
)?))
|
||||
}
|
||||
|
||||
fn break_payload<Msg: AsBytes + FromBytes>(
|
||||
fn break_payload<Msg: IntoBytes + FromBytes + Immutable + KnownLayout>(
|
||||
srv: &mut CryptoServer,
|
||||
peer: PeerPtr,
|
||||
msg: &Envelope<Msg>,
|
||||
) -> anyhow::Result<Envelope<Msg>> {
|
||||
let mut msg = clone_msg(msg)?;
|
||||
msg.as_bytes_mut()[memoffset::offset_of!(Envelope<Msg>, payload)] ^= 0x01;
|
||||
msg.as_mut_bytes()[memoffset::offset_of!(Envelope<Msg>, payload)] ^= 0x01;
|
||||
msg.seal(peer, srv)?; // Recalculate seal; we do not want to focus on "seal broken" errs
|
||||
Ok(msg)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ use rosenpass_util::{
|
||||
};
|
||||
use std::os::fd::{AsFd, AsRawFd};
|
||||
use tempfile::TempDir;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
struct KillChild(std::process::Child);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ use rosenpass_util::{
|
||||
};
|
||||
use rosenpass_util::{mem::DiscardResultExt, zerocopy::ZerocopySliceExt};
|
||||
use tempfile::TempDir;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use rosenpass::config::ProtocolVersion;
|
||||
use rosenpass::protocol::basic_types::SymKey;
|
||||
|
||||
@@ -47,7 +47,7 @@ async fn janitor_demo() -> anyhow::Result<()> {
|
||||
anyhow::Ok(())
|
||||
})
|
||||
}
|
||||
.await;
|
||||
.await?;
|
||||
|
||||
// At this point, all background jobs have finished, now we can check the result of all our
|
||||
// additions
|
||||
|
||||
Reference in New Issue
Block a user