aead

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidValue is an error for an invalid value
	ErrInvalidValue = errors.New("invalid value")
)

Functions

func GenerateKey

func GenerateKey() []byte

GenerateKey wraps miscreant's GenerateKey function

func Nonce

func Nonce(length int) ([]byte, error)

Nonce returns a one time use random number

Types

type Cipher

type Cipher interface {
	Encrypt([]byte) ([]byte, error)
	Decrypt([]byte) ([]byte, error)
	Marshal(interface{}) (string, error)
	Unmarshal(string, interface{}) error
}

Cipher provides methods to encrypt and decrypt values.

type MiscreantCipher

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

MiscreantCipher provides methods to encrypt and decrypt values. Using an AEAD is a cipher providing authenticated encryption with associated data. For a description of the methodology, see https://en.wikipedia.org/wiki/Authenticated_encryption

func NewMiscreantCipher

func NewMiscreantCipher(secret []byte) (*MiscreantCipher, error)

NewMiscreantCipher returns a new AES Cipher for encrypting values

func (*MiscreantCipher) Decrypt

func (c *MiscreantCipher) Decrypt(joined []byte) ([]byte, error)

Decrypt a value using AES GCM

func (*MiscreantCipher) Encrypt

func (c *MiscreantCipher) Encrypt(plaintext []byte) (joined []byte, err error)

Encrypt a value using AES GCM

func (*MiscreantCipher) Marshal

func (c *MiscreantCipher) Marshal(s interface{}) (string, error)

Marshal marshals the interface state as JSON, encrypts the JSON using the cipher and base64 encodes the binary value as a string and returns the result

func (*MiscreantCipher) Unmarshal

func (c *MiscreantCipher) Unmarshal(value string, s interface{}) error

Unmarshal takes the marshaled string, base64-decodes into a byte slice, decrypts the byte slice the pased cipher, and unmarshals the resulting JSON into the struct pointer passed

type MockCipher

type MockCipher struct {
	MarshalError   error
	MarshalString  string
	UnmarshalError error
	UnmarshalBytes []byte
}

MockCipher is a mock of the cipher interface

func (*MockCipher) Decrypt

func (mc *MockCipher) Decrypt([]byte) ([]byte, error)

Decrypt returns an empty byte array and nil

func (*MockCipher) Encrypt

func (mc *MockCipher) Encrypt([]byte) ([]byte, error)

Encrypt returns an empty byte array and nil

func (*MockCipher) Marshal

func (mc *MockCipher) Marshal(interface{}) (string, error)

Marshal returns the marshal string and marsha error

func (*MockCipher) Unmarshal

func (mc *MockCipher) Unmarshal(b string, s interface{}) error

Unmarshal unmarshals the unmarshal bytes to be set in s and returns the unmarshal error

type OldCipher

type OldCipher struct {
	cipher.AEAD
}

OldCipher provides methods to encrypt and decrypt values. Using an AEAD is a cipher providing authenticated encryption with associated data. For a description of the methodology, see https://en.wikipedia.org/wiki/Authenticated_encryption

func NewOldCipher

func NewOldCipher(secret []byte) (*OldCipher, error)

NewOldCipher returns a new AES Cipher for encrypting values

func (*OldCipher) Decrypt

func (c *OldCipher) Decrypt(joined []byte) ([]byte, error)

Decrypt a value using AES GCM

func (*OldCipher) Encrypt

func (c *OldCipher) Encrypt(plaintext []byte) ([]byte, error)

Encrypt a value using AES GCM

func (*OldCipher) Marshal

func (c *OldCipher) Marshal(s interface{}) (string, error)

Marshal marshals the interface state as JSON, encrypts the JSON using the cipher and base64 encodes teh binary value as a string and returns the result

func (*OldCipher) Unmarshal

func (c *OldCipher) Unmarshal(value string, s interface{}) error

Unmarshal takes the marshaled string, base64-decodes into a byte slice, decrypts the byte slice the pased cipher, and unmarshals the resulting JSON into the struct pointer passed

Jump to

Keyboard shortcuts

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