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 ¶
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 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).
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 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 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.