tokenize

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyAlreadyExists = errors.New("key already exists. not overriding")
	ErrKeyDoesNotExists = "key %s does not exist"
	ErrDuplicateKeys    = errors.New("key already exists in request. accepted only the first one")
)
View Source
var (
	DefaultCipherLoc           = "./.cipher"
	EnvKeyAESCipher            = "CIPHER"
	EnvKeyInitializationVector = "IV"
	KeyDelimiter               = "__"
)
View Source
var (
	ErrCipherToken404AES                 = errors.New("aes cipher not found in cipher map")
	ErrCipherToken404IV                  = errors.New("initialization vector (IV) not found in cipher map")
	ErrTokenInvalidPadding               = errors.New("invalid token string: padded bytes larger than aes block size: 16")
	ErrTokenInvalidPaddingNotHomogeneous = errors.New("invalid token string: padded bytes are not all the same")
	ErrTokenInvalidBlockSize             = errors.New("invalid token string: decrypted bytes size is not a multiple of the block size")
)

Functions

func Detokenize

func Detokenize(token string, cypher map[string]string) (string, error)

func GenAlphaNumericString

func GenAlphaNumericString(n int) string

GenAlphaNumericString mimics strings.Builder with package unsafe. According to the author it is one of the pastest implementation of strings builder.

func GetCombinedKey

func GetCombinedKey(s ...string) (cs string)

GetCombinedKey creates a key string unique to every value in the request object. This key string is a concatenation of all the parent keys that constitute the request data

func IsErrKeyAlreadyExist

func IsErrKeyAlreadyExist(err error) bool

IsErrKeyAlreadyExist enables easy checking of error

func WithStore

func WithStore(store store.Store) func(*Manager)

Types

type Manager

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

func NewManager

func NewManager(ctx context.Context, logger *vlog.Logger, opts ...Options) *Manager

NewManager creates a new instance of Manager. It manages token operations (retrieval, storage, servicing) throughout the lifetime of the server.

func (*Manager) DeleteTokenByID

func (m *Manager) DeleteTokenByID(ctx context.Context, id string) (bool, error)

DeleteTokenByID deletes the token from the store identified by ID

func (*Manager) Detokenize

func (m *Manager) Detokenize(ctx context.Context, key, token string) (bool, string, error)

Detokenize retrieves the value represented by a particular token, identified by the particular key

func (*Manager) GenerateCipher

func (m *Manager) GenerateCipher() error

GenerateCipher generates a new AES cipher and Initialization Vector pais, and persists it to disk

func (*Manager) GetAllTokens

func (m *Manager) GetAllTokens(ctx context.Context) ([]*model.Tokenize, error)

GetAllTokens returns all tokens currently in the store

func (*Manager) GetTokenByID

func (m *Manager) GetTokenByID(ctx context.Context, id string) (*model.Tokenize, error)

GetTokenByID returns the token owned by a specific ID/Key

func (*Manager) PatchTokenByID

func (m *Manager) PatchTokenByID(ctx context.Context, key, val string) (string, error)

PatchTokenByID updates a token in the store identified by ID

func (*Manager) Tokenize

func (m *Manager) Tokenize(ctx context.Context, key, val string) (string, error)

Tokenize manages the tokenization, and stores generated tokens in an internal store, for easy retrieval

func (*Manager) Validate

func (m *Manager) Validate(ctx context.Context, token *model.Tokenize, patch bool) ([]*ValidateResponse, bool)

Validate is the high level api for validating all the user provided data

func (*Manager) ValidateKeys

func (m *Manager) ValidateKeys(ctx context.Context, token *model.Tokenize) ([]*ValidateResponse, bool)

ValidateKeys validates the Keys used in the request, ensuring it doesn't already exist, and that it conforms with the standards.

type Options

type Options func(*Manager)

type Token

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

func Tokenize

func Tokenize(s string, cypher map[string]string) (*Token, error)

func (*Token) String

func (t *Token) String() string

type ValidateResponse

type ValidateResponse struct {
	Key string
	Err error
}

ValidateResponse holds the error response from validation and the associated key.

Jump to

Keyboard shortcuts

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