cap

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: BSD-2-Clause Imports: 22 Imported by: 0

README

cap

Go Reference License

A Go implementation of OASIS Common Alerting Protocol Version 1.2 and the Canadian Profile (CAP-CP).

Go 1.27 or newer is required.

The package provides XML parsing and encoding, JSON encoding, CAP 1.2 validation, CAP-CP 1.0 single-message validation, geometry helpers, XML Signature parsing, and enveloped signature verification.

Usage

package main

import (
	"fmt"
	"os"

	"github.com/tannerryan/cap"
)

func main() {
	contents, err := os.ReadFile("alert.xml")
	if err != nil {
		panic(err)
	}
	alert, err := cap.ParseCAP(contents)
	if err != nil {
		panic(err)
	}
	if err := alert.Validate().Err(); err != nil {
		panic(err)
	}
	for _, info := range alert.Info {
		fmt.Println(info.Headline)
	}
}

ParseCAP checks XML syntax, namespaces, dates, and code values. Call Validate for semantic CAP checks. Use ValidateCAPCP for the Canadian profile, MarshalCAP to encode an alert, and VerifySignature with trusted certificate roots to check a signed message. Validation returns errors for broken rules and warnings for recommendations. CAP-CP validation does not download its separately managed event and location lists or message history.

Development

Install the development tools with make deps, then run make check.

License

This project is available under the BSD 2-Clause License.

Documentation

Overview

Package cap parses, validates, and encodes OASIS Common Alerting Protocol Version 1.2 messages, including CAP-CP 1.0. It also provides geometry helpers and enveloped XML signature verification.

Index

Constants

This section is empty.

Variables

View Source
var CategoryMapping = map[string]Category{
	"Geo":       CategoryGeo,
	"Met":       CategoryMet,
	"Safety":    CategorySafety,
	"Security":  CategorySecurity,
	"Rescue":    CategoryRescue,
	"Fire":      CategoryFire,
	"Health":    CategoryHealth,
	"Env":       CategoryEnv,
	"Transport": CategoryTransport,
	"Infra":     CategoryInfra,
	"CBRNE":     CategoryCBRNE,
	"Other":     CategoryOther,
}

CategoryMapping maps CAP category values to Category constants. Callers must not modify it.

View Source
var CertaintyMapping = map[string]Certainty{
	"Observed": CertaintyObserved,
	"Likely":   CertaintyLikely,
	"Possible": CertaintyPossible,
	"Unlikely": CertaintyUnlikely,
	"Unknown":  CertaintyUnknown,
}

CertaintyMapping maps CAP certainty values to Certainty constants. Callers must not modify it.

View Source
var MsgTypeMapping = map[string]MsgType{
	"Alert":  MsgTypeAlert,
	"Update": MsgTypeUpdate,
	"Cancel": MsgTypeCancel,
	"Ack":    MsgTypeAck,
	"Error":  MsgTypeError,
}

MsgTypeMapping maps CAP message type values to MsgType constants. Callers must not modify it.

View Source
var ResponseTypeMapping = map[string]ResponseType{
	"Shelter":  ResponseTypeShelter,
	"Evacuate": ResponseTypeEvacuate,
	"Prepare":  ResponseTypePrepare,
	"Execute":  ResponseTypeExecute,
	"Avoid":    ResponseTypeAvoid,
	"Monitor":  ResponseTypeMonitor,
	"Assess":   ResponseTypeAssess,
	"AllClear": ResponseTypeAllClear,
	"None":     ResponseTypeNone,
}

ResponseTypeMapping maps CAP response values to ResponseType constants. Callers must not modify it.

View Source
var ScopeMapping = map[string]Scope{
	"Public":     ScopePublic,
	"Restricted": ScopeRestricted,
	"Private":    ScopePrivate,
}

ScopeMapping maps CAP scope values to Scope constants. Callers must not modify it.

View Source
var SeverityMapping = map[string]Severity{
	"Extreme":  SeverityExtreme,
	"Severe":   SeveritySevere,
	"Moderate": SeverityModerate,
	"Minor":    SeverityMinor,
	"Unknown":  SeverityUnknown,
}

SeverityMapping maps CAP severity values to Severity constants. Callers must not modify it.

View Source
var StatusMapping = map[string]Status{
	"Actual":   StatusActual,
	"Exercise": StatusExercise,
	"System":   StatusSystem,
	"Test":     StatusTest,
	"Draft":    StatusDraft,
}

StatusMapping maps CAP status values to Status constants. Callers must not modify it.

View Source
var UrgencyMapping = map[string]Urgency{
	"Immediate": UrgencyImmediate,
	"Expected":  UrgencyExpected,
	"Future":    UrgencyFuture,
	"Past":      UrgencyPast,
	"Unknown":   UrgencyUnknown,
}

UrgencyMapping maps CAP urgency values to Urgency constants. Callers must not modify it.

Functions

func MarshalCAP added in v1.1.0

func MarshalCAP(alert *Alert) ([]byte, error)

MarshalCAP encodes an alert as an indented CAP XML document. Re-encoding a signed alert does not preserve its signature validity.

func SignatureCertificates added in v1.1.0

func SignatureCertificates(data []byte) ([]*x509.Certificate, error)

SignatureCertificates returns the certificates in the first XML signature. The returned certificates have not been checked for trust.

func VerifySignature added in v1.1.0

func VerifySignature(data []byte, options SignatureOptions) (*x509.Certificate, error)

VerifySignature verifies the first enveloped XML signature and its signer certificate. When Roots is nil, the system certificate pool is used.

Types

type Alert

type Alert struct {
	XMLName xml.Name `xml:"urn:oasis:names:tc:emergency:cap:1.2 alert" json:"-"` // CAP XML root.

	Identifier  string   `xml:"identifier" json:"identifier"`                       // Unique message ID. Required.
	Sender      string   `xml:"sender" json:"sender"`                               // Sender ID. Required.
	Sent        DateTime `xml:"sent" json:"sent"`                                   // Time the message was sent. Required.
	Status      Status   `xml:"status" json:"status"`                               // Message status. Required.
	MsgType     MsgType  `xml:"msgType" json:"msgType"`                             // Message type. Required.
	Source      string   `xml:"source,omitempty" json:"source,omitempty"`           // Message source.
	Scope       Scope    `xml:"scope" json:"scope"`                                 // Distribution scope. Required.
	Restriction string   `xml:"restriction,omitempty" json:"restriction,omitempty"` // Rule for restricted distribution.
	Addresses   string   `xml:"addresses,omitempty" json:"addresses,omitempty"`     // Intended recipient identifiers or addresses.
	Code        []string `xml:"code,omitempty" json:"code,omitempty"`               // Special handling codes.
	Note        string   `xml:"note,omitempty" json:"note,omitempty"`               // Message note.
	References  *List    `xml:"references,omitempty" json:"references,omitempty"`   // Earlier messages referenced by this message.
	Incidents   string   `xml:"incidents,omitempty" json:"incidents,omitempty"`     // Related incident IDs.

	Info       []Info      `xml:"info,omitempty" json:"info,omitempty"`           // Event details.
	Signature  []Signature `xml:"Signature,omitempty" json:"signature,omitempty"` // XML signatures.
	Extensions []Extension `xml:",any" json:"extensions,omitempty"`               // Additional XML Signature elements.
}

Alert is a CAP message with routing details and optional event information.

func ParseCAP

func ParseCAP(data []byte) (*Alert, error)

ParseCAP decodes an XML CAP 1.2 message. It checks XML syntax, namespaces, dates, and code values. Use Validate or ValidateCAPCP for message rules.

func (*Alert) Validate added in v1.1.0

func (a *Alert) Validate() Diagnostics

Validate checks the CAP 1.2 rules supported by this package.

func (*Alert) ValidateCAPCP added in v1.1.0

func (a *Alert) ValidateCAPCP() Diagnostics

ValidateCAPCP checks CAP-CP 1.0 rules that can be determined from one message. It does not verify external event and location lists or the completeness of active message references. It also checks CAP 1.2.

type Algorithm

type Algorithm struct {
	Algorithm string `xml:"Algorithm,attr" json:"algorithm"` // Algorithm URI.
}

Algorithm names an XML signature algorithm.

type Area

type Area struct {
	XMLName xml.Name `xml:"area" json:"-"` // CAP area element.

	AreaDesc string     `xml:"areaDesc" json:"areaDesc"`                     // Area description. Required.
	Polygon  []List     `xml:"polygon,omitempty" json:"polygon,omitempty"`   // Affected polygons.
	Circle   []string   `xml:"circle,omitempty" json:"circle,omitempty"`     // Affected circles.
	Geocode  []KeyValue `xml:"geocode,omitempty" json:"geocode,omitempty"`   // Area codes.
	Altitude *float64   `xml:"altitude,omitempty" json:"altitude,omitempty"` // Altitude or lower bound in feet above mean sea level.
	Ceiling  *float64   `xml:"ceiling,omitempty" json:"ceiling,omitempty"`   // Upper bound in feet above mean sea level.
}

Area describes a place affected by an event.

func (Area) Circles added in v1.1.0

func (a Area) Circles() ([]CircleGeometry, error)

Circles returns the parsed circles in the area.

func (Area) Polygons added in v1.1.0

func (a Area) Polygons() ([][]Coordinate, error)

Polygons returns the parsed polygon coordinates in the area.

type Category

type Category int

Category identifies the category of an alert's subject event.

const (
	// CategoryGeo covers geophysical events such as landslides.
	CategoryGeo Category = iota + 1
	// CategoryMet covers weather events, including floods.
	CategoryMet
	// CategorySafety covers general emergencies and public safety.
	CategorySafety
	// CategorySecurity covers law enforcement, military, and security events.
	CategorySecurity
	// CategoryRescue covers rescue and recovery.
	CategoryRescue
	// CategoryFire covers fire suppression and rescue.
	CategoryFire
	// CategoryHealth covers medical and public health events.
	CategoryHealth
	// CategoryEnv covers pollution and other environmental events.
	CategoryEnv
	// CategoryTransport covers public and private transportation.
	CategoryTransport
	// CategoryInfra covers utilities and other infrastructure.
	CategoryInfra
	// CategoryCBRNE covers chemical, biological, radiological, nuclear, and
	// explosive threats.
	CategoryCBRNE
	// CategoryOther covers events outside the other categories.
	CategoryOther
)

func (Category) MarshalJSON

func (t Category) MarshalJSON() ([]byte, error)

MarshalJSON encodes a CAP category value.

func (Category) MarshalXML

func (t Category) MarshalXML(encoder *xml.Encoder, elem xml.StartElement) error

MarshalXML encodes a CAP category value.

func (Category) String

func (t Category) String() string

String returns the CAP category value.

func (*Category) UnmarshalJSON

func (t *Category) UnmarshalJSON(buff []byte) error

UnmarshalJSON decodes a CAP category value.

func (*Category) UnmarshalXML

func (t *Category) UnmarshalXML(decoder *xml.Decoder, elem xml.StartElement) error

UnmarshalXML decodes a CAP category value.

type Certainty

type Certainty int

Certainty identifies the certainty of an alert's subject event.

const (
	// CertaintyObserved means the event has occurred or is underway.
	CertaintyObserved Certainty = iota + 1
	// CertaintyLikely means the event is more likely than not. The parser also
	// accepts the deprecated CAP 1.0 value "Very Likely" as this value.
	CertaintyLikely
	// CertaintyPossible means the event is possible but not likely.
	CertaintyPossible
	// CertaintyUnlikely means the event is not expected.
	CertaintyUnlikely
	// CertaintyUnknown means the certainty is unknown.
	CertaintyUnknown
)

func (Certainty) MarshalJSON

func (t Certainty) MarshalJSON() ([]byte, error)

MarshalJSON encodes a CAP certainty value.

func (Certainty) MarshalXML

func (t Certainty) MarshalXML(encoder *xml.Encoder, elem xml.StartElement) error

MarshalXML encodes a CAP certainty value.

func (Certainty) String

func (t Certainty) String() string

String returns the CAP certainty value.

func (*Certainty) UnmarshalJSON

func (t *Certainty) UnmarshalJSON(buff []byte) error

UnmarshalJSON decodes a CAP certainty value.

func (*Certainty) UnmarshalXML

func (t *Certainty) UnmarshalXML(decoder *xml.Decoder, elem xml.StartElement) error

UnmarshalXML decodes a CAP certainty value.

type CircleGeometry added in v1.1.0

type CircleGeometry struct {
	Center   Coordinate // Center point.
	RadiusKM float64    // Radius in kilometers.
}

CircleGeometry is a CAP circle center and radius in kilometers.

func ParseCircle added in v1.1.0

func ParseCircle(value string) (CircleGeometry, error)

ParseCircle parses a CAP circle value.

func (CircleGeometry) String added in v1.1.0

func (c CircleGeometry) String() string

String returns a CAP circle value.

type Coordinate added in v1.1.0

type Coordinate struct {
	Latitude  float64 // Degrees north or south.
	Longitude float64 // Degrees east or west.
}

Coordinate is a WGS 84 latitude and longitude pair.

func ParseCoordinate added in v1.1.0

func ParseCoordinate(value string) (Coordinate, error)

ParseCoordinate parses a CAP latitude,longitude pair.

func (Coordinate) String added in v1.1.0

func (c Coordinate) String() string

String returns a CAP latitude,longitude pair.

type DateTime

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

DateTime represents a CAP date-time with a numeric UTC offset.

func NewDateTime added in v1.1.0

func NewDateTime(value time.Time) (DateTime, error)

NewDateTime returns a CAP date-time for value. It rejects values that CAP cannot represent.

func ParseDateTime added in v1.1.0

func ParseDateTime(value string) (DateTime, error)

ParseDateTime parses a CAP date-time value, including its numeric offset.

func (DateTime) IsZero added in v1.1.0

func (t DateTime) IsZero() bool

IsZero reports whether no time has been assigned.

func (DateTime) MarshalJSON

func (t DateTime) MarshalJSON() ([]byte, error)

MarshalJSON encodes a CAP date and time value.

func (DateTime) MarshalXML

func (t DateTime) MarshalXML(encoder *xml.Encoder, elem xml.StartElement) error

MarshalXML encodes a CAP date and time value.

func (DateTime) String

func (t DateTime) String() string

String returns the CAP date and time value.

func (DateTime) Time

func (t DateTime) Time() time.Time

Time returns the value as a time.Time.

func (*DateTime) UnmarshalJSON

func (t *DateTime) UnmarshalJSON(buff []byte) error

UnmarshalJSON decodes a CAP date and time value.

func (*DateTime) UnmarshalXML

func (t *DateTime) UnmarshalXML(decoder *xml.Decoder, elem xml.StartElement) error

UnmarshalXML decodes a CAP date and time value.

type Diagnostic added in v1.1.0

type Diagnostic struct {
	Level   DiagnosticLevel `json:"level"`          // Error or warning.
	Path    string          `json:"path"`           // Related field path.
	Rule    string          `json:"rule,omitempty"` // CAP rule or recommendation.
	Message string          `json:"message"`        // Description of the result.
}

Diagnostic describes one validation result.

func (Diagnostic) Error added in v1.1.0

func (d Diagnostic) Error() string

Error returns the diagnostic message and its field path.

type DiagnosticLevel added in v1.1.0

type DiagnosticLevel string

DiagnosticLevel says whether a result is an error or warning.

const (
	// DiagnosticError marks a failed rule.
	DiagnosticError DiagnosticLevel = "error"
	// DiagnosticWarning marks a recommendation.
	DiagnosticWarning DiagnosticLevel = "warning"
)

type Diagnostics added in v1.1.0

type Diagnostics []Diagnostic

Diagnostics holds validation errors and warnings.

func (Diagnostics) Err added in v1.1.0

func (d Diagnostics) Err() error

Err returns the validation errors, or nil if there are none.

func (Diagnostics) HasErrors added in v1.1.0

func (d Diagnostics) HasErrors() bool

HasErrors reports whether any result is an error.

type Extension added in v1.1.0

type Extension struct {
	XMLName  xml.Name   `json:"name"`                                 // Element name.
	Attr     []xml.Attr `xml:",any,attr" json:"attributes,omitempty"` // Element attributes.
	InnerXML string     `xml:",innerxml" json:"innerXML,omitempty"`   // Raw child content.
}

Extension preserves an additional XML Signature element at the alert root.

type Info

type Info struct {
	XMLName xml.Name `xml:"info" json:"-"` // CAP info element.

	Language     string         `xml:"language,omitempty" json:"language,omitempty"`         // Content language.
	Category     []Category     `xml:"category" json:"category"`                             // Event categories. At least one is required.
	Event        string         `xml:"event" json:"event"`                                   // Event name. Required.
	ResponseType []ResponseType `xml:"responseType,omitempty" json:"responseType,omitempty"` // Recommended actions.
	Urgency      Urgency        `xml:"urgency" json:"urgency"`                               // Event urgency. Required.
	Severity     Severity       `xml:"severity" json:"severity"`                             // Event severity. Required.
	Certainty    Certainty      `xml:"certainty" json:"certainty"`                           // Event certainty. Required.
	Audience     string         `xml:"audience,omitempty" json:"audience,omitempty"`         // Intended audience.
	EventCode    []KeyValue     `xml:"eventCode,omitempty" json:"eventCode,omitempty"`       // Event codes.
	Effective    *DateTime      `xml:"effective,omitempty" json:"effective,omitempty"`       // Time the information takes effect.
	Onset        *DateTime      `xml:"onset,omitempty" json:"onset,omitempty"`               // Expected start time.
	Expires      *DateTime      `xml:"expires,omitempty" json:"expires,omitempty"`           // Expiration time.
	SenderName   string         `xml:"senderName,omitempty" json:"senderName,omitempty"`     // Sender's display name.
	Headline     string         `xml:"headline,omitempty" json:"headline,omitempty"`         // Short headline.
	Description  string         `xml:"description,omitempty" json:"description,omitempty"`   // Event description.
	Instruction  string         `xml:"instruction,omitempty" json:"instruction,omitempty"`   // Instructions for recipients.
	Web          string         `xml:"web,omitempty" json:"web,omitempty"`                   // Link to more information.
	Contact      string         `xml:"contact,omitempty" json:"contact,omitempty"`           // Follow-up contact.
	Parameter    []KeyValue     `xml:"parameter,omitempty" json:"parameter,omitempty"`       // Extra system values.

	Resource []Resource `xml:"resource,omitempty" json:"resource,omitempty"` // Related files.
	Area     []Area     `xml:"area,omitempty" json:"area,omitempty"`         // Affected areas.
}

Info describes an event and the action recipients should take. An alert may have several Info values for different areas or languages.

func (Info) EffectiveTime added in v1.1.0

func (i Info) EffectiveTime(sent DateTime) DateTime

EffectiveTime returns Effective, or the alert sent time when Effective is omitted.

func (Info) LanguageCode added in v1.1.0

func (i Info) LanguageCode() string

LanguageCode returns Language, or the CAP default of en-US.

type KeyValue

type KeyValue struct {
	ValueName string `xml:"valueName" json:"valueName"` // Name of the code or value domain.
	Value     string `xml:"value" json:"value"`         // Value within that domain.
}

KeyValue holds a named CAP value.

type List

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

List represents whitespace-delimited CAP values.

func NewList added in v1.1.0

func NewList(values ...string) List

NewList returns a list containing a copy of values.

func (List) Coordinates added in v1.1.0

func (t List) Coordinates() ([]Coordinate, error)

Coordinates parses the list as a sequence of coordinates.

func (List) MarshalJSON

func (t List) MarshalJSON() ([]byte, error)

MarshalJSON encodes a whitespace-delimited CAP list.

func (List) MarshalXML

func (t List) MarshalXML(encoder *xml.Encoder, elem xml.StartElement) error

MarshalXML encodes a whitespace-delimited CAP list.

func (List) String

func (t List) String() string

String returns the values joined with spaces.

func (*List) UnmarshalJSON

func (t *List) UnmarshalJSON(buff []byte) error

UnmarshalJSON decodes a whitespace-delimited CAP list.

func (*List) UnmarshalXML

func (t *List) UnmarshalXML(decoder *xml.Decoder, elem xml.StartElement) error

UnmarshalXML decodes a whitespace-delimited CAP list.

func (List) Values

func (t List) Values() []string

Values returns the values in the list.

type MsgType

type MsgType int

MsgType identifies the nature of an alert message.

const (
	// MsgTypeAlert provides new information that needs attention.
	MsgTypeAlert MsgType = iota + 1
	// MsgTypeUpdate replaces the messages listed in References.
	MsgTypeUpdate
	// MsgTypeCancel cancels the messages listed in References.
	MsgTypeCancel
	// MsgTypeAck accepts the messages listed in References.
	MsgTypeAck
	// MsgTypeError rejects the messages listed in References.
	MsgTypeError
)

func (MsgType) MarshalJSON

func (t MsgType) MarshalJSON() ([]byte, error)

MarshalJSON encodes a CAP message type value.

func (MsgType) MarshalXML

func (t MsgType) MarshalXML(encoder *xml.Encoder, elem xml.StartElement) error

MarshalXML encodes a CAP message type value.

func (MsgType) String

func (t MsgType) String() string

String returns the CAP message type value.

func (*MsgType) UnmarshalJSON

func (t *MsgType) UnmarshalJSON(buff []byte) error

UnmarshalJSON decodes a CAP message type value.

func (*MsgType) UnmarshalXML

func (t *MsgType) UnmarshalXML(decoder *xml.Decoder, elem xml.StartElement) error

UnmarshalXML decodes a CAP message type value.

type Reference

type Reference struct {
	URI          string      `xml:"URI,attr" json:"uri"`                   // Referenced content.
	Transform    []Algorithm `xml:"Transforms>Transform" json:"transform"` // Applied transforms.
	DigestMethod Algorithm   `xml:"DigestMethod" json:"digestMethod"`      // Digest algorithm.
	DigestValue  string      `xml:"DigestValue" json:"digestValue"`        // Encoded digest.
}

Reference describes signed data and any transforms applied to it.

type Resource

type Resource struct {
	XMLName xml.Name `xml:"resource" json:"-"` // CAP resource element.

	ResourceDesc string `xml:"resourceDesc" json:"resourceDesc"`             // File description. Required.
	MimeType     string `xml:"mimeType" json:"mimeType"`                     // MIME type. Required.
	Size         *int64 `xml:"size,omitempty" json:"size,omitempty"`         // File size in bytes.
	URI          string `xml:"uri,omitempty" json:"uri,omitempty"`           // File location.
	DerefURI     string `xml:"derefUri,omitempty" json:"derefUri,omitempty"` // Base64 encoded file data.
	Digest       string `xml:"digest,omitempty" json:"digest,omitempty"`     // SHA-1 file digest.
}

Resource describes a file related to an Info value.

type ResponseType

type ResponseType int

ResponseType identifies an action recommended for the target audience.

const (
	// ResponseTypeShelter tells recipients to take shelter.
	ResponseTypeShelter ResponseType = iota + 1
	// ResponseTypeEvacuate tells recipients to relocate.
	ResponseTypeEvacuate
	// ResponseTypePrepare tells recipients to prepare.
	ResponseTypePrepare
	// ResponseTypeExecute tells recipients to carry out a planned action.
	ResponseTypeExecute
	// ResponseTypeAvoid tells recipients to avoid the event.
	ResponseTypeAvoid
	// ResponseTypeMonitor tells recipients to monitor information sources.
	ResponseTypeMonitor
	// ResponseTypeAssess tells recipients to assess the information.
	ResponseTypeAssess
	// ResponseTypeAllClear means the event no longer poses a threat.
	ResponseTypeAllClear
	// ResponseTypeNone means no action is recommended.
	ResponseTypeNone
)

func (ResponseType) MarshalJSON

func (t ResponseType) MarshalJSON() ([]byte, error)

MarshalJSON encodes a CAP response value.

func (ResponseType) MarshalXML

func (t ResponseType) MarshalXML(encoder *xml.Encoder, elem xml.StartElement) error

MarshalXML encodes a CAP response value.

func (ResponseType) String

func (t ResponseType) String() string

String returns the CAP response value.

func (*ResponseType) UnmarshalJSON

func (t *ResponseType) UnmarshalJSON(buff []byte) error

UnmarshalJSON decodes a CAP response value.

func (*ResponseType) UnmarshalXML

func (t *ResponseType) UnmarshalXML(decoder *xml.Decoder, elem xml.StartElement) error

UnmarshalXML decodes a CAP response value.

type Scope

type Scope int

Scope identifies the intended distribution of an alert message.

const (
	// ScopePublic allows general distribution.
	ScopePublic Scope = iota + 1
	// ScopeRestricted limits distribution using Restriction.
	ScopeRestricted
	// ScopePrivate limits distribution to Addresses.
	ScopePrivate
)

func (Scope) MarshalJSON

func (t Scope) MarshalJSON() ([]byte, error)

MarshalJSON encodes a CAP scope value.

func (Scope) MarshalXML

func (t Scope) MarshalXML(encoder *xml.Encoder, elem xml.StartElement) error

MarshalXML encodes a CAP scope value.

func (Scope) String

func (t Scope) String() string

String returns the CAP scope value.

func (*Scope) UnmarshalJSON

func (t *Scope) UnmarshalJSON(buff []byte) error

UnmarshalJSON decodes a CAP scope value.

func (*Scope) UnmarshalXML

func (t *Scope) UnmarshalXML(decoder *xml.Decoder, elem xml.StartElement) error

UnmarshalXML decodes a CAP scope value.

type Severity

type Severity int

Severity identifies the severity of an alert's subject event.

const (
	// SeverityExtreme means an extraordinary threat to life or property.
	SeverityExtreme Severity = iota + 1
	// SeveritySevere means a significant threat to life or property.
	SeveritySevere
	// SeverityModerate means a possible threat to life or property.
	SeverityModerate
	// SeverityMinor means little or no known threat to life or property.
	SeverityMinor
	// SeverityUnknown means the severity is unknown.
	SeverityUnknown
)

func (Severity) MarshalJSON

func (t Severity) MarshalJSON() ([]byte, error)

MarshalJSON encodes a CAP severity value.

func (Severity) MarshalXML

func (t Severity) MarshalXML(encoder *xml.Encoder, elem xml.StartElement) error

MarshalXML encodes a CAP severity value.

func (Severity) String

func (t Severity) String() string

String returns the CAP severity value.

func (*Severity) UnmarshalJSON

func (t *Severity) UnmarshalJSON(buff []byte) error

UnmarshalJSON decodes a CAP severity value.

func (*Severity) UnmarshalXML

func (t *Severity) UnmarshalXML(decoder *xml.Decoder, elem xml.StartElement) error

UnmarshalXML decodes a CAP severity value.

type Signature

type Signature struct {
	XMLName xml.Name `xml:"http://www.w3.org/2000/09/xmldsig# Signature" json:"-"` // XML Signature element.

	ID                  string              `xml:"Id,attr" json:"id"`                                                     // Signature ID.
	SignedInfo          SignedInfo          `xml:"SignedInfo" json:"signedInfo"`                                          // Signed algorithms and references.
	SignatureValue      string              `xml:"SignatureValue" json:"signatureValue"`                                  // Encoded signature value.
	X509Certificate     []string            `xml:"KeyInfo>X509Data>X509Certificate" json:"x509Certificate"`               // Encoded certificates.
	SignatureProperties []SignatureProperty `xml:"Object>SignatureProperties>SignatureProperty" json:"signatureProperty"` // Signed properties.
}

Signature holds commonly used fields from an enveloped XML signature.

type SignatureOptions added in v1.1.0

type SignatureOptions struct {
	// Roots contains trusted certificate authorities. Nil uses system roots.
	Roots *x509.CertPool
	// CurrentTime is the certificate verification time. Zero uses time.Now.
	CurrentTime time.Time
	// KeyUsages limits accepted certificate uses. Empty accepts any use.
	KeyUsages []x509.ExtKeyUsage
	// CertificateCheck runs after the certificate chain is checked.
	CertificateCheck func(*x509.Certificate, [][]*x509.Certificate) error
}

SignatureOptions sets the certificate checks used by VerifySignature.

type SignatureProperty

type SignatureProperty struct {
	ID      string  `xml:"Id,attr" json:"id"`         // Property ID.
	Target  string  `xml:"Target,attr" json:"target"` // Property target.
	XCValue XCValue `xml:"value" json:"value"`        // NAADS xc value.
}

SignatureProperty holds a property covered by a signature.

type SignedInfo

type SignedInfo struct {
	CanonicalizationMethod Algorithm   `xml:"CanonicalizationMethod" json:"canonicalizationMethod"` // Canonical XML algorithm.
	SignatureMethod        Algorithm   `xml:"SignatureMethod" json:"signatureMethod"`               // Signature algorithm.
	Reference              []Reference `xml:"Reference" json:"reference"`                           // Signed content references.
}

SignedInfo references signed data and specifies the algorithms used.

type Status

type Status int

Status describes how recipients should handle an alert.

const (
	// StatusActual is actionable by all targeted recipients.
	StatusActual Status = iota + 1
	// StatusExercise is actionable only by exercise participants.
	StatusExercise
	// StatusSystem is for alert system functions.
	StatusSystem
	// StatusTest is for technical testing.
	StatusTest
	// StatusDraft is a draft and is not actionable.
	StatusDraft
)

func (Status) MarshalJSON

func (t Status) MarshalJSON() ([]byte, error)

MarshalJSON encodes a CAP status value.

func (Status) MarshalXML

func (t Status) MarshalXML(encoder *xml.Encoder, elem xml.StartElement) error

MarshalXML encodes a CAP status value.

func (Status) String

func (t Status) String() string

String returns the CAP status value.

func (*Status) UnmarshalJSON

func (t *Status) UnmarshalJSON(buff []byte) error

UnmarshalJSON decodes a CAP status value.

func (*Status) UnmarshalXML

func (t *Status) UnmarshalXML(decoder *xml.Decoder, elem xml.StartElement) error

UnmarshalXML decodes a CAP status value.

type Urgency

type Urgency int

Urgency identifies the urgency of an alert's subject event.

const (
	// UrgencyImmediate calls for immediate action.
	UrgencyImmediate Urgency = iota + 1
	// UrgencyExpected calls for action within the next hour.
	UrgencyExpected
	// UrgencyFuture calls for action later than the next hour.
	UrgencyFuture
	// UrgencyPast means action is no longer needed.
	UrgencyPast
	// UrgencyUnknown means the urgency is unknown.
	UrgencyUnknown
)

func (Urgency) MarshalJSON

func (t Urgency) MarshalJSON() ([]byte, error)

MarshalJSON encodes a CAP urgency value.

func (Urgency) MarshalXML

func (t Urgency) MarshalXML(encoder *xml.Encoder, elem xml.StartElement) error

MarshalXML encodes a CAP urgency value.

func (Urgency) String

func (t Urgency) String() string

String returns the CAP urgency value.

func (*Urgency) UnmarshalJSON

func (t *Urgency) UnmarshalJSON(buff []byte) error

UnmarshalJSON decodes a CAP urgency value.

func (*Urgency) UnmarshalXML

func (t *Urgency) UnmarshalXML(decoder *xml.Decoder, elem xml.StartElement) error

UnmarshalXML decodes a CAP urgency value.

type ValidationError added in v1.1.0

type ValidationError struct {
	Diagnostics Diagnostics // Failed validation rules.
}

ValidationError contains validation errors.

func (ValidationError) Error added in v1.1.0

func (e ValidationError) Error() string

Error returns the first error and the number of additional errors.

type XCValue

type XCValue struct {
	XC string `xml:"xc,attr" json:"xc"` // Namespace declared for xc.
}

XCValue holds the xc namespace used by NAADS signatures.

Jump to

Keyboard shortcuts

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