@@ -9,6 +9,24 @@ See https://aboutcode.org for more information about nexB OSS projects.
99
1010*/
1111
12+ //! A library to validate whether a PURL actually exists.
13+ //!
14+ //! **purl-validator** is a Rust library for validating
15+ //! [`Package URLs` (PURLs)](https://github.com/package-url/purl-spec).
16+ //! It works fully offline, including in **air-gapped** or **restricted environments**,
17+ //! and answers one key question: **Does the package this PURL represents actually exist?**
18+ //!
19+ //!
20+ //! # Examples
21+ //!
22+ //! Simplest way to use `validate` is as follows:
23+ //!
24+ //! ```
25+ //! use purl_validator::validate;
26+ //!
27+ //! let result: bool = validate("pkg:nuget/FluentValidation");
28+ //! ```
29+ //!
1230
1331use fst:: Set ;
1432use memmap2:: Mmap ;
@@ -28,9 +46,20 @@ fn load_fst(path: &Path) -> Set<Mmap> {
2846 Set :: new ( mmap) . expect ( "Failed to load FST from mmap" )
2947}
3048
31- pub fn validate ( packageurl : & str ) -> bool {
49+ fn strip_and_check_purl ( packageurl : & str , fst_map : & Set < Mmap > ) -> bool {
3250 let trimmed_packageurl = packageurl. trim_end_matches ( "/" ) ;
33- VALIDATOR . contains ( trimmed_packageurl)
51+ fst_map. contains ( trimmed_packageurl)
52+ }
53+
54+ /// Validate a Package URL (PURL)
55+ ///
56+ /// Returns `true` if the given base PURL represents an existing package,
57+ /// otherwise returns `false`.
58+ ///
59+ /// Use pre-built FST (Finite State Transducer) to perform lookups and confirm whether
60+ /// the **base PURL** exists.
61+ pub fn validate ( packageurl : & str ) -> bool {
62+ strip_and_check_purl ( packageurl, & VALIDATOR )
3463}
3564
3665#[ cfg( test) ]
0 commit comments