fix: allow all status codes with catch_all

10..69 range is still checked, see comment at L52
This commit is contained in:
DarkCat09 2024-08-01 12:35:50 +04:00
parent 0a77d0c2e9
commit 2b6150a8e5
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3

View file

@ -48,6 +48,12 @@ pub enum StatusCode {
ClientCerts = 60,
CertNotAuthorized = 61,
CertNotValid = 62,
// 1..6 first digit range check is still
// covered by conversion into ReplyType
// (see Status::parse_status)
#[num_enum(catch_all)]
Unknown(u8),
}
const ASCII_ZERO: u8 = 48; // '0'
@ -58,9 +64,12 @@ impl Status {
// '2' - '0' = 50 - 48 = 2 (from byte '2' to uint 2)
let first = buf[0] - ASCII_ZERO;
let second = buf[1] - ASCII_ZERO;
let code = first * 10 + second;
Ok(Status {
// get enum item for 2-digit status code
status_code: StatusCode::try_from_primitive(first * 10 + second)?,
status_code: StatusCode::try_from_primitive(code)?,
// get enum entry for first digit
reply_type: ReplyType::try_from_primitive(first)?,
// provide separate field for the 2nd digit