chore: Fix typos and add various comments

This commit is contained in:
Katherine Watson
2024-08-07 23:11:13 -07:00
parent 6d47169a5c
commit 9fd3df67ed
7 changed files with 18 additions and 12 deletions

View File

@@ -6,6 +6,7 @@ use crate::RosenpassError::{self, InvalidApiMessageType};
pub type RawMsgType = u128;
// constants generated by gen-ipc-msg-types:
// hash domain hash of: Rosenpass IPC API -> Rosenpass Protocol Server -> Ping Request
pub const PING_REQUEST: RawMsgType =
RawMsgType::from_le_bytes(hex!("2397 3ecc c441 704d 0b02 ea31 45d3 4999"));
@@ -46,7 +47,7 @@ impl MessageAttributes for ResponseMsgType {
impl TryFrom<RawMsgType> for RequestMsgType {
type Error = RosenpassError;
fn try_from(value: u128) -> Result<Self, Self::Error> {
fn try_from(value: RawMsgType) -> Result<Self, Self::Error> {
use RequestMsgType as E;
Ok(match value {
self::PING_REQUEST => E::Ping,
@@ -67,7 +68,7 @@ impl From<RequestMsgType> for RawMsgType {
impl TryFrom<RawMsgType> for ResponseMsgType {
type Error = RosenpassError;
fn try_from(value: u128) -> Result<Self, Self::Error> {
fn try_from(value: RawMsgType) -> Result<Self, Self::Error> {
use ResponseMsgType as E;
Ok(match value {
self::PING_RESPONSE => E::Ping,

View File

@@ -10,7 +10,7 @@ use super::config::ApiConfig;
#[derive(Args, Debug)]
pub struct ApiCli {
/// Where in the file-system to create the unix socket the rosenpass API will be listening for
/// connections on
/// connections on.
#[arg(long)]
api_listen_path: Vec<PathBuf>,

View File

@@ -70,6 +70,8 @@ impl MioManager {
token_dispenser: &mut MioTokenDispenser,
) -> io::Result<()> {
// Accept connection until the socket would block or returns another error
// TODO: This currently only adds connections--we eventually need the ability to remove
// them as well, see the note in connection.rs
loop {
match nonblocking_handle_io_errors(|| self.listeners[idx].accept())? {
None => break,

View File

@@ -17,6 +17,8 @@ pub fn claim_fd(fd: RawFd) -> rustix::io::Result<OwnedFd> {
}
pub fn mask_fd(fd: RawFd) -> rustix::io::Result<()> {
// Safety: because the OwnedFd resulting from OwnedFd::from_raw_fd is wrapped in a Forgetting,
// it never gets dropped, meaning that fd is never closed and thus outlives the OwnedFd
let mut owned = Forgetting::new(unsafe { OwnedFd::from_raw_fd(fd) });
clone_fd_to_cloexec(open_nullfd()?, &mut owned)
}

View File

@@ -19,7 +19,7 @@ pub enum SanityError {
}
#[derive(Error, Debug)]
#[error("Message too lage ({msg_size} bytes) for buffer ({buf_size} bytes)")]
#[error("Message too large ({msg_size} bytes) for buffer ({buf_size} bytes)")]
pub struct MessageTooLargeError {
msg_size: usize,
buf_size: usize,
@@ -132,7 +132,7 @@ impl<Buf: BorrowMut<[u8]>> LengthPrefixDecoder<Buf> {
Ok(match self.next_slice_to_write_to()? {
// Read some bytes; any MessageTooLargeError in the call to self.message_mut() is
// ignored to ensure this function changes no state upon errors; the user should rerun
// the function and colect the MessageTooLargeError on the following invocation
// the function and collect the MessageTooLargeError on the following invocation
Some(buf) => {
let bytes_read = r.read(buf)?;
self.advance(bytes_read).unwrap();

View File

@@ -57,21 +57,22 @@ impl<B: ByteSlice, T> RefMaker<B, T> {
Ok(Self::from_prefix_with_tail(self)?.0)
}
pub fn from_suffix_with_tail(self) -> anyhow::Result<(Self, B)> {
pub fn from_suffix_with_head(self) -> anyhow::Result<(Self, B)> {
self.ensure_fit()?;
let point = self.bytes().len() - Self::target_size();
let (head, tail) = self.buf.split_at(point);
Ok((Self::new(head), tail))
Ok((Self::new(tail), head))
}
pub fn split_suffix(self) -> anyhow::Result<(Self, Self)> {
self.ensure_fit()?;
let (head, tail) = self.buf.split_at(Self::target_size());
let point = self.bytes().len() - Self::target_size();
let (head, tail) = self.buf.split_at(point);
Ok((Self::new(head), Self::new(tail)))
}
pub fn from_suffix(self) -> anyhow::Result<Self> {
Ok(Self::from_suffix_with_tail(self)?.0)
Ok(Self::from_suffix_with_head(self)?.0)
}
pub fn bytes(&self) -> &[u8] {

View File

@@ -16,7 +16,7 @@ pub trait ZerocopySliceExt: Sized + ByteSlice {
}
fn zk_parse_suffix<T>(self) -> anyhow::Result<Ref<Self, T>> {
self.zk_ref_maker().from_prefix()?.parse()
self.zk_ref_maker().from_suffix()?.parse()
}
}
@@ -31,8 +31,8 @@ pub trait ZerocopyMutSliceExt: ZerocopySliceExt + Sized + ByteSliceMut {
self.zk_ref_maker().from_prefix()?.make_zeroized()
}
fn zk_zeroized_from_suffic<T>(self) -> anyhow::Result<Ref<Self, T>> {
self.zk_ref_maker().from_prefix()?.make_zeroized()
fn zk_zeroized_from_suffix<T>(self) -> anyhow::Result<Ref<Self, T>> {
self.zk_ref_maker().from_suffix()?.make_zeroized()
}
}