saascrypto

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Cryptography that is useful for SaaS apps

Index

Constants

View Source
const SecretLen = 32

The length of an unencoded secret, in bytes

Variables

View Source
var ErrExpired = errors.New("ciphertext has expired")
View Source
var ErrMalformedBearerToken = errors.New("malformed bearer token")
View Source
var ErrTampered = errors.New("ciphertext has been tampered")

Functions

func DeobfuscateUint32

func DeobfuscateUint32(secret *Secret, idType string, obfuscatedID [4]byte) uint32

func DeobfuscateUint64

func DeobfuscateUint64(secret *Secret, idType string, obfuscatedID [8]byte) uint64

func ObfuscateUint32

func ObfuscateUint32(secret *Secret, idType string, id uint32) [4]byte

func ObfuscateUint64

func ObfuscateUint64(secret *Secret, idType string, id uint64) [8]byte

func Open

func Open(ciphertextString string, secret *Secret, usage string, value interface{}) error

func Seal

func Seal(secret *Secret, usage string, ttl time.Duration, value interface{}) string

Types

type BearerToken

type BearerToken struct {
	IDType uint8
	ID     uint64
	Secret []byte
}

func BearerTokenFromRequest

func BearerTokenFromRequest(appSecret *Secret, tokenPurpose string, req *http.Request) (*BearerToken, error)

func ParseBearerToken

func ParseBearerToken(appSecret *Secret, tokenPurpose string, token string) (*BearerToken, error)

func (*BearerToken) Encode

func (token *BearerToken) Encode(appSecret *Secret, tokenPurpose string) string

func (*BearerToken) EncodeRedacted

func (token *BearerToken) EncodeRedacted(appSecret *Secret, tokenPurpose string) string

Like Encode, but the secret bits are replaced with "..."

func (*BearerToken) Redact

func (token *BearerToken) Redact() *BearerToken

Return a copy of token without Secret

type Secret

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

A secret that is used for deriving other secrets

func ParseSecret

func ParseSecret(hexString string) (*Secret, error)

Parse a hex-encoded secret. hexString must be SecretLen*2 characters long

func (*Secret) Derive

func (secret *Secret) Derive(outBytes []byte, usage string)

Place secret bytes into outBytes. usage must uniquely identify how the derived secret will be used.

func (*Secret) IsZero

func (secret *Secret) IsZero() bool

Jump to

Keyboard shortcuts

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