Skip to content

Commit

Permalink
ongoing work
Browse files Browse the repository at this point in the history
  • Loading branch information
frochet committed Mar 12, 2024
1 parent 5da844d commit 158588e
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 136 deletions.
8 changes: 4 additions & 4 deletions apps/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,9 +1302,9 @@ impl HttpConn for Http3Conn {
// If this condition is not satified, we can conn.recv() more
// before processing what we already have.
// As long as MAX_FLUSH_SIZE < --max-data/2; this is okay.
if b.len() >= crate::client::MAX_FLUSH_SIZE ||
b.len() == tot_exp_len
{
//if b.len() >= crate::client::MAX_FLUSH_SIZE ||
//b.len() == tot_exp_len
//{
let req = self
.reqs
.iter_mut()
Expand Down Expand Up @@ -1334,7 +1334,7 @@ impl HttpConn for Http3Conn {
.unwrap();
},
}
}
//}
},

Ok((_stream_id, quiche::h3::Event::Finished)) => {
Expand Down
65 changes: 47 additions & 18 deletions octets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl<'a> Octets<'a> {
get_u!(self, u8, 1)
}

/// Decreases the buffer's offset by 1 and reads an unsigned 8-bit integer
/// Decreases the buffer's offset by 1 and reads an unsigned 8-bits integer
pub fn get_u8_reverse(&mut self) -> Result<u8> {
get_u_reverse!(self, u8, 1);
}
Expand All @@ -222,7 +222,7 @@ impl<'a> Octets<'a> {
get_u!(self, u16, 2)
}

/// Decreases the buffer's offset by 2 and reads an unsigned 16-bit integer
/// Decreases the buffer's offset by 2 and reads an unsigned 16-bits integer
pub fn get_u16_reverse(&mut self) -> Result<u16> {
get_u_reverse!(self, u16, 2)
}
Expand All @@ -233,6 +233,7 @@ impl<'a> Octets<'a> {
get_u!(self, u32, 3)
}

/// Decreases the buffer's offset by 3 and reads an unsigned 24-bits integer
pub fn get_u24_reverse(&mut self) -> Result<u32> {
get_u_reverse!(self, u32, 3)
}
Expand All @@ -243,10 +244,17 @@ impl<'a> Octets<'a> {
get_u!(self, u32, 4)
}

/// Decreases the buffer's offset by 4 and reads an unsigned 32-bits integer.
pub fn get_u32_reverse(&mut self) -> Result<u32> {
get_u_reverse!(self, u32, 4)
}

/// Reads an unsigned 56-bit integer in a network byte-order from the current
/// offset and advances the buffer.
pub fn get_u56(&mut self) -> Result<u64> {
get_u!(self, u64, 7)
}

/// Reads an unsigned 64-bit integer in network byte-order from the current
/// offset and advances the buffer.
pub fn get_u64(&mut self) -> Result<u64> {
Expand Down Expand Up @@ -549,6 +557,18 @@ impl<'a> OctetsMut<'a> {
put_u!(self, u32, v, 4)
}

/// Reads an unsigned 64-bit integer in network byte-order from the current
/// offset and advances the buffer.
pub fn get_u56(&mut self) -> Result<u64> {
get_u!(self, u64, 7)
}

/// Writes an unsigned 56-bit integer in network byte-order at the current
/// offset and advances the buffer.
pub fn put_u56(&mut self, v: u64) -> Result<&mut [u8]> {
put_u!(self, u64, v, 7)
}

/// Reads an unsigned 64-bit integer in network byte-order from the current
/// offset and advances the buffer.
pub fn get_u64(&mut self) -> Result<u64> {
Expand Down Expand Up @@ -962,32 +982,36 @@ mod tests {
#[test]
fn get_u_mut() {
let mut d = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
];

let mut b = OctetsMut::with_slice(&mut d);
assert_eq!(b.cap(), 18);
assert_eq!(b.cap(), 25);
assert_eq!(b.off(), 0);

assert_eq!(b.get_u8().unwrap(), 1);
assert_eq!(b.cap(), 17);
assert_eq!(b.cap(), 24);
assert_eq!(b.off(), 1);

assert_eq!(b.get_u16().unwrap(), 0x203);
assert_eq!(b.cap(), 15);
assert_eq!(b.cap(), 22);
assert_eq!(b.off(), 3);

assert_eq!(b.get_u24().unwrap(), 0x40506);
assert_eq!(b.cap(), 12);
assert_eq!(b.cap(), 19);
assert_eq!(b.off(), 6);

assert_eq!(b.get_u32().unwrap(), 0x0708090a);
assert_eq!(b.cap(), 8);
assert_eq!(b.cap(), 15);
assert_eq!(b.off(), 10);

assert_eq!(b.get_u64().unwrap(), 0x0b0c0d0e0f101112);
assert_eq!(b.get_u56().unwrap(), 0xb0c0d0e0f1011);
assert_eq!(b.cap(), 8);
assert_eq!(b.off(), 17);

assert_eq!(b.get_u64().unwrap(), 0x1213141516171819);
assert_eq!(b.cap(), 0);
assert_eq!(b.off(), 18);
assert_eq!(b.off(), 25);

assert!(b.get_u8().is_err());
assert!(b.get_u16().is_err());
Expand Down Expand Up @@ -1324,38 +1348,43 @@ mod tests {

#[test]
fn put_u() {
let mut d = [0; 18];
let mut d = [0; 25];

{
let mut b = OctetsMut::with_slice(&mut d);
assert_eq!(b.cap(), 18);
assert_eq!(b.cap(), 25);
assert_eq!(b.off(), 0);

assert!(b.put_u8(1).is_ok());
assert_eq!(b.cap(), 17);
assert_eq!(b.cap(), 24);
assert_eq!(b.off(), 1);

assert!(b.put_u16(0x203).is_ok());
assert_eq!(b.cap(), 15);
assert_eq!(b.cap(), 22);
assert_eq!(b.off(), 3);

assert!(b.put_u24(0x40506).is_ok());
assert_eq!(b.cap(), 12);
assert_eq!(b.cap(), 19);
assert_eq!(b.off(), 6);

assert!(b.put_u32(0x0708090a).is_ok());
assert_eq!(b.cap(), 8);
assert_eq!(b.cap(), 15);
assert_eq!(b.off(), 10);

assert!(b.put_u64(0x0b0c0d0e0f101112).is_ok());
assert!(b.put_u56(0xb0c0d0e0f1011).is_ok());
assert_eq!(b.cap(), 8);
assert_eq!(b.off(), 17);

assert!(b.put_u64(0x1213141516171819).is_ok());
assert_eq!(b.cap(), 0);
assert_eq!(b.off(), 18);
assert_eq!(b.off(), 25);

assert!(b.put_u8(1).is_err());
}

let exp = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25
];
assert_eq!(&d, &exp);
}
Expand Down
2 changes: 1 addition & 1 deletion quiche/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ either = { version = "1.8", default-features = false }
log = { version = "0.4", features = ["std"] }
libc = "0.2"
libm = "0.2"
ring = { git = "https://github.com/frochet/ring", branch = "b/0.16" }
ring = { git = "https://github.com/frochet/ring"}
slab = "0.4"
once_cell = "1"
octets = { version = "0.2", path = "../octets" }
Expand Down
12 changes: 6 additions & 6 deletions quiche/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,15 @@ impl Open {
Ok(mask)
}

pub fn new_mask_13(&self, sample: &[u8]) -> Result<[u8; 13]> {
pub fn new_mask_16(&self, sample: &[u8]) -> Result<[u8; 16]> {
if cfg!(feature = "fuzzing") {
return Ok(<[u8; 13]>::default());
return Ok(<[u8; 16]>::default());
}

let mask = self
.header
.hpk
.new_mask_13(sample)
.new_mask_16(sample)
.map_err(|_| Error::CryptoFail)?;
Ok(mask)
}
Expand Down Expand Up @@ -400,15 +400,15 @@ impl Seal {
Ok(mask)
}

pub fn new_mask_13(&self, sample: &[u8]) -> Result<[u8; 13]> {
pub fn new_mask_16(&self, sample: &[u8]) -> Result<[u8; 16]> {
if cfg!(feature = "fuzzing") {
return Ok(<[u8; 13]>::default());
return Ok(<[u8; 16]>::default());
}

let mask = self
.header
.hpk
.new_mask_13(sample)
.new_mask_16(sample)
.map_err(|_| Error::CryptoFail)?;
Ok(mask)
}
Expand Down
8 changes: 4 additions & 4 deletions quiche/src/h3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5908,7 +5908,7 @@ mod tests {
if s.pipe.client.version == crate::PROTOCOL_VERSION_V3 {
assert_eq!(
s.pipe.send_pkt_to_server(pkt_type, &frames, &mut buf, None),
Ok(48),
Ok(51),
);
} else {
assert_eq!(
Expand Down Expand Up @@ -7298,7 +7298,7 @@ mod tests {
if s.pipe.client.version == crate::PROTOCOL_VERSION_V3 {
assert_eq!(
s.pipe.send_pkt_to_server(pkt_type, &frames, &mut buf, None),
Ok(48)
Ok(51)
);
} else {
assert_eq!(
Expand All @@ -7315,7 +7315,7 @@ mod tests {
if s.pipe.client.version == crate::PROTOCOL_VERSION_V3 {
assert_eq!(
s.pipe.send_pkt_to_server(pkt_type, &frames, &mut buf, None),
Ok(48)
Ok(51)
);
} else {
assert_eq!(
Expand Down Expand Up @@ -7442,7 +7442,7 @@ mod tests {
if s.pipe.client.version == crate::PROTOCOL_VERSION_V3 {
assert_eq!(
s.pipe.send_pkt_to_server(pkt_type, &frames, &mut buf, None),
Ok(48)
Ok(51)
);
} else {
assert_eq!(
Expand Down
Loading

0 comments on commit 158588e

Please sign in to comment.