diff options
| author | Max Audron <audron@cocaine.farm> | 2025-02-22 22:59:01 +0100 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2025-02-22 22:59:01 +0100 |
| commit | b8ad94cd5061445a45d0790eee36014d34ad6817 (patch) | |
| tree | fb7d11e136b968d2f2b3593ba9163894baed8912 /src/message/handshake/types.rs | |
| parent | update dependencies and fix errors (diff) | |
replace deprecated failure crate with thiserror
this changes the public API in that all our methods now return a proper
ProtocolError crate. Needed change anyways to properly deal with all our
errors in the long run.
Will still need to do a pass through the crate to remove all existing
unwraps where it makes sense.
Diffstat (limited to 'src/message/handshake/types.rs')
| -rw-r--r-- | src/message/handshake/types.rs | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/src/message/handshake/types.rs b/src/message/handshake/types.rs index 6d4960d..fd8c8fa 100644 --- a/src/message/handshake/types.rs +++ b/src/message/handshake/types.rs @@ -1,8 +1,6 @@ use std::result::Result; use std::vec::Vec; -use failure::Error; - use crate::error::ProtocolError; use crate::primitive::Variant; use crate::util; @@ -12,7 +10,7 @@ use crate::message::handshake::{HandshakeDeserialize, HandshakeSerialize}; use crate::primitive::VariantMap; impl HandshakeSerialize for VariantMap { - fn serialize<'a>(&'a self) -> Result<Vec<u8>, Error> { + fn serialize<'a>(&'a self) -> Result<Vec<u8>, ProtocolError> { let mut res: Vec<u8> = Vec::new(); for (k, v) in self { @@ -29,7 +27,7 @@ impl HandshakeSerialize for VariantMap { } impl HandshakeDeserialize for VariantMap { - fn parse(b: &[u8]) -> Result<(usize, Self), Error> { + fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> { let (_, len) = i32::parse(&b[0..4])?; let mut pos: usize = 4; @@ -45,7 +43,7 @@ impl HandshakeDeserialize for VariantMap { match name { Variant::String(x) => map.insert(x, value), Variant::ByteArray(x) => map.insert(x, value), - _ => bail!(ProtocolError::WrongVariant), + _ => return Err(ProtocolError::WrongVariant), }; } @@ -58,21 +56,18 @@ pub fn serialize_variantmap() { let mut test_variantmap = VariantMap::new(); test_variantmap.insert("Configured".to_string(), Variant::bool(true)); let bytes = [ - 0, 0, 0, 2, 0, 0, 0, 10, 0, 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, - 117, 0, 114, 0, 101, 0, 100, 0, 0, 0, 1, 0, 1, + 0, 0, 0, 2, 0, 0, 0, 10, 0, 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, + 114, 0, 101, 0, 100, 0, 0, 0, 1, 0, 1, ] .to_vec(); - assert_eq!( - HandshakeSerialize::serialize(&test_variantmap).unwrap(), - bytes - ); + assert_eq!(HandshakeSerialize::serialize(&test_variantmap).unwrap(), bytes); } #[test] pub fn deserialize_variantmap() { let test_bytes: &[u8] = &[ - 0, 0, 0, 2, 0, 0, 0, 10, 0, 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, - 117, 0, 114, 0, 101, 0, 100, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 2, 0, 0, 0, 10, 0, 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, + 114, 0, 101, 0, 100, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, ]; let mut test_variantmap = VariantMap::new(); test_variantmap.insert("Configured".to_string(), Variant::bool(true)); @@ -86,8 +81,8 @@ pub fn deserialize_variantmap() { #[test] pub fn deserialize_variantmap_utf8() { let test_bytes: &[u8] = &[ - 0, 0, 0, 2, 0, 0, 0, 12, 0, 0, 0, 0, 10, 67, 111, 110, 102, 105, 103, 117, 114, 101, 100, - 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 2, 0, 0, 0, 12, 0, 0, 0, 0, 10, 67, 111, 110, 102, 105, 103, 117, 114, 101, 100, 0, 0, 0, 1, + 0, 1, 0, 0, 0, 1, ]; let mut test_variantmap = VariantMap::new(); test_variantmap.insert("Configured".to_string(), Variant::bool(true)); |
