Skip to content

Commit

Permalink
perf: oer: format! in error messages has too much impact (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicceboy authored Nov 29, 2024
1 parent ff3fa0f commit 8b42b54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/error/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@ pub enum DecodeErrorKind {
},

/// Input is provided as BIT slice for nom in UPER/APER.
/// On BER/CER/DER it is as BYTE slice.
/// On BER/CER/DER/OER/COER it is a BYTE slice.
/// Hence, `needed` field can describe either bits or bytes depending on the codec.
#[snafu(display("Need more BITS to continue: ({:?}).", needed))]
#[snafu(display("Need more data to continue: ({:?}).", needed))]
Incomplete {
/// Amount of bits/bytes needed.
needed: nom::Needed,
Expand Down
14 changes: 7 additions & 7 deletions src/oer/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ use alloc::{
vec::Vec,
};

use core::num::NonZeroUsize;
use nom::Needed;

use crate::{
de::{Decode, Error as _},
oer::EncodingRules,
types::{
self,
Expand All @@ -20,7 +24,7 @@ use crate::{
GeneralString, GeneralizedTime, Ia5String, IntegerType, NumericString, ObjectIdentifier,
PrintableString, SetOf, Tag, TeletexString, UtcTime, VisibleString,
},
Codec, Decode,
Codec,
};

use bitvec::{order::Msb0, view::BitView};
Expand Down Expand Up @@ -190,19 +194,15 @@ impl<'input, const RFC: usize, const EFC: usize> Decoder<'input, RFC, EFC> {
}

/// Extracts data from input by length and updates the input
/// Since we rely on memory and `BitSlice`, we cannot handle larger data length than `0x1fff_ffff_ffff_ffff`
/// 'length' is the length of the data in bytes (octets)
/// Returns the data
fn extract_data_by_length(&mut self, length: usize) -> Result<&'input [u8], DecodeError> {
if length == 0 {
return Ok(&[]);
}
let (data, rest) = self.input.split_at_checked(length).ok_or_else(|| {
DecodeError::parser_fail(
alloc::format!(
"Unexpected end of data when parsing &[u8] with length {}",
length
),
DecodeError::incomplete(
Needed::Size(NonZeroUsize::new(length - self.input.len()).unwrap()),
self.codec(),
)
})?;
Expand Down

0 comments on commit 8b42b54

Please sign in to comment.