Skip to main content

Module policy

Module policy 

Source
Expand description

Pluggable parser policies for “Safe YAML” enforcement. Pluggable parser policies for “Safe YAML” enforcement.

A Policy inspects parser events as the document is loaded and rejects any that violate organisational constraints — common examples are “no anchors”, “no custom tags”, or “no scalar larger than N bytes”. Policies fire on the AST loader path; if any policy is registered the streaming fast-path is bypassed automatically so the policy contract is honoured everywhere.

Built-in policies live in this module:

  • DenyAnchors — reject any document that defines or dereferences an anchor.
  • DenyTags — reject any tagged scalar / collection.
  • MaxScalarLength — cap individual scalar length in bytes.

Custom policies implement the trait directly. Stateful policies that need to mutate during a parse should hold their state behind interior mutability (std::sync::Mutex or equivalent).

§Examples

use noyalib::{from_str_with_config, ParserConfig, Value};
use noyalib::policy::DenyAnchors;

let cfg = ParserConfig::new().with_policy(DenyAnchors);
let res: Result<Value, _> =
    from_str_with_config("k: &x 1\nv: *x\n", &cfg);
assert!(res.is_err(), "DenyAnchors must reject anchored input");

Structs§

DenyAnchors
Reject any document that defines an anchor (&name) or dereferences one (*name).
DenyTags
Reject any document carrying a custom (non-default) tag.
MaxScalarLength
Cap the byte length of any individual scalar.
PolicyEvent
Lightweight projection of a parser event for policy inspection.

Enums§

PolicyEventKind
Kind of parser event handed to a policy.

Traits§

Policy
Pluggable “Safe YAML” policy.