encryption

package module
v0.0.0-...-a882f1d Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: MIT Imports: 12 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Algo_name = map[int32]string{
		0: "UnknownAlgo",
		1: "GCM",
	}
	Algo_value = map[string]int32{
		"UnknownAlgo": 0,
		"GCM":         1,
	}
)

Enum value maps for Algo.

View Source
var File_encrypted_object_proto protoreflect.FileDescriptor

Functions

func RegisterAlgoMapping

func RegisterAlgoMapping(a Algo, at AlgoType)

RgisterAlgoMapping provides the ability to specify new mappings between the proto definition and go code

Types

type Algo

type Algo int32
const (
	Algo_UnknownAlgo Algo = 0
	Algo_GCM         Algo = 1
)

func NewAlgo

func NewAlgo(at AlgoType) (Algo, error)

NewAlgo returns the corresponding Algo to the AlgoType, or returns Algo_Unknown and an error if not matched

func (Algo) Descriptor

func (Algo) Descriptor() protoreflect.EnumDescriptor

func (Algo) Enum

func (x Algo) Enum() *Algo

func (Algo) EnumDescriptor deprecated

func (Algo) EnumDescriptor() ([]byte, []int)

Deprecated: Use Algo.Descriptor instead.

func (Algo) Number

func (x Algo) Number() protoreflect.EnumNumber

func (Algo) String

func (x Algo) String() string

func (Algo) Type

func (Algo) Type() protoreflect.EnumType

type AlgoFactory

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

AlgoFactory manufactures instances of Algorithm by invoking the AlgorithmCreator for the required AlgoType

var DefaultAlgoFactory *AlgoFactory

DefaultAlgoFactory is a AlgoFactory pre-filled with existing AlgoTypes, currently GCM

func NewAlgorithmFactory

func NewAlgorithmFactory(as []AlgorithmCreator) (*AlgoFactory, error)

NewAlgorithmFactory returns an instance of AlgoFactory, pre-filled with the specified set of AlgorithmCreators

func (*AlgoFactory) AddAlgorithmCreator

func (f *AlgoFactory) AddAlgorithmCreator(c AlgorithmCreator) error

AddAlgorithmCreator inserts the specified AlgorithmCreator into the AlgoFactory

func (*AlgoFactory) GetAlgorithm

func (f *AlgoFactory) GetAlgorithm(t AlgoType) (Algorithm, error)

GetAlgorithm returns an instance of a Algorithm of the specified AlgoType

type AlgoType

type AlgoType string

AlgoType identifies the encryption algorithm used

const (
	Unknown AlgoType = "Unknown"
	GCM     AlgoType = "GCM"
)

func ParseAlgo

func ParseAlgo(a Algo) (AlgoType, error)

ParseAlgo returns the corresponding AlgoType to the Algo, or returns Unknown and an error if not matched

type Algorithm

type Algorithm interface {
	CreateKey() ([]byte, error)
	GetType() AlgoType
	GetEncryptor() Encryptor
	GetDecryptor() Decryptor
}

Algorithm provides an Encryptor and Decryptor interface, that implement the specified AlgoType

type AlgorithmCreator

type AlgorithmCreator interface {
	New() Algorithm
}

AlgorithmCreator can construct instances of a Algorithm

func NewGCMCreator

func NewGCMCreator() AlgorithmCreator

NewGCMCreator returns an AlgorithmCreator for GCM

type AlgorithmFactory

type AlgorithmFactory interface {
	AddAlgorithmCreator(a AlgorithmCreator) error
	GetAlgorithm(t AlgoType) (Algorithm, error)
}

AlgorithmFactory returns a Algorithm using the specified algorithm

type Decryptor

type Decryptor interface {
	Decrypt(key []byte, ciphertext []byte) ([]byte, error)
}

Decryptor will attempt to decrypt the ciphertext using the specified key

type EncryptedObject

type EncryptedObject struct {
	KeyToken []byte `protobuf:"bytes,1,opt,name=keyToken,proto3" json:"keyToken,omitempty"`
	A        Algo   `protobuf:"varint,2,opt,name=a,proto3,enum=Algo" json:"a,omitempty"`
	V        []byte `protobuf:"bytes,3,opt,name=v,proto3" json:"v,omitempty"`
	// contains filtered or unexported fields
}

func NewEncryptedObject

func NewEncryptedObject(key []byte, message protoreflect.ProtoMessage, encryptor Encryptor) (*EncryptedObject, error)

NewEncryptedObject creates an instance of EncryptedObject from the supplied message and encryptor details

func NewEncryptedObjectFromToken

func NewEncryptedObjectFromToken(keyToken []byte, message protoreflect.ProtoMessage, encryptor TokenKeyEncryptor) (*EncryptedObject, error)

NewEncryptedObjectFromToken creates an instance of EncryptedObject from the supplied message and encryptor details

func (*EncryptedObject) Descriptor deprecated

func (*EncryptedObject) Descriptor() ([]byte, []int)

Deprecated: Use EncryptedObject.ProtoReflect.Descriptor instead.

func (*EncryptedObject) GetA

func (x *EncryptedObject) GetA() Algo

func (*EncryptedObject) GetKeyToken

func (x *EncryptedObject) GetKeyToken() []byte

func (*EncryptedObject) GetV

func (x *EncryptedObject) GetV() []byte

func (*EncryptedObject) ProtoMessage

func (*EncryptedObject) ProtoMessage()

func (*EncryptedObject) ProtoReflect

func (x *EncryptedObject) ProtoReflect() protoreflect.Message

func (*EncryptedObject) Reset

func (x *EncryptedObject) Reset()

func (*EncryptedObject) String

func (x *EncryptedObject) String() string

type EncryptedObjectParser

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

func NewEncryptedObjectParser

func NewEncryptedObjectParser(decryptor TokenKeyDecryptor) (*EncryptedObjectParser, error)

EncryptedObjectParser decrypts EncryptedObjects in a Message, using the supplied TokenKeyDecryptor

func (*EncryptedObjectParser) Parse

Parse decrypts using into the supplied ProtoMessage instance

type Encryptor

type Encryptor interface {
	Encrypt(key, plaintext []byte) ([]byte, AlgoType, error)
}

Encryptor will attempt to use the key to encrypt the plaintext, returning the AlgoType used as well as the ciphertext

type Keys

type Keys struct {
	Keys map[string][]byte `` /* 149-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*Keys) Descriptor deprecated

func (*Keys) Descriptor() ([]byte, []int)

Deprecated: Use Keys.ProtoReflect.Descriptor instead.

func (*Keys) GetKeys

func (x *Keys) GetKeys() map[string][]byte

func (*Keys) ProtoMessage

func (*Keys) ProtoMessage()

func (*Keys) ProtoReflect

func (x *Keys) ProtoReflect() protoreflect.Message

func (*Keys) Reset

func (x *Keys) Reset()

func (*Keys) String

func (x *Keys) String() string

type TokenKeyDecryptor

type TokenKeyDecryptor interface {
	DecryptFromToken(token []byte, a AlgoType, ciphertext []byte) ([]byte, error)
}

TokenKeyDecryptor receives a token value and AlgoType, which is used to retrieve the key required to decrypt and the algo to use to attempt decryption. Behaviour when the key is not available is unspecified.

type TokenKeyDecryptorCreator

type TokenKeyDecryptorCreator func(a Algorithm, keys map[string][]byte) TokenKeyDecryptor

TokenKeyDecryptorCreator returns an initialised TokenKeyDecryptor

type TokenKeyEncryptionCreator

type TokenKeyEncryptionCreator interface {
	GetID() TokenKeyEncryptionCreatorID
	GetEncryptionAlgoType() AlgoType
	GetTokenKeyDecryptor(key []byte, keys *EncryptedObject, factory AlgorithmFactory) (TokenKeyDecryptor, error)
	GetTokenKeyEncryptor() (TokenKeyEncryptor, error)
}

TokenKeyEncryptionCreator can manufacture encryptors and decryptors

func NewTokenKeyEncryptionCreator

NewTokenKeyEncryptionCreator provides a construction mechanism to create instances of TokenKeyEncryptionCreator

type TokenKeyEncryptionCreatorID

type TokenKeyEncryptionCreatorID string

TokenKeyEncryptionCreatorID identifies TokenKeyEncryptionCreators

type TokenKeyEncryptionCreatorIDList

type TokenKeyEncryptionCreatorIDList []TokenKeyEncryptionCreatorID

TokenKeyEncryptionCreatorIDList is a slice of TokenKeyEncryptionCreatorID

func (TokenKeyEncryptionCreatorIDList) Len

Len returns the number of IDs in the slice

func (TokenKeyEncryptionCreatorIDList) Less

Less returns true if the ID at i is less than at j

func (TokenKeyEncryptionCreatorIDList) Swap

func (tl TokenKeyEncryptionCreatorIDList) Swap(i, j int)

Swap will switch the IDs at i and j

type TokenKeyEncryptionFactory

type TokenKeyEncryptionFactory interface {
	GetTokenKeyEncryptionCreatorIDs() TokenKeyEncryptionCreatorIDList
	AddTokenKeyEncryptionCreator(c TokenKeyEncryptionCreator) error
	GetTokenKeyDecryptor(i TokenKeyEncryptionCreatorID, key []byte, keys *EncryptedObject, factory AlgorithmFactory) (TokenKeyDecryptor, error)
	GetTokenKeyEncryptor(i TokenKeyEncryptionCreatorID) (TokenKeyEncryptor, error)
}

TokenKeyEncryptionFactory returns the encryptor or decryptor for the specified TokenKeyEncryptionCreatorID

var DefaultTokenKeyEncryptionFactory TokenKeyEncryptionFactory

DefaultTokenKeyEncryptionFactory is a TokenKeyEncryptionFactory pre-filled with with default TokenKeyEncryptionCreators (currently only DefaultGCM)

func NewTokenKeyEncryptionFactory

func NewTokenKeyEncryptionFactory(as []TokenKeyEncryptionCreator) (TokenKeyEncryptionFactory, error)

NewTokenKeyEncryptionFactory returns an instance of TokenKeyEncryptionFactory, pre-filled with the specified set of TokenKeyEncryptionCreators

type TokenKeyEncryptor

type TokenKeyEncryptor interface {
	EncryptFromToken(token []byte, plaintext []byte) ([]byte, AlgoType, error)
	GetKeys(key []byte, a Algorithm) (*EncryptedObject, error)
}

TokenKeyEncryptor receives a token value which is used to retrieve the key required to encrypt.

The GetKeys function uses the provided key to encrypt the map of tokens->keys inside an EncryptedObject, for secure distribution

type TokenKeyEncryptorCreator

type TokenKeyEncryptorCreator func(a Algorithm) TokenKeyEncryptor

TokenKeyEncryptorCreator returns an initialised TokenKeyEncryptor

Jump to

Keyboard shortcuts

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