Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkjall committed Jan 9, 2024
1 parent a4682b9 commit c4f3ba6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 31 deletions.
59 changes: 39 additions & 20 deletions h3/src/qpack/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,15 @@ impl HeaderPrefix {
let (sign_negative, delta_base) = prefix_int::decode(7, buf)?;

if encoded_insert_count > (usize::MAX as u64) {
return Err(ParseError::Integer(crate::qpack::prefix_int::Error::Overflow))
return Err(ParseError::Integer(
crate::qpack::prefix_int::Error::Overflow,
));
}

if delta_base > (usize::MAX as u64) {
return Err(ParseError::Integer(crate::qpack::prefix_int::Error::Overflow))
return Err(ParseError::Integer(
crate::qpack::prefix_int::Error::Overflow,
));
}

Ok(Self {
Expand Down Expand Up @@ -211,18 +215,22 @@ impl Indexed {
match prefix_int::decode(6, buf)? {
(0b11, i) => {
if i > (usize::MAX as u64) {
return Err(ParseError::Integer(crate::qpack::prefix_int::Error::Overflow))
return Err(ParseError::Integer(
crate::qpack::prefix_int::Error::Overflow,
));
}

Ok(Indexed::Static(i as usize))
},
}
(0b10, i) => {
if i > (usize::MAX as u64) {
return Err(ParseError::Integer(crate::qpack::prefix_int::Error::Overflow))
return Err(ParseError::Integer(
crate::qpack::prefix_int::Error::Overflow,
));
}

Ok(Indexed::Dynamic(i as usize))
},
}
(f, _) => Err(ParseError::InvalidPrefix(f)),
}
}
Expand All @@ -243,11 +251,13 @@ impl IndexedWithPostBase {
match prefix_int::decode(4, buf)? {
(0b0001, i) => {
if i > (usize::MAX as u64) {
return Err(ParseError::Integer(crate::qpack::prefix_int::Error::Overflow))
return Err(ParseError::Integer(
crate::qpack::prefix_int::Error::Overflow,
));
}

Ok(IndexedWithPostBase(i as usize))
},
}
(f, _) => Err(ParseError::InvalidPrefix(f)),
}
}
Expand Down Expand Up @@ -282,22 +292,28 @@ impl LiteralWithNameRef {
match prefix_int::decode(4, buf)? {
(f, i) if f & 0b0101 == 0b0101 => {
if i > (usize::MAX as u64) {
return Err(ParseError::Integer(crate::qpack::prefix_int::Error::Overflow))
return Err(ParseError::Integer(
crate::qpack::prefix_int::Error::Overflow,
));
}

Ok(LiteralWithNameRef::new_static(
i as usize,
prefix_string::decode(8, buf)?))
},
i as usize,
prefix_string::decode(8, buf)?,
))
}
(f, i) if f & 0b0101 == 0b0100 => {
if i > (usize::MAX as u64) {
return Err(ParseError::Integer(crate::qpack::prefix_int::Error::Overflow))
return Err(ParseError::Integer(
crate::qpack::prefix_int::Error::Overflow,
));
}

Ok(LiteralWithNameRef::new_dynamic(
i as usize,
prefix_string::decode(8, buf)?))
},
i as usize,
prefix_string::decode(8, buf)?,
))
}
(f, _) => Err(ParseError::InvalidPrefix(f)),
}
}
Expand Down Expand Up @@ -335,13 +351,16 @@ impl LiteralWithPostBaseNameRef {
match prefix_int::decode(3, buf)? {
(f, i) if f & 0b1111_0000 == 0 => {
if i > (usize::MAX as u64) {
return Err(ParseError::Integer(crate::qpack::prefix_int::Error::Overflow))
return Err(ParseError::Integer(
crate::qpack::prefix_int::Error::Overflow,
));
}

Ok(LiteralWithPostBaseNameRef::new(
i as usize,
prefix_string::decode(8, buf)?))
},
i as usize,
prefix_string::decode(8, buf)?,
))
}
(f, _) => Err(ParseError::InvalidPrefix(f)),
}
}
Expand Down
3 changes: 2 additions & 1 deletion h3/src/qpack/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ impl Decoder {
}

if self.table.total_inserted() != inserted_on_start {
InsertCountIncrement((self.table.total_inserted() - inserted_on_start).try_into()?).encode(write);
InsertCountIncrement((self.table.total_inserted() - inserted_on_start).try_into()?)
.encode(write);
}

Ok(self.table.total_inserted())
Expand Down
5 changes: 2 additions & 3 deletions h3/src/qpack/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,8 @@ impl Action {
let first = buf.chunk()[0];
let instruction = match DecoderInstruction::decode(first) {
DecoderInstruction::Unknown => return Err(Error::UnknownDecoderInstruction(first)),
DecoderInstruction::InsertCountIncrement => {
InsertCountIncrement::decode(&mut buf)?.map(|x| Action::ReceivedRefIncrement(x.0 as usize))
}
DecoderInstruction::InsertCountIncrement => InsertCountIncrement::decode(&mut buf)?
.map(|x| Action::ReceivedRefIncrement(x.0 as usize)),
DecoderInstruction::HeaderAck => {
HeaderAck::decode(&mut buf)?.map(|x| Action::Untrack(x.0))
}
Expand Down
22 changes: 15 additions & 7 deletions h3/src/qpack/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ impl InsertWithNameRef {
Err(IntError::UnexpectedEnd) => return Ok(None),
Err(e) => return Err(e.into()),
};
let index: usize = index.try_into().map_err(|e| ParseError::Integer(crate::qpack::prefix_int::Error::Overflow))?;
let index: usize = index
.try_into()
.map_err(|e| ParseError::Integer(crate::qpack::prefix_int::Error::Overflow))?;

Check warning on line 102 in h3/src/qpack/stream.rs

View workflow job for this annotation

GitHub Actions / Lint

unused variable: `e`

Check warning on line 102 in h3/src/qpack/stream.rs

View workflow job for this annotation

GitHub Actions / Test beta ubuntu-latest

unused variable: `e`

Check warning on line 102 in h3/src/qpack/stream.rs

View workflow job for this annotation

GitHub Actions / Test stable ubuntu-latest

unused variable: `e`

Check warning on line 102 in h3/src/qpack/stream.rs

View workflow job for this annotation

GitHub Actions / Test stable ubuntu-latest

unused variable: `e`

Check warning on line 102 in h3/src/qpack/stream.rs

View workflow job for this annotation

GitHub Actions / Check MSRV

unused variable: `e`

Check warning on line 102 in h3/src/qpack/stream.rs

View workflow job for this annotation

GitHub Actions / Check MSRV of `h3-quinn`

unused variable: `e`

let value = match prefix_string::decode(8, buf) {
Ok(x) => x,
Expand Down Expand Up @@ -170,10 +172,12 @@ impl Duplicate {
let index = match prefix_int::decode(5, buf) {
Ok((0, x)) => {
if x > (usize::MAX as u64) {
return Err(ParseError::Integer(crate::qpack::prefix_int::Error::Overflow))
return Err(ParseError::Integer(
crate::qpack::prefix_int::Error::Overflow,
));
}
x as usize
},
}
Ok((f, _)) => return Err(ParseError::InvalidPrefix(f)),
Err(IntError::UnexpectedEnd) => return Ok(None),
Err(e) => return Err(e.into()),
Expand All @@ -194,10 +198,12 @@ impl DynamicTableSizeUpdate {
let size = match prefix_int::decode(5, buf) {
Ok((0b001, x)) => {
if x > (usize::MAX as u64) {
return Err(ParseError::Integer(crate::qpack::prefix_int::Error::Overflow))
return Err(ParseError::Integer(
crate::qpack::prefix_int::Error::Overflow,
));
}
x as usize
},
}
Ok((f, _)) => return Err(ParseError::InvalidPrefix(f)),
Err(IntError::UnexpectedEnd) => return Ok(None),
Err(e) => return Err(e.into()),
Expand Down Expand Up @@ -264,10 +270,12 @@ impl InsertCountIncrement {
let insert_count = match prefix_int::decode(6, buf) {
Ok((0b00, x)) => {
if x > 64 {
return Err(ParseError::Integer(crate::qpack::prefix_int::Error::Overflow))
return Err(ParseError::Integer(
crate::qpack::prefix_int::Error::Overflow,
));
}
x as u8
},
}
Ok((f, _)) => return Err(ParseError::InvalidPrefix(f)),
Err(IntError::UnexpectedEnd) => return Ok(None),
Err(e) => return Err(e.into()),
Expand Down

0 comments on commit c4f3ba6

Please sign in to comment.