Skip to content

Commit

Permalink
feat: Add TsigAlgorithm enum and conversions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Litr0 committed Jul 25, 2024
1 parent 1af18b6 commit 4399bb7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/tsig/tsig_algorithm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TsigAlgorithm {
HmacSha1,
HmacSha256,
}

impl From<TsigAlgorithm> for String {
fn from(alg: TsigAlgorithm) -> String {
match alg {
TsigAlgorithm::HmacSha1 => "hmac-sha1".to_string(),
TsigAlgorithm::HmacSha256 => "hmac-sha256".to_string(),
}
}
}

impl From<String> 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"),
}
}
}

0 comments on commit 4399bb7

Please sign in to comment.