Documentation
¶
Overview ¶
Package buttons holds the Command buttons of messages (C-12.FR-1, reference.md "Buttons and links by status") and their signed action ids (ADR-0011). An action id is opaque: a version, the kind of its subject, the subject's public_id, the Command and its argument, the first bytes of the id of the key that signed it, and an HMAC-SHA256 with the button-signature sub-key of that key truncated to 128 bits — at most 64 bytes in its compact base64url form, so that Telegram's callback_data holds it. Verification finds the key in the Keyring by its id, which may be any key of the Keyring, and compares the HMAC in constant time. An action id whose key prefix names no key of the Keyring is expired (C-17.FR-6): its key left the Keyring, which a Reminder button, never re-rendered, outlives.
Index ¶
- Constants
- Variables
- func IsPreset(argument int) bool
- func LooksSigned(s string) bool
- func Sign(k Keys, a Action) (id, keyID string, err error)
- func Validate(in []ItemInput) ([]Item, *ItemError)
- type Action
- type Button
- type Item
- type ItemError
- type ItemInput
- type Keys
- type Own
- type Set
- type Style
- type Subject
Constants ¶
const ( CommandAcknowledge = "acknowledge" CommandUnacknowledge = "unacknowledge" CommandResolve = "resolve" CommandSnooze = "snooze" CommandUnsnooze = "unsnooze" CommandStillOnIt = "still_on_it" )
The Commands a button carries.
const ( ArgumentTomorrow = 254 ArgumentWeekStart = 255 )
The arguments of the Snooze buttons of the two Snooze presets (C-10.FR-18), "Until tomorrow {start}" and "Until {day} {start}", in the order of groups.PresetOrder; the arguments below them are the indices of Snooze durations.
const ( ItemAcknowledge = "acknowledge" ItemResolve = "resolve" ItemSnooze = "snooze" ItemSnoozePreset = "snooze_preset" )
The buttons an item of a button set names (ButtonSetItem): Acknowledge, which brings Unacknowledge with it, Resolve, one Snooze duration by its value in seconds, and one Snooze preset.
const ( PresetTomorrow = "tomorrow" PresetWeekStart = "week_start" )
The Snooze presets an item names (SnoozePreset), in the order of the arguments ArgumentTomorrow and ArgumentWeekStart.
const ( CodeDuplicate = "duplicate" CodeRequired = "required" CodeOutOfRange = "out_of_range" CodeInvalidFormat = "invalid_format" )
The codes of an ItemError, from the catalogue of the API (x-problem-codes).
const MaxLen = 64
MaxLen is the longest action id in its compact form: Telegram's callback_data takes 64 bytes.
const MaxSnoozeDurations = ArgumentTomorrow
MaxSnoozeDurations is the most Snooze durations a Root message offers as buttons: the indices below the arguments of the Snooze presets.
Variables ¶
var ErrExpired = errors.New("the action id names a key that is not in the keyring")
ErrExpired is a well-formed action id whose key prefix names no key of the Keyring (C-17.FR-6): it cannot be told from one signed with a key that left the Keyring. Verify returns the Action it reads alongside it, unverified: its Subject and PublicID may only choose an answer and the lookup of what the press is bound to, never run a Command.
var ErrInvalid = errors.New("the action id is not valid")
ErrInvalid is an action id that is malformed or whose signature does not match.
Functions ¶
func IsPreset ¶
IsPreset reports whether the argument of a Snooze button names a Snooze preset rather than the index of a duration.
func LooksSigned ¶
LooksSigned reports whether s has the structure of an action id — its length in the compact form, the version, a known subject and Command, and a public_id of the right alphabet — without its signature, which needs the key: the Request log masks every such string, a forged one too (C-23.FR-3).
func Sign ¶
Sign is the action id of a, signed with the active key, and the full id of that key, which Mattermost receives as context.key_id and deliveries.desired_button_key_id records.
func Validate ¶
Validate reads the items of a request in their order and returns them as a set stores them, each with only the fields its button takes, or the first item that is not valid: a snooze without snooze_seconds (required) or with one below 1 (out_of_range), a snooze_preset without its preset (required), an unknown button or preset (invalid_format), or the same button, duration or preset a second time (duplicate). An item of a duration that no Route has is valid: it is simply never shown.
Types ¶
type Action ¶
Action is what an action id says.
func Verify ¶
Verify reads an action id and checks its signature with the key of the Keyring its prefix names; keyID, when given, is the full key id Mattermost returns, which must agree with the prefix. A prefix that names no key of the Keyring is ErrExpired, with the unverified Action; anything else is ErrInvalid.
type Button ¶
Button is a button before it is signed: its Command and the argument of a Snooze button, the index of a Snooze duration or the argument of a Snooze preset.
func ForStatus ¶
ForStatus are the buttons of a Root message in a status (reference.md): firing — Ack, Resolve, Snooze; acknowledged — Unack, Resolve, Snooze; snoozed — Ack, Unsnooze, Resolve; resolved — none. Snooze is one button per duration of route.snooze_durations, at most MaxSnoozeDurations, then one per Snooze preset when there is at least one duration.
type Item ¶
type Item struct {
Button string `json:"button"`
SnoozeSeconds int64 `json:"snooze_seconds,omitempty"`
Preset string `json:"preset,omitempty"`
}
Item is one entry of a button set: a button, the value of a Snooze duration in seconds, or a Snooze preset.
type ItemError ¶
ItemError is an item of a set that is not valid: its index, -1 for the list itself, its code and what is wrong.
type ItemInput ¶
ItemInput is an item of a set as a request writes it: snooze_seconds and preset may be missing.
type Keys ¶
type Keys interface {
Sign(p keyring.Purpose, msg []byte) (mac []byte, keyID string, err error)
VerifyPrefix(p keyring.Purpose, keyID string, msg, prefix []byte) (bool, error)
KeyIDs() []string
}
Keys are the keys that sign and verify action ids: the Keyring.
type Own ¶
Own is the button set of a Destination (destination.buttons): its own items when Set, otherwise "As in the Organization", which follows the Organization's set.
func ParseOwn ¶
ParseOwn reads a Destination's set as destinations.buttons stores it: an array of items, or null for "As in the Organization".
type Set ¶
Set is a button set (C-28.FR-8): every button, durations a Route gains later included, or the buttons its items list. The zero Set lists none; All is the default of the Organization (organization.buttons).
func ParseSet ¶
ParseSet reads the Organization's set as organizations.buttons stores it; an empty value is every button, the default of a row that a replica of 0.1 read before the column existed.
func (Set) Filter ¶
Filter are the buttons of bs that the set shows on a Route with the Snooze durations given, in their order, so that the order of ForStatus — reference.md's — stays.
func (Set) Shows ¶
Shows reports whether a Root message with the set shows the button b of a Route with the Snooze durations given, in seconds: Acknowledge and Unacknowledge by the item acknowledge, Resolve by resolve, a Snooze duration when its value is an item, a Snooze preset when its preset is; Unsnooze and the buttons of Reminders always, whatever the set. A Snooze button of a duration the Route does not have is not shown.
type Style ¶
type Style string
Style is the style hint of a button, named as the ButtonStyle of the Bridge protocol; each adapter maps it to the closest style of its messenger, neutral being a plain button.