Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEventNotSigned = errors.New("the event is not signed")
ErrEventNotSigned is returned when the event is not signed
var ErrEventSystemNotConfigured = errors.New("the event system hasn't been configured, please call Configure()")
ErrEventSystemNotConfigured is returned when the event system is used but wasn't configured by calling Configure()
var ErrInvalidTimestamp = errors.New("event timestamp does not match required pattern (yyyyMMddHHmmssmmm)")
ErrInvalidTimestamp is returned when a timestamp does not match the required pattern
var ErrMissingEventType = errors.New("unmarshalling error: missing event type")
ErrMissingEventType is given when the event being unmarshalled has no type attribute.
var NoopJwsVerifier = func(signature []byte, signingTime time.Time, verifier crypto.CertificateVerifier) ([]byte, error) { msg, err := jws.Parse(bytes.NewReader(signature)) if err != nil { return nil, err } return msg.Payload(), nil }
NoopJwsVerifier is a JwsVerifier that just parses the JWS without verifying the signatures
var NoopTrustStore = &noopTrustStore{}
NoopTrustStore is a TrustStore that holds no state
Functions ¶
func SuggestEventFileName ¶
SuggestEventFileName suggests a file name for a event, when writing that event to disk.
Types ¶
type Event ¶
type Event interface { Type() EventType IssuedAt() time.Time Unmarshal(out interface{}) error Marshal() []byte Signature() []byte Sign(signFn func([]byte) ([]byte, error)) error }
Event defines an event which can be (un)marshalled.
func CreateEvent ¶
CreateEvent creates an event of the given type and the provided payload. If the event can't be created, an error is returned.
func EventFromJSON ¶
EventFromJSON unmarshals an event. If the event can't be unmarshalled, an error is returned.
type EventHandler ¶
EventHandler handles an event of a specific type.
type EventRegistrar ¶
type EventRegistrar func(EventType, EventHandler)
EventRegistrar is a function to register an event
type EventSystem ¶
type EventSystem interface { // RegisterEventHandler registers an event handler for the given type, which will be called when the an event of this // type is received. RegisterEventHandler(eventType EventType, handler EventHandler) ProcessEvent(event Event) error PublishEvent(event Event) error LoadAndApplyEvents() error Configure(location string) error }
EventSystem is meant for registering and handling events.
func NewEventSystem ¶
func NewEventSystem(eventTypes ...EventType) EventSystem
NewEventSystem creates and initializes a new event system.
type EventType ¶
type EventType string
EventType defines a supported type of event, which is used for executing the right handler.
type JwsVerifier ¶
type JwsVerifier func(signature []byte, signingTime time.Time, verifier crypto.CertificateVerifier) ([]byte, error)
JwsVerifier defines a verification delegate for JWS'.
type SignatureDetails ¶
type SignatureDetails struct { // Certificate contains the X.509 certificate that signed the event Certificate *x509.Certificate // Payload contains the event data that is protected by the signature Payload []byte }
SignatureDetails describes the properties of the signature that secures the event
type SignatureValidator ¶
type SignatureValidator struct {
// contains filtered or unexported fields
}
SignatureValidator validates event signatures.
func NewSignatureValidator ¶
func NewSignatureValidator(verifier JwsVerifier, trustStore TrustStore) SignatureValidator
NewSignatureValidator creates a new SignatureValidator for the given event types.
func (SignatureValidator) RegisterEventHandlers ¶
func (v SignatureValidator) RegisterEventHandlers(fn EventRegistrar, eventType []EventType)
RegisterEventHandlers registers event handlers which will validate the event signatures.
type TrustStore ¶
type TrustStore interface { crypto.CertificateVerifier RegisterEventHandlers(func(EventType, EventHandler)) }
type UnmarshalPostProcessor ¶
UnmarshalPostProcessor allows to define custom logic that should be executed after unmarshalling