1use std::{fmt::Display, num::ParseIntError};
2
3#[derive(Debug)]
5pub enum TlshError {
6 DataLenOverflow,
8 InvalidHashValue,
10 MinSizeNotReached,
12 ParseHexFailed,
14 NoValidHash,
16}
17
18impl From<ParseIntError> for TlshError {
19 fn from(_: ParseIntError) -> Self {
20 Self::ParseHexFailed
21 }
22}
23
24impl Display for TlshError {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 match self {
27 TlshError::DataLenOverflow => {
28 write!(f, "Input file is too big. Maximal file size is 4GB.")
29 }
30 TlshError::InvalidHashValue => write!(f, "Can't parse hash string"),
31 TlshError::MinSizeNotReached => {
32 write!(f, "TLSH requires an input of at least 50 bytes.")
33 }
34 TlshError::ParseHexFailed => write!(f, "Can't convert hex string to integer"),
35 TlshError::NoValidHash => write!(
36 f,
37 "No valid hash could be computed. See https://github.com/trendmicro/tlsh/issues/79"
38 ),
39 }
40 }
41}