decode header bytes only

This commit is contained in:
yggverse 2025-03-19 03:23:20 +02:00
parent 6dbf49cea3
commit ab8eb402a8
6 changed files with 61 additions and 17 deletions

View file

@ -31,7 +31,14 @@ impl Certificate {
/// Create new `Self` from buffer include header bytes
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
use std::str::FromStr;
match std::str::from_utf8(buffer) {
let len = buffer.len();
match std::str::from_utf8(
&buffer[..if len > super::HEADER_LEN {
super::HEADER_LEN
} else {
len
}],
) {
Ok(header) => Self::from_str(header),
Err(e) => Err(Error::Utf8Error(e)),
}