diff --git a/rosenpass/src/api/api_handler.rs b/rosenpass/src/api/api_handler.rs index 26683d78..1044571d 100644 --- a/rosenpass/src/api/api_handler.rs +++ b/rosenpass/src/api/api_handler.rs @@ -316,7 +316,7 @@ where use crate::app_server::BrokerStorePtr; // use rosenpass_secret_memory::Public; - use zerocopy::AsBytes; + use zerocopy::IntoBytes; (self.app_server().brokers.store.len() - 1) .apply(|x| x as u64) .apply(|x| Public::from_slice(x.as_bytes())) diff --git a/rosenpass/src/api/boilerplate/payload.rs b/rosenpass/src/api/boilerplate/payload.rs index 3f58f703..2185279f 100644 --- a/rosenpass/src/api/boilerplate/payload.rs +++ b/rosenpass/src/api/boilerplate/payload.rs @@ -1,5 +1,5 @@ use rosenpass_util::zerocopy::ZerocopyMutSliceExt; -use zerocopy::{AsBytes, ByteSliceMut, FromBytes, FromZeroes, Ref}; +use zerocopy::{IntoBytes, ByteSliceMut, FromBytes, Ref}; use super::{Message, RawMsgType, RequestMsgType, ResponseMsgType}; @@ -12,8 +12,8 @@ pub const MAX_REQUEST_FDS: usize = 2; /// Message envelope for API messages #[repr(packed)] -#[derive(Debug, Copy, Clone, Hash, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)] -pub struct Envelope { +#[derive(Debug, Copy, Clone, Hash, IntoBytes, FromBytes, PartialEq, Eq)] +pub struct Envelope { /// Which message this is pub msg_type: RawMsgType, /// The actual Paylod @@ -27,7 +27,7 @@ pub type ResponseEnvelope = Envelope; #[allow(missing_docs)] #[repr(packed)] -#[derive(Debug, Copy, Clone, Hash, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, IntoBytes, FromBytes, PartialEq, Eq)] pub struct PingRequestPayload { /// Randomly generated connection id pub echo: [u8; 256], @@ -68,7 +68,7 @@ impl Message for PingRequest { #[allow(missing_docs)] #[repr(packed)] -#[derive(Debug, Copy, Clone, Hash, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, IntoBytes, FromBytes, PartialEq, Eq)] pub struct PingResponsePayload { /// Randomly generated connection id pub echo: [u8; 256], @@ -109,7 +109,7 @@ impl Message for PingResponse { #[allow(missing_docs)] #[repr(packed)] -#[derive(Debug, Copy, Clone, Hash, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, IntoBytes, FromBytes, PartialEq, Eq)] pub struct SupplyKeypairRequestPayload {} #[allow(missing_docs)] @@ -169,7 +169,7 @@ pub mod supply_keypair_response_status { #[allow(missing_docs)] #[repr(packed)] -#[derive(Debug, Copy, Clone, Hash, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, IntoBytes, FromBytes, PartialEq, Eq)] pub struct SupplyKeypairResponsePayload { #[allow(missing_docs)] pub status: u128, @@ -210,7 +210,7 @@ impl Message for SupplyKeypairResponse { #[allow(missing_docs)] #[repr(packed)] -#[derive(Debug, Copy, Clone, Hash, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, IntoBytes, FromBytes, PartialEq, Eq)] pub struct AddListenSocketRequestPayload {} #[allow(missing_docs)] @@ -264,7 +264,7 @@ pub mod add_listen_socket_response_status { #[allow(missing_docs)] #[repr(packed)] -#[derive(Debug, Copy, Clone, Hash, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, IntoBytes, FromBytes, PartialEq, Eq)] pub struct AddListenSocketResponsePayload { pub status: u128, } @@ -304,7 +304,7 @@ impl Message for AddListenSocketResponse { #[allow(missing_docs)] #[repr(packed)] -#[derive(Debug, Copy, Clone, Hash, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, IntoBytes, FromBytes, PartialEq, Eq)] pub struct AddPskBrokerRequestPayload {} #[allow(missing_docs)] @@ -359,7 +359,7 @@ pub mod add_psk_broker_response_status { #[allow(missing_docs)] #[repr(packed)] -#[derive(Debug, Copy, Clone, Hash, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, IntoBytes, FromBytes, PartialEq, Eq)] pub struct AddPskBrokerResponsePayload { pub status: u128, } diff --git a/rosenpass/src/api/boilerplate/request_ref.rs b/rosenpass/src/api/boilerplate/request_ref.rs index f988940e..49e8a328 100644 --- a/rosenpass/src/api/boilerplate/request_ref.rs +++ b/rosenpass/src/api/boilerplate/request_ref.rs @@ -20,7 +20,7 @@ impl RequestRef { /// # Examples /// /// ``` - /// use zerocopy::AsBytes; + /// use zerocopy::IntoBytes; /// /// use rosenpass::api::{PingRequest, RequestRef, RequestMsgType}; /// diff --git a/rosenpass/src/api/boilerplate/response_ref.rs b/rosenpass/src/api/boilerplate/response_ref.rs index 3b9fc19a..a1ab3805 100644 --- a/rosenpass/src/api/boilerplate/response_ref.rs +++ b/rosenpass/src/api/boilerplate/response_ref.rs @@ -23,7 +23,7 @@ impl ResponseRef { /// # Examples /// /// ``` - /// use zerocopy::AsBytes; + /// use zerocopy::IntoBytes; /// /// use rosenpass::api::{PingResponse, ResponseRef, ResponseMsgType}; /// // Produce the original PingResponse diff --git a/rosenpass/src/app_server.rs b/rosenpass/src/app_server.rs index 1408500a..09c939db 100644 --- a/rosenpass/src/app_server.rs +++ b/rosenpass/src/app_server.rs @@ -13,7 +13,7 @@ use signal_hook_mio::v1_0 as signal_hook_mio; use anyhow::{Context, Result, bail}; use derive_builder::Builder; use log::{error, info, warn}; -use zerocopy::AsBytes; +use zerocopy::IntoBytes; use rosenpass_util::attempt; use rosenpass_util::fmt::debug::NullDebug; diff --git a/rosenpass/src/msgs.rs b/rosenpass/src/msgs.rs index db90912d..e2cb21bf 100644 --- a/rosenpass/src/msgs.rs +++ b/rosenpass/src/msgs.rs @@ -9,7 +9,7 @@ //! To achieve this we utilize the zerocopy library. //! use std::mem::size_of; -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{IntoBytes, FromBytes}; use super::RosenpassError; use rosenpass_cipher_traits::primitives::{Aead as _, Kem}; @@ -51,7 +51,7 @@ pub type MsgEnvelopeCookie = [u8; COOKIE_SIZE]; /// /// ``` /// use rosenpass::msgs::{Envelope, InitHello}; -/// use zerocopy::{AsBytes, FromBytes, Ref, FromZeroes}; +/// use zerocopy::{IntoBytes, FromBytes, Ref, FromZeroes}; /// use memoffset::offset_of; /// /// // Zero-initialization @@ -76,8 +76,8 @@ pub type MsgEnvelopeCookie = [u8; COOKIE_SIZE]; /// assert_eq!(ih3.msg_type, 42); /// ``` #[repr(packed)] -#[derive(AsBytes, FromBytes, FromZeroes, Clone)] -pub struct Envelope { +#[derive(IntoBytes, FromBytes, Clone)] +pub struct Envelope { /// [MsgType] of this message pub msg_type: u8, /// Reserved for future use @@ -106,7 +106,7 @@ pub struct Envelope { /// /// ``` /// use rosenpass::msgs::{Envelope, InitHello}; -/// use zerocopy::{AsBytes, FromBytes, Ref, FromZeroes}; +/// use zerocopy::{IntoBytes, FromBytes, Ref, FromZeroes}; /// use memoffset::span_of; /// /// // Zero initialization @@ -126,7 +126,7 @@ pub struct Envelope { /// assert_eq!(ih.payload.sidi, [1,2,3,4]); /// ``` #[repr(packed)] -#[derive(AsBytes, FromBytes, FromZeroes)] +#[derive(IntoBytes, FromBytes)] pub struct InitHello { /// Randomly generated connection id pub sidi: [u8; 4], @@ -155,7 +155,7 @@ pub struct InitHello { /// /// ``` /// use rosenpass::msgs::{Envelope, RespHello}; -/// use zerocopy::{AsBytes, FromBytes, Ref, FromZeroes}; +/// use zerocopy::{IntoBytes, FromBytes, Ref, FromZeroes}; /// use memoffset::span_of; /// /// // Zero initialization @@ -175,7 +175,7 @@ pub struct InitHello { /// assert_eq!(ih.payload.sidi, [1,2,3,4]); /// ``` #[repr(packed)] -#[derive(AsBytes, FromBytes, FromZeroes)] +#[derive(IntoBytes, FromBytes)] pub struct RespHello { /// Randomly generated connection id pub sidr: [u8; 4], @@ -206,7 +206,7 @@ pub struct RespHello { /// /// ``` /// use rosenpass::msgs::{Envelope, InitConf}; -/// use zerocopy::{AsBytes, FromBytes, Ref, FromZeroes}; +/// use zerocopy::{IntoBytes, FromBytes, Ref, FromZeroes}; /// use memoffset::span_of; /// /// // Zero initialization @@ -226,7 +226,7 @@ pub struct RespHello { /// assert_eq!(ih.payload.sidi, [1,2,3,4]); /// ``` #[repr(packed)] -#[derive(AsBytes, FromBytes, FromZeroes, Debug)] +#[derive(IntoBytes, FromBytes, Debug)] pub struct InitConf { /// Copied from InitHello pub sidi: [u8; 4], @@ -264,7 +264,7 @@ pub struct InitConf { /// /// ``` /// use rosenpass::msgs::{Envelope, EmptyData}; -/// use zerocopy::{AsBytes, FromBytes, Ref, FromZeroes}; +/// use zerocopy::{IntoBytes, FromBytes, Ref, FromZeroes}; /// use memoffset::span_of; /// /// // Zero initialization @@ -284,7 +284,7 @@ pub struct InitConf { /// assert_eq!(ih.payload.sid, [1,2,3,4]); /// ``` #[repr(packed)] -#[derive(AsBytes, FromBytes, FromZeroes, Clone, Copy)] +#[derive(IntoBytes, FromBytes, Clone, Copy)] pub struct EmptyData { /// Copied from RespHello pub sid: [u8; 4], @@ -311,7 +311,7 @@ pub struct EmptyData { /// /// [Envelope] and [InitHello] contain some extra examples on how to use structures from the [::zerocopy] crate. #[repr(packed)] -#[derive(AsBytes, FromBytes, FromZeroes)] +#[derive(IntoBytes, FromBytes)] pub struct Biscuit { /// H(spki) – Ident ifies the initiator pub pidi: [u8; KEY_LEN], @@ -336,7 +336,7 @@ pub struct Biscuit { /// /// [Envelope] and [InitHello] contain some extra examples on how to use structures from the [::zerocopy] crate. #[repr(packed)] -#[derive(AsBytes, FromBytes, FromZeroes)] +#[derive(IntoBytes, FromBytes)] pub struct CookieReplyInner { /// [MsgType] of this message pub msg_type: u8, @@ -363,7 +363,7 @@ pub struct CookieReplyInner { /// /// [Envelope] and [InitHello] contain some extra examples on how to use structures from the [::zerocopy] crate. #[repr(packed)] -#[derive(AsBytes, FromBytes, FromZeroes)] +#[derive(IntoBytes, FromBytes)] pub struct CookieReply { pub inner: CookieReplyInner, pub padding: [u8; size_of::>() - size_of::()], diff --git a/rosenpass/src/protocol/protocol.rs b/rosenpass/src/protocol/protocol.rs index 28ca7df8..87acaafd 100644 --- a/rosenpass/src/protocol/protocol.rs +++ b/rosenpass/src/protocol/protocol.rs @@ -17,7 +17,7 @@ use std::{ use anyhow::{Context, Result, bail, ensure}; use assert_tv::{TestVector, TestVectorNOP}; use memoffset::span_of; -use zerocopy::{AsBytes, FromBytes, Ref}; +use zerocopy::{IntoBytes, FromBytes, Ref}; use rosenpass_cipher_traits::primitives::{ Aead as _, AeadWithNonceInCiphertext, Kem, KeyedHashInstance, @@ -413,7 +413,7 @@ pub struct InitiatorHandshake { /// /// Used as [KnownInitConfResponse] for now cache [EmptyData] (responder confirmation) /// responses to [InitConf] -pub struct KnownResponse { +pub struct KnownResponse { /// When the response was initially computed pub received_at: Timing, /// Hash of the message that triggered the response; created using @@ -423,7 +423,7 @@ pub struct KnownResponse { pub response: Envelope, } -impl Debug for KnownResponse { +impl Debug for KnownResponse { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("KnownResponse") .field("received_at", &self.received_at) @@ -508,7 +508,7 @@ impl KnownResponseHasher { /// # Panic & Safety /// /// Panics in case of a problem with this underlying hash function - pub fn hash(&self, msg: &Envelope) -> KnownResponseHash { + pub fn hash(&self, msg: &Envelope) -> KnownResponseHash { let data = &msg.as_bytes()[span_of!(Envelope, msg_type..cookie)]; // This function is only used internally and results are not propagated // to outside the peer. Thus, it uses SHAKE256 exclusively. @@ -2341,8 +2341,8 @@ impl CryptoServer { /// /// To save some code, the function returns the size of the message, /// but the same could be easily achieved by calling [size_of] with the - /// message type or by calling [AsBytes::as_bytes] on the message reference. - pub fn seal_and_commit_msg( + /// message type or by calling [IntoBytes::as_bytes] on the message reference. + pub fn seal_and_commit_msg( &mut self, peer: PeerPtr, msg_type: MsgType, @@ -3065,7 +3065,7 @@ impl IniHsPtr { impl Envelope where - M: AsBytes + FromBytes, + M: IntoBytes + FromBytes, { /// Internal business logic: Calculate the message authentication code (`mac`) and also append cookie value pub fn seal(&mut self, peer: PeerPtr, srv: &CryptoServer) -> Result<()> { @@ -3094,7 +3094,7 @@ where impl Envelope where - M: AsBytes + FromBytes, + M: IntoBytes + FromBytes, { /// Internal business logic: Check the message authentication code produced by [Self::seal] pub fn check_seal(&self, srv: &CryptoServer, shake_or_blake: KeyedHash) -> Result { diff --git a/rosenpass/src/protocol/test.rs b/rosenpass/src/protocol/test.rs index 025575fd..cd295cf7 100644 --- a/rosenpass/src/protocol/test.rs +++ b/rosenpass/src/protocol/test.rs @@ -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::{IntoBytes, FromBytes}; use rosenpass_cipher_traits::primitives::Kem; use rosenpass_ciphers::StaticKem; @@ -542,7 +542,7 @@ fn init_conf_retransmission(protocol_version: ProtocolVersion) -> anyhow::Result Ok(msg.read()) } - fn proc_msg( + fn proc_msg( srv: &mut CryptoServer, rx: &Envelope, ) -> anyhow::Result> { @@ -583,11 +583,11 @@ fn init_conf_retransmission(protocol_version: ProtocolVersion) -> anyhow::Result } // TODO: Implement Clone on our message types - fn clone_msg(msg: &Msg) -> anyhow::Result { + fn clone_msg(msg: &Msg) -> anyhow::Result { Ok(truncating_cast_into_nomut::(msg.as_bytes())?.read()) } - fn break_payload( + fn break_payload( srv: &mut CryptoServer, peer: PeerPtr, msg: &Envelope,