#domain #tld #data-file #etld

public-suffix

Crate for efficient determination of eTLD+1 based on the Mozilla Public Suffix List

3 releases

0.1.2 Sep 16, 2024
0.1.1 Dec 14, 2023
0.1.0 Jul 28, 2023

#101 in Web programming

Download history 5887/week @ 2024-07-29 4854/week @ 2024-08-05 7473/week @ 2024-08-12 8764/week @ 2024-08-19 8106/week @ 2024-08-26 8291/week @ 2024-09-02 10458/week @ 2024-09-09 21632/week @ 2024-09-16 29449/week @ 2024-09-23 26335/week @ 2024-09-30 32836/week @ 2024-10-07 31283/week @ 2024-10-14 36033/week @ 2024-10-21 29999/week @ 2024-10-28 34710/week @ 2024-11-04 36116/week @ 2024-11-11

137,357 downloads per month
Used in 2 crates (via passkey-client)

MIT/Apache

430KB
22K SLoC

public-suffix by 1Password

github version documentation

The public-suffix crate provides a compact and efficient way to determine the effective TLD-plus-one of any given domain.

This crate is driven by a data file, held in public-suffix-list.dat and contains code to generate Rust structures to represent this information in code.

Using this Crate

You can use this crate directly, using the included DEFAULT_PROVIDER list as follows:

let domain = "sainsburys.co.uk";
let etld = DEFAULT_PROVIDER.effective_tld_plus_one(domain);

Generating a Custom Public Suffix List

It may be that users of this crate wish to compute eTLD+1 differently for certain domains according to the needs of their particular application.

To do this, provide your own version of public_suffix_list.dat and run the included generator script (gen.sh) with the contents of your custom TLD file.

This will regenerate the Rust representations of that data for inclusion in your own crate. The main.go program called by gen.sh supports various arguments to control its output. The main arguments you may wish to use are:

  • --output-path - directory in which to place the generated files.
  • --base-name - the base name of the generated files. The generator will create ${base-name}.rs and ${base-name}_test.rs in the directory specified by output-path.
  • --struct - the name of the Rust struct that will be generated to represent your custom TLD data.
  • --crate - a boolean controlling whether the struct will be created as public_suffix::StructName (if true) or crate::StructName (if false). When you are creating your own structs, always set this to false.

Using Your Custom Public Suffix List

Next, in your Cargo.toml, disable the default-provider feature in this crate: default-features = false. Doing so will remove the built-in implementation of the public suffix list structure and instead you can use your own:

type PublicSuffixList = ListProvider<my_custom_tld_list::MyCustomTldListStruct>;

pub const MY_CUSTOM_TLD_LIST: PublicSuffixList = PublicSuffixList::new();

...then you can call the same functions on MY_CUSTOM_TLD_LIST:

let domain = "sainsburys.co.uk";
let etld = MY_CUSTOM_TLD_LIST.effective_tld_plus_one(domain);

Contributing and feedback

public-suffix is an open source project.

🐛 If you find an issue you'd like to report, or otherwise have feedback, please file a new Issue.

🧑‍💻 If you'd like to contribute to the code please start by filing or commenting on an Issue so we can track the work.

Credits

Made with ❤️ and ☕ by the 1Password team.

Get a free 1Password account for your open source project

Does your team need a secure way to manage passwords and other credentials for your open source project? Head on over to our other repository to get a 1Password Teams account on us:

1Password for Open Source Projects

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps

Features