forked from
oppi.li/at-advent
this repo has no description
1use atrium_identity::handle::DnsTxtResolver;
2use hickory_resolver::TokioAsyncResolver;
3
4/// Setup for dns resolver for the handle resolver
5pub struct HickoryDnsTxtResolver {
6 resolver: hickory_resolver::TokioAsyncResolver,
7}
8
9impl Default for HickoryDnsTxtResolver {
10 fn default() -> Self {
11 Self {
12 resolver: TokioAsyncResolver::tokio_from_system_conf()
13 .expect("failed to create resolver"),
14 }
15 }
16}
17
18impl DnsTxtResolver for HickoryDnsTxtResolver {
19 async fn resolve(
20 &self,
21 query: &str,
22 ) -> Result<Vec<String>, Box<dyn std::error::Error + Send + Sync + 'static>> {
23 Ok(self
24 .resolver
25 .txt_lookup(query)
26 .await?
27 .iter()
28 .map(|txt| txt.to_string())
29 .collect())
30 }
31}