typomania/lib.rs
1//! Checks and a harness to detect potential typosquatting in a package repository.
2//!
3//! This is ported from [`typogard`][typogard], originally by a team led by Matthew Taylor at the
4//! University of Kansas and published alongside the [_Defending Against Package
5//! Typosquatting_][paper] paper, and adapted by [Dan Gardner][dangardner] for crates.io
6//! specifically.
7//!
8//! ## Theory of operation
9//!
10//! Given a [`Corpus`] of popular packages, the checks in the [`checks`] module allow new or
11//! interesting packages to be matched against that corpus to look for common typosquatting
12//! techniques. Custom checks may also be written by implementing [`checks::Check`]; custom checks
13//! should use [`checks::Squat::Custom`] when returning potential typosquats.
14//!
15//! A [`Harness`] is provided that can be used to run a suite of checks against a single package,
16//! or — when the `rayon` feature is enabled — against many packages at once in parallel.
17//!
18//! Checks and corpora both use instances of [`Package`], which provides a basic lowest common
19//! denominator representation of ecosystem-specific packages. Users are expected to implement
20//! [`Package`] (and the related [`AuthorSet`]) on their native package type for analysis.
21//!
22//! ## Tracing
23//!
24//! Potentially expensive operations are traced using `tracing` at the TRACE level, except for
25//! [`Harness::check`], which is traced at the DEBUG level.
26//!
27//! [dangardner]: https://github.com/dangardner/typogard
28//! [paper]: https://dl.acm.org/doi/10.1007/978-3-030-65745-1_7
29//! [typogard]: https://github.com/mt3443/typogard
30
31pub mod checks;
32pub mod corpus;
33mod error;
34mod harness;
35mod package;
36
37pub use corpus::Corpus;
38pub use error::{BoxError, Result};
39pub use harness::{Builder as HarnessBuilder, Error as HarnessError, Harness};
40pub use package::{AuthorSet, Package};