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
24 changes: 22 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ tokio-util = { version = "0.7", features = ["compat"] }
usdt = "0.5.0"
uuid = { version = "1.16", default-features = false }
version_check = "0.9.5"
zerocopy = "0.6.6"
zerocopy = "0.8.25"
zip = { version = "0.6.6", default-features = false, features = ["deflate", "bzip2"] }

gateway-messages.path = "gateway-messages"
Expand Down
2 changes: 1 addition & 1 deletion faux-mgs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use std::sync::Arc;
use std::time::Duration;
use tokio::net::UdpSocket;
use uuid::Uuid;
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

mod picocom_map;
mod usart;
Expand Down
2 changes: 1 addition & 1 deletion gateway-messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ smoltcp = { workspace = true, optional = true }
static_assertions.workspace = true
strum_macros.workspace = true
uuid.workspace = true
zerocopy.workspace = true
zerocopy = { workspace = true, features = ["derive"] }

[dev-dependencies]
serde_json.workspace = true
Expand Down
4 changes: 3 additions & 1 deletion gateway-messages/src/mgs_to_sp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ pub enum UnlockChallenge {
PartialEq,
Eq,
Debug,
zerocopy::AsBytes,
zerocopy::IntoBytes,
zerocopy::KnownLayout,
zerocopy::Immutable,
)]
#[repr(C)]
pub struct EcdsaSha2Nistp256Challenge {
Expand Down
33 changes: 27 additions & 6 deletions gateway-messages/src/tlv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ use core::iter;
use core::mem;
use zerocopy::byteorder::LittleEndian;
use zerocopy::byteorder::U32;
use zerocopy::AsBytes;
use zerocopy::FromBytes;
use zerocopy::Immutable;
use zerocopy::IntoBytes;
use zerocopy::KnownLayout;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EncodeError<E> {
Expand Down Expand Up @@ -42,11 +44,31 @@ impl fmt::Display for DecodeError {
#[cfg(feature = "std")]
impl std::error::Error for DecodeError {}

#[derive(Debug, Clone, Copy, PartialEq, Eq, AsBytes, FromBytes)]
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
IntoBytes,
FromBytes,
Immutable,
KnownLayout,
)]
#[repr(C)]
pub struct Tag(pub [u8; 4]);

#[derive(Debug, Clone, Copy, PartialEq, Eq, AsBytes, FromBytes)]
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
IntoBytes,
FromBytes,
Immutable,
KnownLayout,
)]
#[repr(C)]
struct Header {
tag: Tag,
Expand Down Expand Up @@ -103,9 +125,8 @@ where
/// returns `(Tag, value, rest_of_buf)`.
pub fn decode(buf: &[u8]) -> Result<(Tag, &[u8], &[u8]), DecodeError> {
// Peel header off the front.
let header =
Header::read_from_prefix(buf).ok_or(DecodeError::BufferTooSmall)?;
let buf = &buf[mem::size_of::<Header>()..];
let (header, buf) = Header::read_from_prefix(buf)
.map_err(|_| DecodeError::BufferTooSmall)?;

// Split remaining buffer at the end of our value.
let length = header.length.get() as usize;
Expand Down
Loading