Skip to main content

Crate rpsl

Crate rpsl 

Source
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ยง

object
Creates an Object containing the given attributes.

Structsยง

Attribute
An attribute of an Object.
Name
The name of an Attribute.
Object
A RPSL object.
ObjectValidationError
Contains all attribute validation errors for an Object.
ParseError
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.