diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-11-13 14:06:28 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-11-13 14:06:28 +0100 |
commit | ac992e085ace12ed3268f82f02ee97af0321ea99 (patch) | |
tree | 25d923c2550aab6d42e32d70b87a066a0d2ba6a5 | |
parent | 0ea1e08fa5b9ac52339d1c35a2995a00fdcf4413 (diff) |
make hexdump infallible
Empty input now results in an empty output String.
-rw-r--r-- | src/error.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 8 | ||||
-rw-r--r-- | src/util.rs | 4 |
3 files changed, 6 insertions, 8 deletions
diff --git a/src/error.rs b/src/error.rs index 348fb47..333374d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -10,8 +10,6 @@ pub enum Error { LeaseNotFound, #[error("server did not include a client id option")] NoClientId, - #[error("can't hexdump empty slice")] - NoData, #[error("server did not include a domain name servers option")] NoDns, #[error("server did not include an ia_pd option")] diff --git a/src/main.rs b/src/main.rs index ba4ad0e..d870de8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -231,8 +231,8 @@ fn handle(dhcp6: &mut Dhcp6, dhcp6c: &mut Dhcp6c, buf: &[u8]) -> Result<()> { if client_id != dhcp6.duid.as_ref() { return Err(Error::WrongClientId( - hexdump(dhcp6.duid.as_ref())?, - hexdump(client_id)?, + hexdump(dhcp6.duid.as_ref()), + hexdump(client_id), )); } @@ -240,8 +240,8 @@ fn handle(dhcp6: &mut Dhcp6, dhcp6c: &mut Dhcp6c, buf: &[u8]) -> Result<()> { dhcp6.server_id = server_id.to_vec(); } else if server_id != &dhcp6.server_id { return Err(Error::WrongServerId( - hexdump(&dhcp6.server_id)?, - hexdump(server_id)?, + hexdump(&dhcp6.server_id), + hexdump(server_id), )); } diff --git a/src/util.rs b/src/util.rs index e226ca6..7b3517f 100644 --- a/src/util.rs +++ b/src/util.rs @@ -48,12 +48,12 @@ pub fn inform() { } } -pub fn hexdump<A: AsRef<[u8]>>(data: A) -> Result<String> { +pub fn hexdump<A: AsRef<[u8]>>(data: A) -> String { data.as_ref() .iter() .map(|byte| format!("{:02x}", byte)) .reduce(|acc, ch| acc + &ch) - .ok_or(Error::NoData) + .unwrap_or(String::new()) } pub fn sys_to_instant(sys: SystemTime) -> Result<Instant> { |