share

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

internal/share/anon.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnonDisplayName added in v0.2.0

func AnonDisplayName(srcPath string) string

AnonDisplayName returns a 6-char lowercase-base32 slug, followed by the lowercased extension of srcPath (if any). Example: "secret.PDF" -> "k9vm3q.pdf". The source file's original name and path are never included.

func ContentDispositionHeader

func ContentDispositionHeader(name string, mode DispositionMode) (string, error)

ContentDispositionHeader builds an RFC 6266 Content-Disposition value. Uses the ext-value (filename*) form for non-ASCII characters. Expects name to have already passed SanitizeDisplayName.

func Digest

func Digest(tok string) [32]byte

Digest returns the SHA-256 of a token. Only digests hit disk; raw tokens stay in memory.

func EqualDigest

func EqualDigest(a, b [32]byte) bool

EqualDigest compares two digests in constant time.

func NewID

func NewID() string

NewID returns a 40-bit ID encoded as 8 lowercase base32 chars.

func NewToken

func NewToken() string

NewToken returns a 128-bit token encoded as 26 lowercase base32 chars.

func SanitizeDisplayName

func SanitizeDisplayName(name string) (string, error)

SanitizeDisplayName validates a user-supplied display name for use in URL path and Content-Disposition. Rejects anything that could enable path traversal, header injection, or Windows-reserved devices.

Types

type DispositionMode

type DispositionMode int
const (
	Inline DispositionMode = iota
	Attachment
)

type Share

type Share struct {
	ID          string   // 8-char base32, surfaced to user
	Token       string   // 26-char base32, in URL path
	TokenDigest [32]byte // SHA-256 of Token, persisted to history
	SrcPath     string   // absolute, symlink-resolved path
	DisplayName string   // sanitized
	CreatedAt   time.Time
	ExpiresAt   time.Time
	Revoked     bool
}

Share is an active (or historical) file share.

func (Share) Active

func (s Share) Active(t time.Time) bool

Active reports whether the share is currently accessible at time t.

Jump to

Keyboard shortcuts

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