Documentation
¶
Overview ¶
package yaml provides mechanisms for serializing and deserializing spam policies in YAML.
spam uses protocol buffers as the canonical format for several reasons: * Most invalid states are impossible to represent. For example, proto has sum types, while Go does not. * Efficient wire format for transmission and storage. * The protocol buffer compiler writes all the risky parsing code.
That being said, for human consumption, textproto spam policies leave a bit to be desired.
YAML is a JSON-based text serialization format that has human readability as its top priority.
For very complex policies, the `define` key may be used to set up anchors that can be referred to later, in the actual policy. See the below example.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadSumType = errors.New("too many members were set on this sum type") ErrInvalidOperand = errors.New("operand must be 0x followed by a hex string of at least 1 byte") )
Functions ¶
func DebugString ¶
DebugString converts a spam policy into YAML or the error string from attempting to do so.
func Decode ¶
Decode parses a YAML document for a spam policy, and converts it into the canonical protobuf form.
Example ¶
package main import ( "fmt" "google.golang.org/protobuf/encoding/prototext" "github.com/chrisfenner/tpm-spam/pkg/yaml" ) func main() { policy := ` # Set up some anchors - these aren't part of the parsed policy until aliased. define: - &spam2_major_version_greater_than_5 spam: index: 2 offset: 8 gt: 0x00000005 - &spam2_minor_version_greater_than_10 spam: index: 2 offset: 12 gt: 0x0000000a and: - or: - spam: index: 1 offset: 0 eq: 0x0001020304050607 - spam: index: 1 offset: 0 eq: 0x08090A0B0C0D0E0F - or: - *spam2_major_version_greater_than_5 - *spam2_minor_version_greater_than_10` proto := yaml.DecodeOrPanic(policy) opts := prototext.MarshalOptions{ Multiline: true, Indent: " ", } fmt.Println(opts.Format(proto)) }
Output:
func DecodeOrPanic ¶
DecodeOrPanic parses a YAML document for a spam policy, or panics if there is an error.
Types ¶
type Policy ¶
type Policy struct { And []*Policy `yaml:",omitempty"` Or []*Policy `yaml:",omitempty"` Spam *SpamPolicy `yaml:",flow,omitempty"` // Define is ignored when assembling policies: use it to define anchors for readability. Define []interface{} }
INTERNAL: Only exported for manipulation by the `yaml` package.
type SpamPolicy ¶
type SpamPolicy struct { Index uint32 Offset uint32 Eq string `yaml:",omitempty"` Neq string `yaml:",omitempty"` Gt string `yaml:",omitempty"` Gte string `yaml:",omitempty"` Lt string `yaml:",omitempty"` Lte string `yaml:",omitempty"` Bitset string `yaml:",omitempty"` Bitclear string `yaml:",omitempty"` }
INTERNAL: Only exported for manipulation by the `yaml` package.