Expand description
A Routing Policy Specification Language (RPSL) parser with a focus on speed and correctness.
โก๏ธ 130-250x faster than other parsers
๐ฐ Complete implementation for multiline RPSL values
๐ฌ Able to parse objects directly from whois server responses
๐ง Low memory footprint by leveraging zero-copy
๐งช Robust parsing of any valid input ensured by Property Based Tests
๐งฉ Optional validation via customizable specifications
ยงUsage
ยงParsing RPSL objects
A string containing an object in RPSL notation can be parsed using the parse_object function.
use rpsl::{parse_object, Object, spec::Raw};
let role_acme = "
role: ACME Company
address: Packet Street 6
address: 128 Series of Tubes
address: Internet
email: rpsl-rs@github.com
nic-hdl: RPSL1-RIPE
source: RIPE
";
let parsed: Object<Raw> = parse_object(role_acme)?;This returns an Object<Raw>, a sorted Attribute<Raw> collection which contain string references
pointing to attributes and their values from the parsed text.
role: ACME Company โโโโโโโโโโโโโโโโ &"role": &"ACME Company"
address: Packet Street 6 โโโโโโโโโโโโโ &"address": &"Packet Street 6"
address: 128 Series of Tubes โโโโโโโโโ &"address": &"128 Series of Tubes"
address: Internet โโโโโโโโโโโโโโโโโโโโ &"address": &"Internet"
email: rpsl-rs@github.com โโโโโโโโโโ &"email": &"rpsl-rs@github.com"
nic-hdl: RPSL1-RIPE โโโโโโโโโโโโโโโโโโ &"nic-hdl": &"RPSL1-RIPE"
source: RIPE โโโโโโโโโโโโโโโโโโโโโโโโ &"source": &"RIPE"Parsing is intentionally lenient and returns objects typed with Raw, meaning no
validation has been applied. To ensure the object conforms to a Specification,
it can be converted to a typed spec after parsing.
let validated: Object<Rfc2622> = parsed.into_spec()?;For more information on object validation, see the spec module.
ยงParsing a WHOIS server response
WHOIS servers often respond to queries by returning multiple related objects.
An example ARIN query for AS32934 will return with the requested ASNumber object first, followed by its associated OrgName:
$ whois -h whois.arin.net AS32934
ASNumber: 32934
ASName: FACEBOOK
ASHandle: AS32934
RegDate: 2004-08-24
Updated: 2012-02-24
Comment: Please send abuse reports to abuse@facebook.com
Ref: https://rdap.arin.net/registry/autnum/32934
OrgName: Facebook, Inc.
OrgId: THEFA-3
Address: 1601 Willow Rd.
City: Menlo Park
StateProv: CA
PostalCode: 94025
Country: US
RegDate: 2004-08-11
Updated: 2012-04-17
Ref: https://rdap.arin.net/registry/entity/THEFA-3
To extract each individual object, the parse_whois_response function can be used to parse the response into a Vec containing all individual Objects within the response. Examples can be found in the function documentation.
ยงOptional Features
The following cargo features can be used to enable additional functionality.
- simd (enabled by default): Enables the Winnow simd feature which improves string search performance using simd.
- serde: Enables Object serialization using Serde.
- json: Provides JSON serialization of an Object using Serde JSON.
Modulesยง
- spec
- Specifications and validation rules for RPSL objects.
Macrosยง
Structsยง
- Attribute
- An attribute of an
Object. - Name
- The name of an
Attribute. - Object
- A RPSL object.
- Object
Validation Error - Contains all attribute validation errors for an
Object. - Parse
Error - An error that can occur when parsing RPSL text.
Enumsยง
- Value
- The value of an
Attribute. Since only some values contain multiple lines and single line values do not require additional heap allocation, an Enum is used to represent both variants.
Functionsยง
- parse_
object - Parse RPSL into an
Object, borrowing from the source. - parse_
whois_ response - Parse a WHOIS server response into
Objects contained within.