#domain #allowlist #blocklist #dns

match-domain

Rapid checker for the prefix and suffix matching of domain names

3 releases

0.1.2 Nov 22, 2024
0.1.1 Nov 21, 2024
0.1.0 Nov 21, 2024

#1744 in Network programming

Download history 150/week @ 2024-11-15 234/week @ 2024-11-22 6/week @ 2024-11-29 29/week @ 2024-12-06

419 downloads per month

MIT license

11KB
146 lines

match-domain: Rapid checker for the prefix and suffix matching of domain names, written in Rust

match-domain match-domain License: MIT Unit Test

Double-array trie based domain matcher, written in Rust.

This enables you to check if the given domain name matches the prefix or suffix of the domain name in the trie.

Usage

use match_domain::DomainMatchingRule;

let domain_matching_rule = DomainMatchingRule::try_from(vec![
    "www.google.com".to_string(),
    "*.google.com".to_string(),
    "yahoo.co.*".to_string(),
  ])
  .unwrap();

assert!(domain_matching_rule.is_matched("wwxx.google.com"));
assert!(domain_matching_rule.is_matched("yahoo.co.jp"));

assert!(!domain_matching_rule.is_matched("www.yahoo.com"));
assert!(!domain_matching_rule.is_matched("www.yahoo.co.jp"));

Note that for the DomainMatchingRule::is_matched(&self, domain_name: &str) -> bool method:

  • the argument domain_name should be in lowercase
  • the argument domain_name should not contain a leading dot

Dependencies

~2.5–4MB
~73K SLoC