Expand description
New netdoc parsing arrangements, with derive
§Parsing principles
A parseable network document is a type implementing NetdocParseable.
usually via the
NetdocParseable derive=deftly macro`.
A document type is responsible for recognising its own heading item. Its parser will also be told other of structural items that it should not consume. The structural lines can then be used to pass control to the appropriate parser.
A “structural item” is a netdoc item that is defines the structure of the document. This includes the intro items for whole documents, the items that introduce document sections (which we model by treating the section as a sub-document) and signature items (which introduce the signatures at the end of the document, and after which no non-signature items may appear).
§Ordering
We don’t always parse things into a sorted order. Sorting will be done when assembling documents, before outputting.
§Types, and signature handling
Most top-level network documents are signed somehow. In this case there are three types:
-
FooUnverified: a signedFoo, with its signatures, not yet verified. ImplementsNetdocUnverified, typically by invoking theNetdocUParseablenverifiedderive macro onFoo.Type-specific methods are provided for verification, to obtain a
Foo. -
Foo: the body data for the document. This doesn’t contain any signatures. Having one of these to play with means signatures have already been validated. Can be parsed as part of the signed document, via theNetdocParseableimplementation onFooUnverified, and then obtained via.verify_...method(s) onFooUnverified, -
FooSignatures: the signatures for aFoo. ImplementsNetdocParseableSignatures, via derive, with#[deftly(netdoc(signatures))].
§Relationship to tor_netdoc::parse
This is a completely new parsing approach, based on different principles.
The key principle is the recognition of “structural keywords”,
recursively within a parsing stack, via the pNetdocParseable] trait.
This allows the parser to be derived. We have type-driven parsing of whole Documents, Items, and their Arguments and Objects, including of their multiplicity.
The different keyword handling means we can’t use most of the existing lexer, and need new item parsing API:
NetdocParseabletrait.KeywordReftype.ItemStream,UnparsedItem,ArgumentStream,UnparsedObject.
The different error handling means we have our own error types. (The crate’s existing parse errors have information that we don’t track, and is also a portmanteau error for parsing, writing, and other functions.)
Document signing is handled in a more abstract way.
Some old netdoc constructs are not supported.
For example, the obsolete opt prefix on safe-to-ignore Items.
The parser may make different decisions about netdocs with anomalous item ordering.
Re-exports§
pub use keyword::KeywordRef;
Modules§
- derive 🔒
- Deriving
NetdocParseable - error 🔒
- Parsing errors
- impls 🔒
- Implementations of our useful traits, on external and parsing-mode types
- keyword
- Keywords in netdocs
- lex 🔒
- Lexing of netdoc elements
- lines 🔒
- Version of
std::str::Linesthat tracks line numbers and hasremainder() - multiplicity
- Multiplicity of fields (Items and Arguments)
- poc
- Proof-of-concept parser using parse2 for network status documents.
- sig_
hashes - Hash types suitable for use as
#[deftly(netdoc(signature(hash_accu = TY))] - signatures 🔒
- Handling of netdoc signatures
- structural 🔒
- Structural keyword recognition helpers
- traits 🔒
- Core model for netdoc parsing
Structs§
- Argument
Stream - Reader for arguments on an Item
- IsStructural
- Token indicating that a keyword is structural
- Item
Stream - Top-level reader: Netdoc text interpreted as a stream of items
- Lines
- Version of
std::str::Linesthat tracks line numbers and hasremainder() - NoFurther
Arguments - End of an argument list that does not accept any further (unknown) arguments
- Parse
Error - Error encountered when parsing a document, including its location
- Parse
Input - Input to a network document top-level parsing operation
- Parse
Options - Options for parsing
- Peeked
- Information about the next line we have peeked
- Signature
Hash Inputs - Inputs needed to calculate a specific signature hash for a specific Item
- Signatures
Data - The signatures information extracted from a signed network document
- StopAt
- Predicate for testing whether a keyword is a structural one that we should stop at
- Unexpected
Argument - An unexpected argument was encountered
- Unparsed
Item - An Item that has been lexed but not parsed
- Unparsed
Object - An Object that has been lexed but not parsed
Enums§
- Argument
Error - Problem found when parsing an individual argument in a netdoc keyword item
- Error
Problem - Problem found when parsing a document
- Verify
Failed - Error from signature verification (and timeliness check)
Traits§
- HasUnverified
Parsed Body - Network document that has an unparsed body type (internal trait)
- Item
Argument Parseable - An (individual) argument that can be parsed from in a netdoc
- Item
Object Parseable - An Object value that be parsed from a netdoc
- Item
Value Parseable - An item (value) that can be parsed in a netdoc
- Netdoc
Parseable - A document or section that can be parsed
- Netdoc
Parseable Fields - A collection of fields that can be parsed within a section
- Netdoc
Parseable Signatures - The signatures section of a network document, that can be parsed
- Netdoc
Unverified - A network document with (unverified) signatures
- Signature
Hashes Accumulator - Hash(es) for a signature item
- Signature
Item Parseable - A signature item that can appear in a netdoc
- Stop
Predicate - Raw predicate, usually a closure, that can appear within
StopAt. - StrExt
- Extension trait adding a method to
str
Functions§
- check_
validity_ time - Utility function to check that a time is within a validity period
- check_
validity_ time_ tolerance - Like
check_validity_time()but with a tolerance to support clock skews. - parse_
internal 🔒 - Common code for
parse_netdocandparse_netdoc_multiple - parse_
netdoc - Parse a network document - toplevel entrypoint
- parse_
netdoc_ multiple - Parse multiple concatenated network documents - toplevel entrypoint
- parse_
netdoc_ multiple_ with_ offsets - Parse multiple network documents, also returning their offsets - toplevel entrypoint
Type Aliases§
- NdaSystem
Time Deprecated Syntax - Date and time in deprecated ISO8601-with-space separate arguments syntax