mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2024-12-27 04:08:20 +01:00
Did some renaming because calling all those fields idna didn't really make sense.
Also switched to the less strict domain to ascii because the errors aren't exactly very well machine readable.
This commit is contained in:
parent
d202ebb14e
commit
1108b7d653
16
src/idna.rs
16
src/idna.rs
@ -14,7 +14,7 @@ pub enum NameType {
|
||||
Ascii,
|
||||
#[default]
|
||||
Unicode,
|
||||
IDNA,
|
||||
IDN,
|
||||
}
|
||||
|
||||
// Note, that the
|
||||
@ -23,7 +23,7 @@ pub struct IdnaName {
|
||||
pub unicode: String,
|
||||
// if null the unicode version only contains ascii range chars,
|
||||
// not neccessary to encode
|
||||
pub idna: Option<String>,
|
||||
pub idn: Option<String>,
|
||||
pub original_was: NameType,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub decoder_error: Option<String>,
|
||||
@ -37,7 +37,7 @@ impl IdnaName {
|
||||
let unicode: String;
|
||||
let decoder_error;
|
||||
if s.starts_with("xn--") && s.is_ascii() {
|
||||
original_was = NameType::IDNA;
|
||||
original_was = NameType::IDN;
|
||||
let (uc, ures) = idna::domain_to_unicode(s);
|
||||
unicode = uc;
|
||||
decoder_error = ures.map_or_else(|e| Some(e.to_string()), |_| None);
|
||||
@ -45,10 +45,10 @@ impl IdnaName {
|
||||
unicode = s.clone();
|
||||
decoder_error = None;
|
||||
};
|
||||
let (idna, encoder_error) = match idna::domain_to_ascii_strict(s) {
|
||||
Ok(idna) => {
|
||||
if &idna != s || original_was == NameType::IDNA{
|
||||
(Some(idna), None)
|
||||
let (idn, encoder_error) = match idna::domain_to_ascii(s) {
|
||||
Ok(idn) => {
|
||||
if &idn != s || original_was == NameType::IDN {
|
||||
(Some(idn), None)
|
||||
} else {
|
||||
original_was = NameType::Ascii;
|
||||
(None, None)
|
||||
@ -61,7 +61,7 @@ impl IdnaName {
|
||||
|
||||
IdnaName {
|
||||
unicode: unicode,
|
||||
idna: idna,
|
||||
idn: idn,
|
||||
original_was: original_was,
|
||||
|
||||
decoder_error: decoder_error,
|
||||
|
@ -77,7 +77,7 @@ pub struct IpResult {
|
||||
pub struct DigResult {
|
||||
records: simple_dns::DnsLookupResult,
|
||||
#[serde(skip_serializing_if = "IdnaName::was_ascii")]
|
||||
idna: IdnaName,
|
||||
idn: IdnaName,
|
||||
}
|
||||
|
||||
struct ServiceSharedState {
|
||||
@ -487,9 +487,9 @@ async fn get_dig_result(
|
||||
DigResult {
|
||||
records: simple_dns::lookup(
|
||||
&state.dns_resolver,
|
||||
&(idna_name.idna.clone().unwrap_or(name.to_owned())+"."),
|
||||
&(idna_name.idn.clone().unwrap_or(name.to_owned())+"."),
|
||||
true).await,
|
||||
idna: idna_name,
|
||||
idn: idna_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user