From 4399bb7f30a3f0db847045e8cb5d3b148658bced Mon Sep 17 00:00:00 2001 From: Litr0 Date: Thu, 25 Jul 2024 12:11:18 -0400 Subject: [PATCH] feat: Add TsigAlgorithm enum and conversions This commit adds the TsigAlgorithm enum, which represents the supported TSIG algorithms for DNS messages. It includes the HmacSha1 and HmacSha256 algorithms. The enum also provides conversions to and from strings for easy serialization and deserialization. --- src/tsig/tsig_algorithm.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/tsig/tsig_algorithm.rs diff --git a/src/tsig/tsig_algorithm.rs b/src/tsig/tsig_algorithm.rs new file mode 100644 index 00000000..5bdf4f0e --- /dev/null +++ b/src/tsig/tsig_algorithm.rs @@ -0,0 +1,25 @@ + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum TsigAlgorithm { + HmacSha1, + HmacSha256, +} + +impl From for String { + fn from(alg: TsigAlgorithm) -> String { + match alg { + TsigAlgorithm::HmacSha1 => "hmac-sha1".to_string(), + TsigAlgorithm::HmacSha256 => "hmac-sha256".to_string(), + } + } +} + +impl From for TsigAlgorithm { + fn from(name: String) -> TsigAlgorithm { + match name { + name if name == "hmac-sha1" => TsigAlgorithm::HmacSha1, + name if name == "hmac-sha256" => TsigAlgorithm::HmacSha256, + _ => panic!("Invalid TsigAlgorithm"), + } + } +} \ No newline at end of file