crypto

package
v1.80.0-pref-login-name.5 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package crypto is a generated GoMock package.

Package crypto is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmpty = errors.New("cannot decode, empty data")

Functions

func BytesToPrivateKey

func BytesToPrivateKey(priv []byte) (*rsa.PrivateKey, error)

func BytesToPublicKey

func BytesToPublicKey(pub []byte) (*rsa.PublicKey, error)

func CompareHash

func CompareHash(value *CryptoValue, comparer []byte, alg HashAlgorithm) error

func Decrypt

func Decrypt(value *CryptoValue, alg EncryptionAlgorithm) ([]byte, error)

func DecryptAES

func DecryptAES(text []byte, key string) ([]byte, error)

func DecryptAESString

func DecryptAESString(data string, key string) (string, error)

func DecryptString

func DecryptString(value *CryptoValue, alg EncryptionAlgorithm) (string, error)

func EncryptAES

func EncryptAES(plainText []byte, key string) ([]byte, error)

func EncryptAESString

func EncryptAESString(data string, key string) (string, error)

func EncryptKeys

func EncryptKeys(privateKey *rsa.PrivateKey, publicKey *rsa.PublicKey, alg EncryptionAlgorithm) (*CryptoValue, *CryptoValue, error)

func GenerateEncryptedKeyPair

func GenerateEncryptedKeyPair(bits int, alg EncryptionAlgorithm) (*CryptoValue, *CryptoValue, error)

func GenerateKeyPair

func GenerateKeyPair(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)

func IsCodeExpired

func IsCodeExpired(creationDate time.Time, expiry time.Duration) bool

func LoadKey

func LoadKey(id string, keyStorage KeyStorage) (string, error)

func PrivateKeyToBytes

func PrivateKeyToBytes(priv *rsa.PrivateKey) []byte

func PublicKeyToBytes

func PublicKeyToBytes(pub *rsa.PublicKey) ([]byte, error)

func VerifyCode

func VerifyCode(creationDate time.Time, expiry time.Duration, cryptoCode *CryptoValue, verificationCode string, g Generator) error

Types

type AESCrypto

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

func NewAESCrypto

func NewAESCrypto(config *KeyConfig, keyStorage KeyStorage) (*AESCrypto, error)

func (*AESCrypto) Algorithm

func (a *AESCrypto) Algorithm() string

func (*AESCrypto) Decrypt

func (a *AESCrypto) Decrypt(value []byte, keyID string) ([]byte, error)

func (*AESCrypto) DecryptString

func (a *AESCrypto) DecryptString(value []byte, keyID string) (string, error)

func (*AESCrypto) DecryptionKeyIDs

func (a *AESCrypto) DecryptionKeyIDs() []string

func (*AESCrypto) Encrypt

func (a *AESCrypto) Encrypt(value []byte) ([]byte, error)

func (*AESCrypto) EncryptionKeyID

func (a *AESCrypto) EncryptionKeyID() string

type BCrypt

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

func NewBCrypt

func NewBCrypt(cost int) *BCrypt

func (*BCrypt) Algorithm

func (b *BCrypt) Algorithm() string

func (*BCrypt) CompareHash

func (b *BCrypt) CompareHash(hashed, value []byte) error

func (*BCrypt) Hash

func (b *BCrypt) Hash(value []byte) ([]byte, error)

type Crypto

type Crypto interface {
	Algorithm() string
}

type CryptoType

type CryptoType int
const (
	TypeEncryption CryptoType = iota
	TypeHash
)

type CryptoValue

type CryptoValue struct {
	CryptoType CryptoType
	Algorithm  string
	KeyID      string
	Crypted    []byte
}

func Crypt

func Crypt(value []byte, c Crypto) (*CryptoValue, error)

func Encrypt

func Encrypt(value []byte, alg EncryptionAlgorithm) (*CryptoValue, error)

func Hash

func Hash(value []byte, alg HashAlgorithm) (*CryptoValue, error)

func NewCode

func NewCode(g Generator) (*CryptoValue, string, error)

func (*CryptoValue) Scan

func (c *CryptoValue) Scan(src interface{}) error

func (*CryptoValue) Value

func (c *CryptoValue) Value() (driver.Value, error)

type EncryptionAlgorithm

type EncryptionAlgorithm interface {
	Crypto
	EncryptionKeyID() string
	DecryptionKeyIDs() []string
	Encrypt(value []byte) ([]byte, error)
	Decrypt(hashed []byte, keyID string) ([]byte, error)
	DecryptString(hashed []byte, keyID string) (string, error)
}

func CreateMockEncryptionAlg

func CreateMockEncryptionAlg(ctrl *gomock.Controller) EncryptionAlgorithm

type Generator

type Generator interface {
	Length() uint
	Expiry() time.Duration
	Alg() Crypto
	Runes() []rune
}

func NewEncryptionGenerator

func NewEncryptionGenerator(config GeneratorConfig, algorithm EncryptionAlgorithm) Generator

func NewHashGenerator

func NewHashGenerator(config GeneratorConfig, algorithm HashAlgorithm) Generator

type GeneratorConfig

type GeneratorConfig struct {
	Length              uint
	Expiry              time.Duration
	IncludeLowerLetters bool
	IncludeUpperLetters bool
	IncludeDigits       bool
	IncludeSymbols      bool
}

type HashAlgorithm

type HashAlgorithm interface {
	Crypto
	Hash(value []byte) ([]byte, error)
	CompareHash(hashed, comparer []byte) error
}

func CreateMockHashAlg

func CreateMockHashAlg(ctrl *gomock.Controller) HashAlgorithm

type Key

type Key struct {
	ID    string
	Value string
}

func NewKey

func NewKey(id string) (*Key, error)

type KeyConfig

type KeyConfig struct {
	EncryptionKeyID  string
	DecryptionKeyIDs []string
}

type KeyStorage

type KeyStorage interface {
	ReadKeys() (Keys, error)
	ReadKey(id string) (*Key, error)
	CreateKeys(...*Key) error
}

type Keys

type Keys map[string]string

func LoadKeys

func LoadKeys(config *KeyConfig, keyStorage KeyStorage) (Keys, []string, error)

type MockCrypto

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

MockCrypto is a mock of Crypto interface

func NewMockCrypto

func NewMockCrypto(ctrl *gomock.Controller) *MockCrypto

NewMockCrypto creates a new mock instance

func (*MockCrypto) Algorithm

func (m *MockCrypto) Algorithm() string

Algorithm mocks base method

func (*MockCrypto) EXPECT

func (m *MockCrypto) EXPECT() *MockCryptoMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

type MockCryptoMockRecorder

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

MockCryptoMockRecorder is the mock recorder for MockCrypto

func (*MockCryptoMockRecorder) Algorithm

func (mr *MockCryptoMockRecorder) Algorithm() *gomock.Call

Algorithm indicates an expected call of Algorithm

type MockEncryptionAlgorithm

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

MockEncryptionAlgorithm is a mock of EncryptionAlgorithm interface

func NewMockEncryptionAlgorithm

func NewMockEncryptionAlgorithm(ctrl *gomock.Controller) *MockEncryptionAlgorithm

NewMockEncryptionAlgorithm creates a new mock instance

func (*MockEncryptionAlgorithm) Algorithm

func (m *MockEncryptionAlgorithm) Algorithm() string

Algorithm mocks base method

func (*MockEncryptionAlgorithm) Decrypt

func (m *MockEncryptionAlgorithm) Decrypt(hashed []byte, keyID string) ([]byte, error)

Decrypt mocks base method

func (*MockEncryptionAlgorithm) DecryptString

func (m *MockEncryptionAlgorithm) DecryptString(hashed []byte, keyID string) (string, error)

DecryptString mocks base method

func (*MockEncryptionAlgorithm) DecryptionKeyIDs

func (m *MockEncryptionAlgorithm) DecryptionKeyIDs() []string

DecryptionKeyIDs mocks base method

func (*MockEncryptionAlgorithm) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockEncryptionAlgorithm) Encrypt

func (m *MockEncryptionAlgorithm) Encrypt(value []byte) ([]byte, error)

Encrypt mocks base method

func (*MockEncryptionAlgorithm) EncryptionKeyID

func (m *MockEncryptionAlgorithm) EncryptionKeyID() string

EncryptionKeyID mocks base method

type MockEncryptionAlgorithmMockRecorder

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

MockEncryptionAlgorithmMockRecorder is the mock recorder for MockEncryptionAlgorithm

func (*MockEncryptionAlgorithmMockRecorder) Algorithm

Algorithm indicates an expected call of Algorithm

func (*MockEncryptionAlgorithmMockRecorder) Decrypt

func (mr *MockEncryptionAlgorithmMockRecorder) Decrypt(hashed, keyID interface{}) *gomock.Call

Decrypt indicates an expected call of Decrypt

func (*MockEncryptionAlgorithmMockRecorder) DecryptString

func (mr *MockEncryptionAlgorithmMockRecorder) DecryptString(hashed, keyID interface{}) *gomock.Call

DecryptString indicates an expected call of DecryptString

func (*MockEncryptionAlgorithmMockRecorder) DecryptionKeyIDs

func (mr *MockEncryptionAlgorithmMockRecorder) DecryptionKeyIDs() *gomock.Call

DecryptionKeyIDs indicates an expected call of DecryptionKeyIDs

func (*MockEncryptionAlgorithmMockRecorder) Encrypt

func (mr *MockEncryptionAlgorithmMockRecorder) Encrypt(value interface{}) *gomock.Call

Encrypt indicates an expected call of Encrypt

func (*MockEncryptionAlgorithmMockRecorder) EncryptionKeyID

func (mr *MockEncryptionAlgorithmMockRecorder) EncryptionKeyID() *gomock.Call

EncryptionKeyID indicates an expected call of EncryptionKeyID

type MockGenerator

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

MockGenerator is a mock of Generator interface

func NewMockGenerator

func NewMockGenerator(ctrl *gomock.Controller) *MockGenerator

NewMockGenerator creates a new mock instance

func (*MockGenerator) Alg

func (m *MockGenerator) Alg() Crypto

Alg mocks base method

func (*MockGenerator) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockGenerator) Expiry

func (m *MockGenerator) Expiry() time.Duration

Expiry mocks base method

func (*MockGenerator) Length

func (m *MockGenerator) Length() uint

Length mocks base method

func (*MockGenerator) Runes

func (m *MockGenerator) Runes() []rune

Runes mocks base method

type MockGeneratorMockRecorder

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

MockGeneratorMockRecorder is the mock recorder for MockGenerator

func (*MockGeneratorMockRecorder) Alg

Alg indicates an expected call of Alg

func (*MockGeneratorMockRecorder) Expiry

func (mr *MockGeneratorMockRecorder) Expiry() *gomock.Call

Expiry indicates an expected call of Expiry

func (*MockGeneratorMockRecorder) Length

func (mr *MockGeneratorMockRecorder) Length() *gomock.Call

Length indicates an expected call of Length

func (*MockGeneratorMockRecorder) Runes

func (mr *MockGeneratorMockRecorder) Runes() *gomock.Call

Runes indicates an expected call of Runes

type MockHashAlgorithm

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

MockHashAlgorithm is a mock of HashAlgorithm interface

func NewMockHashAlgorithm

func NewMockHashAlgorithm(ctrl *gomock.Controller) *MockHashAlgorithm

NewMockHashAlgorithm creates a new mock instance

func (*MockHashAlgorithm) Algorithm

func (m *MockHashAlgorithm) Algorithm() string

Algorithm mocks base method

func (*MockHashAlgorithm) CompareHash

func (m *MockHashAlgorithm) CompareHash(hashed, comparer []byte) error

CompareHash mocks base method

func (*MockHashAlgorithm) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockHashAlgorithm) Hash

func (m *MockHashAlgorithm) Hash(value []byte) ([]byte, error)

Hash mocks base method

type MockHashAlgorithmMockRecorder

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

MockHashAlgorithmMockRecorder is the mock recorder for MockHashAlgorithm

func (*MockHashAlgorithmMockRecorder) Algorithm

func (mr *MockHashAlgorithmMockRecorder) Algorithm() *gomock.Call

Algorithm indicates an expected call of Algorithm

func (*MockHashAlgorithmMockRecorder) CompareHash

func (mr *MockHashAlgorithmMockRecorder) CompareHash(hashed, comparer interface{}) *gomock.Call

CompareHash indicates an expected call of CompareHash

func (*MockHashAlgorithmMockRecorder) Hash

func (mr *MockHashAlgorithmMockRecorder) Hash(value interface{}) *gomock.Call

Hash indicates an expected call of Hash

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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