Selaa lähdekoodia

Put IDNA code behind a default feature

This feature (which is on by default) provides users with a way to opt-out of the Unicode-related dependencies.
Benjamin Sago 4 vuotta sitten
vanhempi
commit
2aed64618a
3 muutettua tiedostoa jossa 13 lisäystä ja 4 poistoa
  1. 2 1
      Cargo.toml
  2. 5 3
      dns/Cargo.toml
  3. 6 0
      dns/src/strings.rs

+ 2 - 1
Cargo.toml

@@ -69,6 +69,7 @@ datetime = { version = "0.5.1", default_features = false }
 pretty_assertions = "0.7"
 
 [features]
-default = ["tls", "https"]
+default = ["idna", "tls", "https"]
+idna = ["dns/idna"]
 tls = ["dns-transport/tls"]
 https = ["dns-transport/https"]

+ 5 - 3
dns/Cargo.toml

@@ -19,14 +19,16 @@ byteorder = "1.3"
 # packet printing
 base64 = "0.13"
 
+# idna encoding
+unic-idna = { version = "0.9.0", optional = true }
+
 # testing
 mutagen = { git = "https://github.com/llogiq/mutagen", optional = true }
 
-# idna encoding
-unic-idna = "0.9.0"
-
 [dev-dependencies]
 pretty_assertions = "0.7"
 
 [features]
+default = []  # these are enabled in the main dog crate
+idna = ["unic-idna"]
 with_mutagen = ["mutagen"]  # needs nightly

+ 6 - 0
dns/src/strings.rs

@@ -20,11 +20,17 @@ pub struct Labels {
     segments: Vec<(u8, String)>,
 }
 
+#[cfg(feature = "idna")]
 fn label_to_ascii(label: &str) -> Result<String, unic_idna::Errors> {
     let flags = unic_idna::Flags{use_std3_ascii_rules: true, transitional_processing: false, verify_dns_length: true};
     unic_idna::to_ascii(label, flags)
 }
 
+#[cfg(not(feature = "idna"))]
+fn label_to_ascii(label: &str) -> Result<String, ()> {
+    Ok(label.to_owned())
+}
+
 impl Labels {
 
     /// Creates a new empty set of labels, which represent the root of the DNS