Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidValue is an error for an invalid value ErrInvalidValue = errors.New("invalid value") )
Functions ¶
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 ¶
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 ¶
NewOldCipher returns a new AES Cipher for encrypting values