sharelink

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sharelink runs one-shot secret exchanges with people who have no account: a drop box they fill in (values land straight in the encrypted variables store) or a share link that shows them existing values once.

Two rules hold the whole design together. Every state change happens on a POST, so link previewers and browser prefetch can't burn a link by looking at it. And every burn is a claim, an UPDATE guarded on the current state, so two concurrent submits can never both go through.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDead covers every reason a link won't open, wrong token, expired,
	// burned, revoked, locked. The public pages must not tell a stranger which.
	ErrDead = errors.New("link is no longer available")
	// ErrPass is returned when the passphrase is missing or wrong; after
	// repo.MaxLinkAttempts the link locks and ErrDead takes over.
	ErrPass = errors.New("wrong passphrase")
)

Functions

func EncodeFields

func EncodeFields(fields []repo.SecretLinkField) (string, error)

EncodeFields is the writer side of SecretLink.Fields.

func HashToken

func HashToken(raw string) string

HashToken is the one-way mapping from the token in the URL to what we store. Same shape as API keys: the plaintext exists only in the link we hand out.

func Mint

func Mint(ctx context.Context, store repo.Store, l *repo.SecretLink, pass string) (string, error)

Mint stores a link and returns the token for its URL. The token is returned exactly once, only its hash is persisted, so a lost link can't be recovered.

func Open

func Open(ctx context.Context, store repo.Store, token string) (*repo.SecretLink, error)

Open resolves a token to a live link. It is safe on GET: no state changes here, and a passphrase-protected link reports ErrPass without touching the row, so a prefetch can't spend an attempt.

func Reveal

func Reveal(ctx context.Context, store repo.Store, l *repo.SecretLink) ([]repo.Variable, error)

Reveal burns a share link and reads the values it points at. Values are read live, never copied at mint, so revoking a link leaves nothing to clean up. With a grace window the link stays readable until the window closes rather than dying on the first read.

func Revoke

func Revoke(ctx context.Context, store repo.Store, id string) error

Revoke kills a link whatever state it is in.

func Submit

func Submit(ctx context.Context, store repo.Store, l *repo.SecretLink, values map[string]string) error

Submit burns a drop box and writes what was collected, atomically: the claimed burn and the variable writes are one transaction, so a losing double-submit writes nothing and a failed write un-burns the link.

func Unlock

func Unlock(ctx context.Context, store repo.Store, l *repo.SecretLink, pass string) error

Unlock checks the passphrase on a link Open already returned, counting wrong answers and locking the link once they run out. POST only, it writes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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