-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #344 from parkma99/main
add "Deny All" Dns Resolver
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::DnsResolver; | ||
use rama_net::address::Domain; | ||
use rama_utils::macros::error::static_str_error; | ||
use std::net::{Ipv4Addr, Ipv6Addr}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
#[non_exhaustive] | ||
/// a [`DnsResolver`] implementation which | ||
/// denies all incoming DNS requests with a [`DnsDeniedError`]. | ||
pub struct DenyAllDns; | ||
|
||
impl DenyAllDns { | ||
#[inline] | ||
/// Create a new [`Default`] [`DenyAllDns`]. | ||
pub fn new() -> Self { | ||
Self::default() | ||
} | ||
} | ||
|
||
static_str_error! { | ||
#[doc = "Dns denied"] | ||
pub struct DnsDeniedError; | ||
} | ||
|
||
impl DnsResolver for DenyAllDns { | ||
type Error = DnsDeniedError; | ||
|
||
async fn ipv4_lookup(&self, _domain: Domain) -> Result<Vec<Ipv4Addr>, Self::Error> { | ||
Err(DnsDeniedError) | ||
} | ||
|
||
async fn ipv6_lookup(&self, _domain: Domain) -> Result<Vec<Ipv6Addr>, Self::Error> { | ||
Err(DnsDeniedError) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters