summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Nimmagadda <sunil@nimmagadda.net>2024-11-24 10:21:14 +0530
committerSunil Nimmagadda <sunil@nimmagadda.net>2024-11-24 10:21:14 +0530
commit86db852b18229aa1277627ea5f3f13fa71040ed3 (patch)
tree6a9947e33f315b9ee9632d6bee75b1ba7eb71153
parentf2f82afcc47ecf2895d6292751309c7c3a8a8e65 (diff)
Let's stick to 80 line length.
-rw-r--r--rustfmt.toml1
-rw-r--r--src/vrrpv2.rs30
2 files changed, 18 insertions, 13 deletions
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 0000000..df99c69
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1 @@
+max_width = 80
diff --git a/src/vrrpv2.rs b/src/vrrpv2.rs
index 643d6c3..3ad19b6 100644
--- a/src/vrrpv2.rs
+++ b/src/vrrpv2.rs
@@ -111,7 +111,9 @@ impl VRRPv2 {
]
.as_ref(),
)?;
- wr.write_all([self.auth_type as u8, self.advertisement_interval].as_ref())?;
+ wr.write_all(
+ [self.auth_type as u8, self.advertisement_interval].as_ref(),
+ )?;
wr.write_all(self.checksum.to_be_bytes().as_ref())?;
for ip in self.ip_addrs.iter() {
wr.write_all(&ip.to_bits().to_be_bytes())?;
@@ -170,8 +172,8 @@ fn parse(bytes: &[u8]) -> Result<VRRPv2, VRRPv2Error> {
/// use std::net::Ipv4Addr;
///
/// let bytes = [
-/// 0x21, 0x01, 0x64, 0x01, 0x00, 0x01, 0xba, 0x52, 0xc0, 0xa8, 0x00, 0x01, 0x00, 0x00, 0x00,
-/// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/// 0x21, 0x01, 0x64, 0x01, 0x00, 0x01, 0xba, 0x52, 0xc0, 0xa8, 0x00, 0x01, 0x00, 0x00,
+/// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/// ];
/// let expected = VRRPv2 {
/// virtual_router_id: 1,
@@ -214,8 +216,8 @@ fn test_incomplete_bytes() {
#[test]
fn test_invalid_version() {
let bytes = [
- 0x31, 0x1, 0x2a, 0x0, 0x0, 0x1, 0xb5, 0xfd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
- 0x0, 0x0, 0x0,
+ 0x31, 0x1, 0x2a, 0x0, 0x0, 0x1, 0xb5, 0xfd, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
];
assert_eq!(from_bytes(&bytes), Err(VRRPv2Error::InvalidVersion));
}
@@ -223,8 +225,8 @@ fn test_invalid_version() {
#[test]
fn test_invalid_type() {
let bytes = [
- 0x20, 0x2a, 0x64, 0x1, 0x0, 0x1, 0xaa, 0x29, 0xc0, 0xa8, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0,
- 0x0, 0x0, 0x0,
+ 0x20, 0x2a, 0x64, 0x1, 0x0, 0x1, 0xaa, 0x29, 0xc0, 0xa8, 0x0, 0x1, 0x0,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
];
assert_eq!(from_bytes(&bytes), Err(VRRPv2Error::InvalidType));
}
@@ -232,8 +234,9 @@ fn test_invalid_type() {
#[test]
fn test_invalid_auth_type() {
let bytes = [
- 0x21, 0x01, 0x64, 0x01, 0x03, 0x01, 0xba, 0x52, 0xc0, 0xa8, 0x00, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x21, 0x01, 0x64, 0x01, 0x03, 0x01, 0xba, 0x52, 0xc0, 0xa8, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00,
];
assert_eq!(from_bytes(&bytes), Err(VRRPv2Error::InvalidAuthType));
}
@@ -241,8 +244,9 @@ fn test_invalid_auth_type() {
#[test]
fn test_invalid_checksum() {
let bytes = [
- 0x21, 0x01, 0x64, 0x01, 0x00, 0x01, 0xbb, 0x52, 0xc0, 0xa8, 0x00, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x21, 0x01, 0x64, 0x01, 0x00, 0x01, 0xbb, 0x52, 0xc0, 0xa8, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00,
];
assert_eq!(from_bytes(&bytes), Err(VRRPv2Error::InvalidChecksum));
}
@@ -274,8 +278,8 @@ fn test_checksum_another() {
#[test]
fn test_to_bytes() {
let in_bytes = [
- 0x21, 0x01, 0x64, 0x01, 0x00, 0x01, 0xba, 0x52, 0xc0, 0xa8, 0x00, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x21, 0x01, 0x64, 0x01, 0x00, 0x01, 0xba, 0x52, 0xc0, 0xa8, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
let vrrpv2 = from_bytes(&in_bytes).expect("parsing failed");
let out_bytes = vrrpv2.to_bytes().expect("conversion failed");