Skip to content

Commit

Permalink
add UNKNOWN to Tsig Algorithm enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Litr0 committed Jul 25, 2024
1 parent ab3b7de commit 2f59b36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/tsig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ fn digest(bytes: Vec<u8>, tsig_algorithm: TsigAlgorithm, key: Vec<u8>) -> Vec<u8
hasher.input(&bytes[..]);
hasher.result().code().to_vec()
}
TsigAlgorithm::UNKNOWN(a) => {
panic!("Unknown algorithm {}", a);
}
}
}

Expand All @@ -151,7 +154,7 @@ pub fn sign_tsig(query_msg: &mut DnsMessage, key: &[u8], alg_name: TsigAlgorithm
let tsig_rd: TSigRdata;
let new_query_message = query_msg.clone();
let original_id = query_msg.get_query_id();
let alg_name_str = String::from(alg_name);
let alg_name_str = String::from(alg_name.clone());
let tsig_rr= set_tsig_vars(alg_name_str.as_str(), key_name.as_str(),
time_signed, fudge);
let digest_comp = get_digest_request(mac_request, new_query_message.to_bytes(),
Expand Down Expand Up @@ -186,6 +189,9 @@ pub fn sign_tsig(query_msg: &mut DnsMessage, key: &[u8], alg_name: TsigAlgorithm
32);

},
TsigAlgorithm::UNKNOWN(a) => {
panic!("Unknown algorithm {}", a);
}
}
let rr_len = tsig_rd.to_bytes().len() as u16;
let signature = tsig_rd.get_mac();
Expand Down Expand Up @@ -597,7 +603,7 @@ mod tsig_test {
id
);
//partial TSIG Resource record verify the signing process
let tsig_rr = set_tsig_vars(String::from(alg_name).as_str(), &name, time_signed, fudge);
let tsig_rr = set_tsig_vars(String::from(alg_name.clone()).as_str(), &name, time_signed, fudge);
let q_for_mac = q.clone();
//creation of the signature to compare
let firma_a_comparar = sign_tsig(&mut q, key, alg_name, fudge, time_signed, name, vec![]);
Expand Down
6 changes: 4 additions & 2 deletions src/tsig/tsig_algorithm.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@

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

impl From<TsigAlgorithm> for String {
fn from(alg: TsigAlgorithm) -> String {
match alg {
TsigAlgorithm::HmacSha1 => "hmac-sha1".to_string(),
TsigAlgorithm::HmacSha256 => "hmac-sha256".to_string(),
TsigAlgorithm::UNKNOWN(s) => s,
}
}
}
Expand All @@ -19,7 +21,7 @@ impl From<String> for TsigAlgorithm {
match name {
name if name == "hmac-sha1" => TsigAlgorithm::HmacSha1,
name if name == "hmac-sha256" => TsigAlgorithm::HmacSha256,
_ => panic!("Invalid TsigAlgorithm"),
_ => TsigAlgorithm::UNKNOWN(name),
}
}
}

0 comments on commit 2f59b36

Please sign in to comment.