aead

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKey

func GenerateKey() []byte

GenerateKey wraps miscreant's GenerateKey function

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-CMAC-SIV

func (*MiscreantCipher) Encrypt

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

Encrypt a value using AES-CMAC-SIV

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

Jump to

Keyboard shortcuts

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