secret

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound          = errors.New("not found")
	ErrInvalidPassphrase = errors.New("invalid passphrase")
	ErrExpired           = errors.New("expired")
)

Functions

This section is empty.

Types

type Encryptor

type Encryptor interface {
	Encrypt(ctx context.Context, passpharse, message string) ([]byte, error)
	Decrypt(ctx context.Context, passphrase string, data []byte) (string, error)
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(secrets *Service, renderer *html.Renderer) *Handler

func (*Handler) Open

func (h *Handler) Open(w http.ResponseWriter, r *http.Request)

func (*Handler) Share

func (h *Handler) Share(w http.ResponseWriter, r *http.Request)

type InMemoryStore

type InMemoryStore struct {
	// contains filtered or unexported fields
}

func NewInMemoryStore

func NewInMemoryStore(logger *slog.Logger) *InMemoryStore

func (*InMemoryStore) Cleanup

func (s *InMemoryStore) Cleanup(ctx context.Context)

func (*InMemoryStore) Load

func (s *InMemoryStore) Load(ctx context.Context, key string) (Secret, error)

func (*InMemoryStore) Remove

func (s *InMemoryStore) Remove(ctx context.Context, key string) error

func (*InMemoryStore) Save

func (s *InMemoryStore) Save(ctx context.Context, key string, secret Secret) error

type RetrieveRequest

type RetrieveRequest struct {
	Key        string
	Passphrase string
}

type Secret

type Secret struct {
	// contains filtered or unexported fields
}

type SecretboxEncryptor

type SecretboxEncryptor struct {
	// contains filtered or unexported fields
}

func NewSecretboxEncryptor

func NewSecretboxEncryptor(logger *slog.Logger) *SecretboxEncryptor

func (*SecretboxEncryptor) Decrypt

func (e *SecretboxEncryptor) Decrypt(ctx context.Context, passphrase string, data []byte) (string, error)

func (*SecretboxEncryptor) Encrypt

func (e *SecretboxEncryptor) Encrypt(ctx context.Context, passphrase, message string) ([]byte, error)

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(logger *slog.Logger, encryptor Encryptor, store Store, cleanupInterval time.Duration, now func() time.Time) *Service

func (*Service) CleanupLoop

func (s *Service) CleanupLoop(ctx context.Context) bool

func (*Service) Retrieve

func (s *Service) Retrieve(ctx context.Context, request RetrieveRequest) (string, error)

func (*Service) Store

func (s *Service) Store(ctx context.Context, request StoreRequest) (string, error)

type Store

type Store interface {
	Save(ctx context.Context, key string, secret Secret) error
	Load(ctx context.Context, key string) (Secret, error)
	Remove(ctx context.Context, key string) error
	Cleanup(ctx context.Context)
}

type StoreRequest

type StoreRequest struct {
	Passphrase string
	Message    string
	Attempts   int
	ExpireAt   time.Time
}

Jump to

Keyboard shortcuts

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