mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 09:05:45 +00:00
decode header bytes only
This commit is contained in:
parent
6dbf49cea3
commit
ab8eb402a8
6 changed files with 61 additions and 17 deletions
|
|
@ -31,7 +31,14 @@ impl Certificate {
|
||||||
/// Create new `Self` from buffer include header bytes
|
/// Create new `Self` from buffer include header bytes
|
||||||
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
use std::str::FromStr;
|
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),
|
Ok(header) => Self::from_str(header),
|
||||||
Err(e) => Err(Error::Utf8Error(e)),
|
Err(e) => Err(Error::Utf8Error(e)),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,14 @@ impl Permanent {
|
||||||
/// Create new `Self` from buffer include header bytes
|
/// Create new `Self` from buffer include header bytes
|
||||||
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
match std::str::from_utf8(buffer) {
|
let len = buffer.len();
|
||||||
|
match std::str::from_utf8(
|
||||||
|
&buffer[..if len > super::super::HEADER_LEN {
|
||||||
|
super::super::HEADER_LEN
|
||||||
|
} else {
|
||||||
|
len
|
||||||
|
}],
|
||||||
|
) {
|
||||||
Ok(header) => Self::from_str(header),
|
Ok(header) => Self::from_str(header),
|
||||||
Err(e) => Err(Error::Utf8Error(e)),
|
Err(e) => Err(Error::Utf8Error(e)),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,14 @@ impl Temporary {
|
||||||
/// Create new `Self` from buffer include header bytes
|
/// Create new `Self` from buffer include header bytes
|
||||||
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
match std::str::from_utf8(buffer) {
|
let len = buffer.len();
|
||||||
|
match std::str::from_utf8(
|
||||||
|
&buffer[..if len > super::super::HEADER_LEN {
|
||||||
|
super::super::HEADER_LEN
|
||||||
|
} else {
|
||||||
|
len
|
||||||
|
}],
|
||||||
|
) {
|
||||||
Ok(header) => Self::from_str(header),
|
Ok(header) => Self::from_str(header),
|
||||||
Err(e) => Err(Error::Utf8Error(e)),
|
Err(e) => Err(Error::Utf8Error(e)),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,14 @@ impl Input {
|
||||||
/// Create new `Self` from buffer include header bytes
|
/// Create new `Self` from buffer include header bytes
|
||||||
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
use std::str::FromStr;
|
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),
|
Ok(header) => Self::from_str(header),
|
||||||
Err(e) => Err(Error::Utf8Error(e)),
|
Err(e) => Err(Error::Utf8Error(e)),
|
||||||
}
|
}
|
||||||
|
|
@ -69,17 +76,19 @@ impl std::fmt::Display for Input {
|
||||||
impl std::str::FromStr for Input {
|
impl std::str::FromStr for Input {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
fn from_str(header: &str) -> Result<Self, Self::Err> {
|
fn from_str(header: &str) -> Result<Self, Self::Err> {
|
||||||
if let Some(postfix) = header.strip_prefix("10") {
|
if header.len() <= super::HEADER_LEN {
|
||||||
return Ok(Self::Default {
|
if let Some(postfix) = header.strip_prefix("10") {
|
||||||
header: header.to_string(),
|
return Ok(Self::Default {
|
||||||
message: message(postfix),
|
header: header.to_string(),
|
||||||
});
|
message: message(postfix),
|
||||||
}
|
});
|
||||||
if let Some(postfix) = header.strip_prefix("11") {
|
}
|
||||||
return Ok(Self::Sensitive {
|
if let Some(postfix) = header.strip_prefix("11") {
|
||||||
header: header.to_string(),
|
return Ok(Self::Sensitive {
|
||||||
message: message(postfix),
|
header: header.to_string(),
|
||||||
});
|
message: message(postfix),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(Error::Protocol)
|
Err(Error::Protocol)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,14 @@ impl Redirect {
|
||||||
/// Create new `Self` from buffer include header bytes
|
/// Create new `Self` from buffer include header bytes
|
||||||
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
use std::str::FromStr;
|
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),
|
Ok(header) => Self::from_str(header),
|
||||||
Err(e) => Err(Error::Utf8Error(e)),
|
Err(e) => Err(Error::Utf8Error(e)),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,14 @@ impl Success {
|
||||||
/// Create new `Self` from buffer include header bytes
|
/// Create new `Self` from buffer include header bytes
|
||||||
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
use std::str::FromStr;
|
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),
|
Ok(header) => Self::from_str(header),
|
||||||
Err(e) => Err(Error::Utf8Error(e)),
|
Err(e) => Err(Error::Utf8Error(e)),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue