diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2021-01-15 09:51:27 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2021-01-15 11:34:49 +0100 |
commit | de649ea58966273392f4ab09f2bb72bb75650ae2 (patch) | |
tree | 794bc953ade0610d30c373d94b43ad06c8309944 /store | |
parent | 59a59ac5bf9cc9be2698eb35376c3b58fd483252 (diff) |
net: Make conversion from u8 to Policy fallible.
Diffstat (limited to 'store')
-rw-r--r-- | store/src/backend/mod.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/store/src/backend/mod.rs b/store/src/backend/mod.rs index 8e913436..a285d635 100644 --- a/store/src/backend/mod.rs +++ b/store/src/backend/mod.rs @@ -1,6 +1,7 @@ //! Storage backend. use std::cmp; +use std::convert::TryFrom; use std::fmt; use std::io; use std::rc::Rc; @@ -304,7 +305,7 @@ impl MappingServer { if mapping_policy < 0 || mapping_policy > 3 { return Err(super::Error::ProtocolError.into()); } - let mapping_policy = net::Policy::from(mapping_policy as u8); + let mapping_policy = net::Policy::try_from(mapping_policy as u8)?; if mapping_policy != policy { return Err(net::Error::PolicyViolation(mapping_policy) @@ -1112,7 +1113,7 @@ impl node::mapping_iter::Server for MappingIterServer { if network_policy < 0 || network_policy > 3 { fail!(node::Error::SystemError); } - let network_policy = net::Policy::from(network_policy as u8); + let network_policy = sry!(net::Policy::try_from(network_policy as u8)); let mut entry = pry!(results.get().get_result()).init_ok(); entry.set_realm(&realm); @@ -1310,6 +1311,12 @@ impl From<net::Error> for node::Error { } } +impl From<net::TryFromU8Error> for node::Error { + fn from(_: net::TryFromU8Error) -> Self { + node::Error::SystemError + } +} + impl From<io::Error> for node::Error { fn from(_: io::Error) -> Self { node::Error::SystemError |