recipe

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package recipe strictly parses, applies, and generates bounded DKIM2 message reconstruction recipes for draft-ietf-dkim-dkim2-spec-09.

The package owns the decoded RFC 8259 schema, immutable recipe plans, reconstruction state, resource accounting, transactional application, and deterministic inverse generation from a current source state to a previous target state. Generated compact decoded JSON is conservative and reproducible but not required to be minimal. Copy-only disclosure and unavailable-body behavior are explicit closed policies, and every recipe success passes the package's strict parse, apply, and semantic reconstruction proof first.

Message-Instance base64 remains owned by instance, RFC 5322 bytes remain owned by rawmsg, and signed-header relevance and canonical hashes remain owned by canonical. Authenticated history remains owned by verify. Hash-gated revision decisions, Message-Instance formatting, and signing are outside this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsErrorCode

func IsErrorCode(err error, code ErrorCode) bool

IsErrorCode reports whether err contains a recipe Error with code.

func IsJSONSyntaxError

func IsJSONSyntaxError(err error) bool

IsJSONSyntaxError reports whether err is a recipe failure of the JSON text itself: malformed RFC 8259 syntax, a repeated member name, or a root that is not a JSON object. Draft-09 Section 14.2 reports these as "contains invalid JSON"; every schema, step, range, literal, or application failure of otherwise valid JSON is instead "Recipe <value> is invalid".

Types

type Applier

type Applier struct {
	// contains filtered or unexported fields
}

Applier owns immutable recipe application limits and reconstruction policy.

func NewApplier

func NewApplier(limits Limits) (Applier, error)

NewApplier constructs one fail-closed recipe applier.

func (Applier) Apply

func (a Applier) Apply(current State, recipe Recipe) (State, Usage, error)

Apply transactionally reconstructs both recipe dimensions under one operation budget.

func (Applier) ApplyHistorical

func (a Applier) ApplyHistorical(current State, recipe Recipe) (State, Usage, error)

ApplyHistorical strictly applies reconstructable dimensions after an explicit body-unavailable boundary.

func (Applier) Valid

func (a Applier) Valid() bool

Valid reports whether the applier owns coherent resolved limits.

type BodyAvailability

type BodyAvailability string

BodyAvailability identifies whether reconstructed body bytes exist.

const (
	// BodyAvailabilityKnown reports validated body bytes and indexing.
	BodyAvailabilityKnown BodyAvailability = "known"
	// BodyAvailabilityUnavailable reports that no body bytes exist.
	BodyAvailabilityUnavailable BodyAvailability = "unavailable"
)

func (BodyAvailability) Known

func (a BodyAvailability) Known() bool

Known reports whether availability belongs to the closed recipe vocabulary.

type BodyGenerationOutcome

type BodyGenerationOutcome string

BodyGenerationOutcome identifies the generated recipe's body dimension.

const (
	// BodyGenerationUnchanged reports that the body member is omitted.
	BodyGenerationUnchanged BodyGenerationOutcome = "unchanged"
	// BodyGenerationGenerated reports that body steps reconstruct the previous body.
	BodyGenerationGenerated BodyGenerationOutcome = "generated"
	// BodyGenerationUnavailable reports an explicitly authorized b:null result.
	BodyGenerationUnavailable BodyGenerationOutcome = "unavailable"
)

func (BodyGenerationOutcome) Known

func (o BodyGenerationOutcome) Known() bool

Known reports whether outcome belongs to the closed body-generation vocabulary.

type BodyMode

type BodyMode string

BodyMode identifies the body member form in one parsed recipe.

const (
	// BodyModeAbsent preserves the source body state.
	BodyModeAbsent BodyMode = "absent"
	// BodyModeSteps applies an ordered body recipe.
	BodyModeSteps BodyMode = "steps"
	// BodyModeUnavailable declares that prior body bytes cannot be reconstructed.
	BodyModeUnavailable BodyMode = "unavailable"
)

func (BodyMode) Known

func (m BodyMode) Known() bool

Known reports whether mode belongs to the closed recipe vocabulary.

type BodyUnavailablePolicy

type BodyUnavailablePolicy uint8

BodyUnavailablePolicy controls whether an unrepresentable previous body may become b:null.

const (
	// RejectUnavailableBody fails closed when the previous body cannot be reconstructed.
	RejectUnavailableBody BodyUnavailablePolicy = iota
	// AllowUnavailableBody permits an explicit unavailable-body success
	// outcome (Draft-09 Section 12.1 MAY). The resulting history is never
	// Fully Verified (Sections 13 and 14.2), so later verifiers report
	// PERMERROR body_history_unavailable and later signers refuse it.
	AllowUnavailableBody
)

func (BodyUnavailablePolicy) Known

func (p BodyUnavailablePolicy) Known() bool

Known reports whether policy belongs to the closed unavailable-body vocabulary.

type BodyUnavailableReason

type BodyUnavailableReason string

BodyUnavailableReason identifies a non-sensitive reason for an authorized b:null result.

const (
	// BodyUnavailableReasonUnrepresentable reports draft framing or literal unrepresentability.
	BodyUnavailableReasonUnrepresentable BodyUnavailableReason = "unrepresentable"
	// BodyUnavailableReasonLiteralRequired reports a literal forbidden by copy-only policy.
	BodyUnavailableReasonLiteralRequired BodyUnavailableReason = "literal_required"
)

func (BodyUnavailableReason) Known

func (r BodyUnavailableReason) Known() bool

Known reports whether reason belongs to the closed unavailable-body vocabulary.

type ChangeClass

type ChangeClass string

ChangeClass identifies one conservative normalized Recipe change dimension.

const (
	// ChangeClassBodyRewrite reports an authenticated body reconstruction recipe.
	ChangeClassBodyRewrite ChangeClass = "body.rewrite"
	// ChangeClassHeaderRewrite reports one or more authenticated header reconstruction recipes.
	ChangeClassHeaderRewrite ChangeClass = "header.rewrite"
)

func (ChangeClass) Known

func (c ChangeClass) Known() bool

Known reports whether the change class belongs to the closed descriptor vocabulary.

type Descriptor

type Descriptor struct {
	// contains filtered or unexported fields
}

Descriptor stores a privacy-minimized immutable Recipe projection.

func UnchangedDescriptor

func UnchangedDescriptor() Descriptor

UnchangedDescriptor returns the canonical descriptor for an absent Recipe.

func (Descriptor) AffectedHeaderCount

func (d Descriptor) AffectedHeaderCount() int

AffectedHeaderCount returns the coherence count for AffectedHeaders.

func (Descriptor) AffectedHeaders

func (d Descriptor) AffectedHeaders() []string

AffectedHeaders returns sorted unique canonical lower-case header names.

func (Descriptor) BodyMode

func (d Descriptor) BodyMode() BodyMode

BodyMode returns the exact Draft-09 body member form.

func (Descriptor) ChangeClasses

func (d Descriptor) ChangeClasses() []ChangeClass

ChangeClasses returns the sorted closed conservative change dimensions.

func (Descriptor) ChangeCount

func (d Descriptor) ChangeCount() int

ChangeCount returns the number of normalized change dimensions.

func (Descriptor) Digest

func (d Descriptor) Digest() [sha256.Size]byte

Digest returns the SHA-256 binding of the normalized descriptor.

func (Descriptor) Format

func (Descriptor) Format(state fmt.State, _ rune)

Format prevents formatting verbs from exposing message-derived descriptor facts.

func (Descriptor) GoString

func (Descriptor) GoString() string

GoString returns a constant representation without message-derived names or counts.

func (Descriptor) HasHeaderChanges

func (d Descriptor) HasHeaderChanges() bool

HasHeaderChanges reports whether h= contains at least one header dimension.

func (Descriptor) String

func (Descriptor) String() string

String returns a constant representation without message-derived names or counts.

func (Descriptor) Valid

func (d Descriptor) Valid() bool

Valid reports whether the descriptor is a coherent closed projection.

type Dimension

type Dimension string

Dimension identifies one bounded recipe dimension.

const (
	// DimensionRecipe identifies whole-plan processing.
	DimensionRecipe Dimension = "recipe"
	// DimensionHeader identifies header reconstruction.
	DimensionHeader Dimension = "header"
	// DimensionBody identifies body reconstruction.
	DimensionBody Dimension = "body"
)

func (Dimension) Known

func (d Dimension) Known() bool

Known reports whether dimension belongs to the closed recipe vocabulary.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is a typed recipe failure that never retains input-derived causes.

func (*Error) Class

func (e *Error) Class() ErrorClass

Class returns the closed recipe error class.

func (*Error) Code

func (e *Error) Code() ErrorCode

Code returns the closed recipe error code.

func (*Error) Dimension

func (e *Error) Dimension() Dimension

Dimension returns the closed recipe dimension associated with the failure.

func (*Error) Error

func (e *Error) Error() string

Error returns a deterministic secret-safe recipe diagnostic.

func (*Error) Is

func (e *Error) Is(target error) bool

Is matches recipe errors by stable code.

func (*Error) LimitName

func (e *Error) LimitName() string

LimitName returns a stable configured limit identifier.

func (*Error) Location

func (e *Error) Location() ErrorLocation

Location returns bounded structural coordinates.

type ErrorClass

type ErrorClass string

ErrorClass groups recipe failures without retaining input.

const (
	// ErrorClassOptions identifies constructor configuration failures.
	ErrorClassOptions ErrorClass = "options"
	// ErrorClassState identifies invalid domain states.
	ErrorClassState ErrorClass = "state"
	// ErrorClassLimit identifies resource-limit failures.
	ErrorClassLimit ErrorClass = "limit"
	// ErrorClassSyntax identifies malformed JSON text.
	ErrorClassSyntax ErrorClass = "syntax"
	// ErrorClassSchema identifies recipe-v1 shape failures.
	ErrorClassSchema ErrorClass = "schema"
	// ErrorClassRange identifies invalid copy coordinates.
	ErrorClassRange ErrorClass = "range"
	// ErrorClassSource identifies unavailable reconstruction input.
	ErrorClassSource ErrorClass = "source"
	// ErrorClassRequest identifies invalid generation requests.
	ErrorClassRequest ErrorClass = "request"
	// ErrorClassPolicy identifies invalid closed generation policy values.
	ErrorClassPolicy ErrorClass = "policy"
	// ErrorClassRepresentation identifies content that recipes cannot represent.
	ErrorClassRepresentation ErrorClass = "representation"
	// ErrorClassSerialization identifies deterministic output encoding failures.
	ErrorClassSerialization ErrorClass = "serialization"
	// ErrorClassInvariant identifies internal dependency or proof disagreement.
	ErrorClassInvariant ErrorClass = "invariant"
)

func (ErrorClass) Known

func (c ErrorClass) Known() bool

Known reports whether class belongs to the closed recipe vocabulary.

type ErrorCode

type ErrorCode string

ErrorCode identifies one closed recipe failure.

const (
	// ErrorCodeInvalidOptions reports unsafe or incoherent recipe limits.
	ErrorCodeInvalidOptions ErrorCode = "invalid_options"
	// ErrorCodeInvalidState reports a zero or incoherent recipe domain value.
	ErrorCodeInvalidState ErrorCode = "invalid_state"
	// ErrorCodeLimitExceeded reports a bounded resource limit failure.
	ErrorCodeLimitExceeded ErrorCode = "limit_exceeded"
	// ErrorCodeInvalidJSON reports malformed RFC 8259 syntax.
	ErrorCodeInvalidJSON ErrorCode = "invalid_json"
	// ErrorCodeDuplicateMember reports repeated JSON object names.
	ErrorCodeDuplicateMember ErrorCode = "duplicate_member"
	// ErrorCodeInvalidTopLevel reports a non-object recipe root.
	ErrorCodeInvalidTopLevel ErrorCode = "invalid_top_level"
	// ErrorCodeMissingRecipeDimension reports a root without h or b.
	ErrorCodeMissingRecipeDimension ErrorCode = "missing_recipe_dimension"
	// ErrorCodeInvalidHeaderName reports a non-RFC 5322 recipe key.
	ErrorCodeInvalidHeaderName ErrorCode = "invalid_header_name"
	// ErrorCodeNonLowercaseHeaderName reports a decoded recipe key that is not lowercase.
	ErrorCodeNonLowercaseHeaderName ErrorCode = "non_lowercase_header_name"
	// ErrorCodeNonLowercaseKey reports a decoded JSON object key that is not lowercase.
	ErrorCodeNonLowercaseKey ErrorCode = "non_lowercase_key"
	// ErrorCodeUnsignedHeaderRecipe reports a header recipe for a field that is never signed.
	ErrorCodeUnsignedHeaderRecipe ErrorCode = "unsigned_header_recipe"
	// ErrorCodeHeaderNameCollision reports ASCII case-folded key duplication.
	ErrorCodeHeaderNameCollision ErrorCode = "header_name_collision"
	// ErrorCodeInvalidHeaderRecipe reports an invalid h member shape.
	ErrorCodeInvalidHeaderRecipe ErrorCode = "invalid_header_recipe"
	// ErrorCodeInvalidBodyRecipe reports an invalid b member shape.
	ErrorCodeInvalidBodyRecipe ErrorCode = "invalid_body_recipe"
	// ErrorCodeInvalidStep reports an unknown or mixed recipe step.
	ErrorCodeInvalidStep ErrorCode = "invalid_step"
	// ErrorCodeInvalidCopyRange reports invalid inclusive copy coordinates.
	ErrorCodeInvalidCopyRange ErrorCode = "invalid_copy_range"
	// ErrorCodeCopyRangeOrder reports overlapping or descending copy ranges.
	ErrorCodeCopyRangeOrder ErrorCode = "copy_range_order"
	// ErrorCodeCopyRangeOutOfBounds reports a range outside its source.
	ErrorCodeCopyRangeOutOfBounds ErrorCode = "copy_range_out_of_bounds"
	// ErrorCodeInvalidLiteral reports invalid UTF-8, invalid base64, or line-breaking data.
	ErrorCodeInvalidLiteral ErrorCode = "invalid_literal"
	// ErrorCodeSourceUnavailable reports a copy operation without source bytes.
	ErrorCodeSourceUnavailable ErrorCode = "source_unavailable"
	// ErrorCodeInvalidGenerator reports a zero or invalid generation dependency set.
	ErrorCodeInvalidGenerator ErrorCode = "invalid_generator"
	// ErrorCodeInvalidRequest reports an invalid generation request or unknown body state.
	ErrorCodeInvalidRequest ErrorCode = "invalid_request"
	// ErrorCodeInvalidPolicy reports a value outside a closed generation policy.
	ErrorCodeInvalidPolicy ErrorCode = "invalid_policy"
	// ErrorCodeHeaderRelevance reports invalid, failing, or inconsistent relevance classification.
	ErrorCodeHeaderRelevance ErrorCode = "header_relevance"
	// ErrorCodeHeaderUnrepresentable reports a relevant header state that cannot be reconstructed.
	ErrorCodeHeaderUnrepresentable ErrorCode = "header_unrepresentable"
	// ErrorCodeBodyUnrepresentable reports a body state rejected by unavailable-body policy.
	ErrorCodeBodyUnrepresentable ErrorCode = "body_unrepresentable"
	// ErrorCodeSerializationFailure reports deterministic decoded-JSON serialization failure.
	ErrorCodeSerializationFailure ErrorCode = "serialization_failure"
	// ErrorCodeGeneratedOutputInvariant reports an internal generated parse or apply proof failure.
	ErrorCodeGeneratedOutputInvariant ErrorCode = "generated_output_invariant"
	// ErrorCodeReconstructionMismatch reports generated output that does not reconstruct the target.
	ErrorCodeReconstructionMismatch ErrorCode = "reconstruction_mismatch"
)

func (ErrorCode) Known

func (c ErrorCode) Known() bool

Known reports whether code belongs to the closed recipe vocabulary.

type ErrorDetails

type ErrorDetails struct {
	Class     ErrorClass
	LimitName string
	Expected  int
	Actual    int
	Dimension Dimension
	StepKind  StepKind
}

ErrorDetails carries bounded closed recipe diagnostics.

type ErrorLocation

type ErrorLocation struct {
	Offset        int
	StepIndex     int
	MemberIndex   int
	HeaderOrdinal int
	BodyLine      int
}

ErrorLocation carries bounded structural coordinates only.

type Generation

type Generation struct {
	// contains filtered or unexported fields
}

Generation stores one immutable closed generation success.

func (Generation) BodyOutcome

func (g Generation) BodyOutcome() BodyGenerationOutcome

BodyOutcome returns the closed body generation outcome.

func (Generation) BodyUnavailableReason

func (g Generation) BodyUnavailableReason() BodyUnavailableReason

BodyUnavailableReason returns the reason only for an unavailable-body result.

func (Generation) DecodedJSON

func (g Generation) DecodedJSON() []byte

DecodedJSON returns a detached copy of protected decoded recipe JSON.

func (Generation) Outcome

func (g Generation) Outcome() GenerationOutcome

Outcome returns the closed top-level generation outcome.

func (Generation) Recipe

func (g Generation) Recipe() (Recipe, bool)

Recipe returns a detached immutable recipe for recipe success.

func (Generation) Valid

func (g Generation) Valid() bool

Valid reports whether generation is a coherent unchanged or recipe success.

type GenerationLimits

type GenerationLimits struct {
	// RecipeLimits bounds generated recipe syntax and internal parse/apply proof.
	RecipeLimits Limits
	// MaxInputBytes bounds previous and current state bytes examined.
	MaxInputBytes int
	// MaxInputItems bounds previous and current header fields and body lines examined.
	MaxInputItems int
	// MaxCandidateEntries bounds retained current-source occurrences.
	MaxCandidateEntries int
	// MaxCandidateKeyBytes bounds protected exact-match keys retained from the source.
	MaxCandidateKeyBytes int
	// MaxComparisons bounds target lookups and monotone candidate advances.
	MaxComparisons int
	// MaxGenerationWorkUnits bounds aggregate scans, plans, output, and proof work.
	MaxGenerationWorkUnits int
}

GenerationLimits bounds one deterministic generation operation and its proof.

func DefaultGenerationLimits

func DefaultGenerationLimits() GenerationLimits

DefaultGenerationLimits returns the exact closed generation hard ceilings.

func (GenerationLimits) Validate

func (l GenerationLimits) Validate() error

Validate rejects negative, widening, overflowing, or incoherent generation limits.

type GenerationOutcome

type GenerationOutcome string

GenerationOutcome identifies one closed top-level generation success.

const (
	// GenerationOutcomeUnchanged reports that no recipe-semantic relevant change exists.
	GenerationOutcomeUnchanged GenerationOutcome = "unchanged"
	// GenerationOutcomeRecipe reports one initialized recipe result.
	GenerationOutcomeRecipe GenerationOutcome = "recipe"
)

func (GenerationOutcome) Known

func (o GenerationOutcome) Known() bool

Known reports whether outcome belongs to the closed generation vocabulary.

type GenerationRequest

type GenerationRequest struct {
	// contains filtered or unexported fields
}

GenerationRequest stores one immutable inverse-generation request.

func NewGenerationRequest

func NewGenerationRequest(previous, current State, bodyPolicy BodyUnavailablePolicy, literalPolicy LiteralDisclosurePolicy) (GenerationRequest, error)

NewGenerationRequest constructs a request from known initialized states and closed policies.

func (GenerationRequest) BodyUnavailablePolicy

func (r GenerationRequest) BodyUnavailablePolicy() BodyUnavailablePolicy

BodyUnavailablePolicy returns the closed body-unavailable policy.

func (GenerationRequest) Current

func (r GenerationRequest) Current() State

Current returns the immutable current source state.

func (GenerationRequest) LiteralPolicy

func (r GenerationRequest) LiteralPolicy() LiteralDisclosurePolicy

LiteralPolicy returns the closed literal-disclosure policy.

func (GenerationRequest) Previous

func (r GenerationRequest) Previous() State

Previous returns the immutable previous target state.

func (GenerationRequest) Valid

func (r GenerationRequest) Valid() bool

Valid reports whether the request contains two known states and closed policies.

type GenerationUsage

type GenerationUsage struct {
	// contains filtered or unexported fields
}

GenerationUsage stores bounded numeric accounting for one generation attempt.

func (GenerationUsage) CandidateKeyBytes

func (u GenerationUsage) CandidateKeyBytes() int

CandidateKeyBytes returns protected key bytes retained during matching.

func (GenerationUsage) Candidates

func (u GenerationUsage) Candidates() int

Candidates returns retained source occurrence entries.

func (GenerationUsage) Comparisons

func (u GenerationUsage) Comparisons() int

Comparisons returns exact target lookup and candidate advance operations.

func (GenerationUsage) GeneratedLiterals

func (u GenerationUsage) GeneratedLiterals() int

GeneratedLiterals returns planned data-string count.

func (GenerationUsage) GeneratedSteps

func (u GenerationUsage) GeneratedSteps() int

GeneratedSteps returns planned recipe steps.

func (GenerationUsage) InputBytes

func (u GenerationUsage) InputBytes() int

InputBytes returns source and target bytes examined.

func (GenerationUsage) InputItems

func (u GenerationUsage) InputItems() int

InputItems returns source and target items examined.

func (GenerationUsage) JSONBytes

func (u GenerationUsage) JSONBytes() int

JSONBytes returns generated decoded recipe bytes.

func (GenerationUsage) LiteralBytes

func (u GenerationUsage) LiteralBytes() int

LiteralBytes returns previous content bytes authorized for disclosure.

func (GenerationUsage) ProofWorkUnits

func (u GenerationUsage) ProofWorkUnits() int

ProofWorkUnits returns parse, application, and semantic reconstruction proof work.

func (GenerationUsage) Valid

func (u GenerationUsage) Valid() bool

Valid reports whether usage contains only initialized nonnegative counters.

func (GenerationUsage) WorkUnits

func (u GenerationUsage) WorkUnits() int

WorkUnits returns aggregate generation work.

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator stores immutable validated generation dependencies and limits.

func NewGenerator

func NewGenerator(limits GenerationLimits, relevance HeaderRelevance) (Generator, error)

NewGenerator constructs an immutable fail-closed recipe generator.

func (Generator) Generate

Generate deterministically plans and returns a recipe only after strict parse, apply, and semantic proof.

func (Generator) Limits

func (g Generator) Limits() GenerationLimits

Limits returns the immutable normalized generation limits.

func (Generator) Valid

func (g Generator) Valid() bool

Valid reports whether the generator was constructed with validated dependencies.

type HeaderRelevance

type HeaderRelevance interface {
	Validate() error
	IsRelevantHeader(nameLower string) (bool, error)
}

HeaderRelevance classifies validated canonical lowercase header names. Implementations must be immutable, deterministic, concurrent-safe, and must return errors that do not retain or expose header names or message content.

type Limits

type Limits struct {
	// MaxDecodedRecipeBytes bounds one decoded r= JSON payload.
	MaxDecodedRecipeBytes int
	// MaxJSONDepth bounds nested unknown extension traversal.
	MaxJSONDepth int
	// MaxJSONMembers bounds all object members scanned.
	MaxJSONMembers int
	// MaxJSONTokens bounds total JSON tokenization work.
	MaxJSONTokens int
	// MaxHeaderNames bounds distinct recipe and state header groups.
	MaxHeaderNames int
	// MaxHeaderNameBytes bounds one RFC 5322 header field name.
	MaxHeaderNameBytes int
	// MaxTotalHeaderNameBytes bounds retained recipe-key storage.
	MaxTotalHeaderNameBytes int
	// MaxStepsPerHeader bounds one header-name instruction array.
	MaxStepsPerHeader int
	// MaxBodySteps bounds the body instruction array.
	MaxBodySteps int
	// MaxTotalSteps bounds all retained recipe steps.
	MaxTotalSteps int
	// MaxCopyRanges bounds copy-range metadata.
	MaxCopyRanges int
	// MaxCopiedItemsPerRange bounds one inclusive copy expansion.
	MaxCopiedItemsPerRange int
	// MaxTotalCopiedItems bounds all copied fields or lines per apply.
	MaxTotalCopiedItems int
	// MaxDataStrings bounds retained literal strings.
	MaxDataStrings int
	// MaxDataStringBytes bounds one decoded literal before dimension checks.
	MaxDataStringBytes int
	// MaxTotalLiteralBytes bounds all retained decoded literal bytes.
	MaxTotalLiteralBytes int
	// MaxHeaderFields bounds reconstructed header occurrence count.
	MaxHeaderFields int
	// MaxHeaderFieldBytes bounds one reconstructed logical field.
	MaxHeaderFieldBytes int
	// MaxHeaderLineBytes bounds one reconstructed physical header line.
	MaxHeaderLineBytes int
	// MaxHeaderBytes bounds the reconstructed header block.
	MaxHeaderBytes int
	// MaxBodyLines bounds reconstructed body line indexing.
	MaxBodyLines int
	// MaxBodyLineBytes bounds one reconstructed body line.
	MaxBodyLineBytes int
	// MaxStateBytes bounds one reconstructed raw message state.
	MaxStateBytes int
	// MaxOperationWorkUnits bounds aggregate parsing or application work.
	MaxOperationWorkUnits int
}

Limits bounds one recipe parse or apply operation.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits returns the closed hard ceilings for one recipe operation.

func (Limits) Validate

func (l Limits) Validate() error

Validate rejects negative, widening, or incoherent recipe limits.

type LiteralDisclosurePolicy

type LiteralDisclosurePolicy uint8

LiteralDisclosurePolicy controls whether generated recipes may embed previous content.

const (
	// CopyOnly forbids embedding previous header or body content.
	CopyOnly LiteralDisclosurePolicy = iota
	// AllowLiterals permits bounded literal disclosure in generated recipes.
	AllowLiterals
)

func (LiteralDisclosurePolicy) Known

func (p LiteralDisclosurePolicy) Known() bool

Known reports whether policy belongs to the closed disclosure vocabulary.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser converts decoded Draft-09 recipe JSON into immutable plans.

func NewParser

func NewParser(limits Limits, relevance HeaderRelevance) (Parser, error)

NewParser constructs a strict recipe parser with resolved restrictive limits. The header relevance classifier is mandatory because Draft-09 Section 5.1 forbids recipes for header fields that are not signed; the parser rejects such recipes instead of leaving the rule to each caller.

func (Parser) Parse

func (p Parser) Parse(input []byte) (Recipe, Usage, error)

Parse parses one complete decoded RFC 8259 recipe object.

func (Parser) Valid

func (p Parser) Valid() bool

Valid reports whether the parser owns coherent resolved limits and a stable header relevance classifier.

type Recipe

type Recipe struct {
	// contains filtered or unexported fields
}

Recipe stores one immutable parsed Draft-09 reconstruction plan.

func (Recipe) BodyMode

func (r Recipe) BodyMode() BodyMode

BodyMode returns the closed body-member form.

func (Recipe) CanonicalHeaderNames

func (r Recipe) CanonicalHeaderNames() []string

CanonicalHeaderNames returns the lowercase canonical names of every header plan, the names whose fields the applier regroups when the recipe is applied.

func (Recipe) Descriptor

func (r Recipe) Descriptor() Descriptor

Descriptor returns a privacy-minimized immutable view of this Recipe.

func (Recipe) HasHeaderRecipe

func (r Recipe) HasHeaderRecipe() bool

HasHeaderRecipe reports whether h was present.

func (Recipe) HeaderNames

func (r Recipe) HeaderNames() []string

HeaderNames returns deterministic retained key spellings only.

func (Recipe) Valid

func (r Recipe) Valid() bool

Valid reports whether the recipe is an initialized coherent closed model.

type State

type State struct {
	// contains filtered or unexported fields
}

State stores one immutable controlled reconstruction state.

func NewHeadersOnlyState

func NewHeadersOnlyState(headers rawmsg.HeaderBlock) (State, error)

NewHeadersOnlyState constructs a header-known state whose body is truthfully unavailable, such as the text/rfc822-headers original of a delivery-status report. Application and generation semantics are unchanged: the state behaves exactly like the body-unavailable state produced by a null recipe.

func NewState

func NewState(message rawmsg.Message) (State, error)

NewState clones one validated raw message into a known reconstruction state.

func (State) Body

func (s State) Body() (rawmsg.Body, bool)

Body returns a cloned known body and false when unavailable.

func (State) BodyState

func (s State) BodyState() BodyAvailability

BodyState returns the closed body availability.

func (State) Framing

func (s State) Framing() rawmsg.MessageFraming

Framing returns the validated header/body separator form of the state, or the empty value for an invalid state. A body-unavailable state always reports delimited framing because its body is unknown rather than empty.

func (State) Headers

func (s State) Headers() rawmsg.HeaderBlock

Headers returns an immutable cloned header block.

func (State) Materialize

func (s State) Materialize() (rawmsg.Message, error)

Materialize returns exact raw framing when both dimensions are known.

func (State) Valid

func (s State) Valid() bool

Valid reports whether the state is initialized and coherent.

type StepKind

type StepKind string

StepKind identifies one closed recipe operation.

const (
	// StepKindCopy identifies an inclusive source-range copy.
	StepKindCopy StepKind = "copy"
	// StepKindData identifies UTF-8 literal data emission ("d").
	StepKindData StepKind = "data"
	// StepKindBinaryData identifies base64-carried literal emission ("u") for
	// lines or values that are not valid UTF-8 (Draft-09 Section 5).
	StepKindBinaryData StepKind = "binary_data"
)

func (StepKind) Known

func (k StepKind) Known() bool

Known reports whether kind belongs to the Draft-09 recipe vocabulary.

type Usage

type Usage struct {
	// contains filtered or unexported fields
}

Usage records bounded work performed by one parse or apply operation.

func (Usage) DecodedBytes

func (u Usage) DecodedBytes() int

DecodedBytes returns charged decoded recipe bytes.

func (Usage) EmittedBytes

func (u Usage) EmittedBytes() int

EmittedBytes returns charged reconstructed output bytes.

func (Usage) Items

func (u Usage) Items() int

Items returns charged structural and emitted items.

func (Usage) Valid

func (u Usage) Valid() bool

Valid reports whether usage was initialized with nonnegative bounded counters.

func (Usage) WorkUnits

func (u Usage) WorkUnits() int

WorkUnits returns total charged operation work.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL