h2cipher

package
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotSupported is returned when the cipher is not supported
	ErrNotSupported errNotSupported
	// ErrKeyInvalid is returned when the cipher key config is invalid
	ErrKeyInvalid errKeyInvalid
	// ErrCiphertextInvalid is returned when the ciphertext is invalid
	ErrCiphertextInvalid errCiphertextInvalid
)

Functions

func KeyID

func KeyID(params string) string

KeyID computes a key id from params

Types

type Algs

type Algs interface {
	Register(b Builder)
	Get(id string) (Builder, bool)
}

Algs are a map of valid cipher algorithms

type AlgsMap

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

func NewAlgsMap

func NewAlgsMap() *AlgsMap

func (*AlgsMap) Get

func (m *AlgsMap) Get(id string) (Builder, bool)

func (*AlgsMap) Register

func (m *AlgsMap) Register(b Builder)

type Builder

type Builder interface {
	ID() string
	Build(params string) (Cipher, error)
}

Builder constructs a new cipher from params

type Cipher

type Cipher interface {
	ID() string
	Encrypt(plaintext []byte) (string, error)
	Decrypt(ciphertext string) ([]byte, error)
}

Cipher is an encryption interface

func FromParams

func FromParams(params string, algs Algs) (Cipher, error)

FromParams creates a cipher from params

type Keyring

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

Keyring decrypts ciphertext

func NewKeyring

func NewKeyring() *Keyring

NewKeyring creates a new decrypter

func (*Keyring) Decrypt

func (k *Keyring) Decrypt(ciphertext string) ([]byte, error)

Decrypt finds the cipher by id and returns plaintext

func (*Keyring) Register

func (k *Keyring) Register(cipher Cipher)

Register registers a Cipher

func (*Keyring) Size

func (k *Keyring) Size() int

Size returns the number of registered ciphers

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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