keys

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotImplementedKeyType  = errors.New("this type of key is not yet implemented")
	ErrInvalidKeySize         = errors.New("invalid key size")
	ErrInvalidKeyType         = errors.New("invalid key type. Type should be equal to rsa, dsa, ecdsa or ed25519")
	ErrPrivateKeyNotGenerated = errors.New("private key must be generated before generating the public key")
	ErrKeySizeNotValid        = errors.New("key size is not valid")
	ErrKeyOverrideNotAllowed  = errors.New("overriding the key is not allowed")
)

Keys errors

View Source
var Types = []Type{RSA, ECDSA, ED25519}

Types contains the list of key types

Functions

func EncodeToPEM

func EncodeToPEM(privateKey crypto.PrivateKey, pwd string) ([]byte, error)

EncodeToPEM encodes the key into PEM

func GetDir

func GetDir(path string) string

GetDir get the destination directory

func GetFilenamesFromString

func GetFilenamesFromString(pk string) (string, string)

GetFilenamesFromString returns a pair of string based on user's input The first value is the name of the private key The second value is the name of the public key

func GetFilenamesFromType

func GetFilenamesFromType(t Type) (pk string, pub string)

GetFilenamesFromType returns a pair of string based on the type of key The first value is the name of the private key The second value is the name of the public key

func MakeDir

func MakeDir(path string) error

MakeDir makes destination directory if it does not exist

func TypesToString

func TypesToString() string

TypesToString returns the list of key types separated by a comma

func WriteToFile

func WriteToFile(b []byte, path string) error

WriteToFile writes the key to a file

func Writekeys added in v0.0.4

func Writekeys(publicKey []byte, privateKey []byte, opts *Options) error

Writekeys writes keys to files

Types

type ECDSAGenerator

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

ECDSAGenerator generates ECDSA private and public keys

func (*ECDSAGenerator) GenPrivateKey

func (g *ECDSAGenerator) GenPrivateKey() ([]byte, error)

GenPrivateKey generates a ECDSA private key

func (*ECDSAGenerator) GenPublicKey

func (g *ECDSAGenerator) GenPublicKey() ([]byte, error)

GenPublicKey generates a ECDSA public key

type ECDSAKeySize

type ECDSAKeySize struct{}

ECDSAKeySize ECDSA complexity implementation

func (*ECDSAKeySize) GetDefault

func (c *ECDSAKeySize) GetDefault() string

GetDefault returns the default complexity

func (*ECDSAKeySize) GetValue

func (c *ECDSAKeySize) GetValue(s string) interface{}

GetValue returns the complexity value

func (*ECDSAKeySize) GetValues

func (c *ECDSAKeySize) GetValues() []string

GetValues returns the available complexity values

type ED25519Generator

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

ED25519Generator generates RSA private and public keys

func (*ED25519Generator) GenPrivateKey

func (g *ED25519Generator) GenPrivateKey() ([]byte, error)

GenPrivateKey generates a ED25519 private key

func (*ED25519Generator) GenPublicKey

func (g *ED25519Generator) GenPublicKey() ([]byte, error)

GenPublicKey generates a ED25519 public key

type ED25519KeySize

type ED25519KeySize struct{}

ED25519KeySize ED25519 complexity implementation

func (*ED25519KeySize) GetDefault

func (c *ED25519KeySize) GetDefault() string

GetDefault returns the default complexity

func (*ED25519KeySize) GetValue

func (c *ED25519KeySize) GetValue(s string) interface{}

GetValue returns the complexity value

func (*ED25519KeySize) GetValues

func (c *ED25519KeySize) GetValues() []string

GetValues returns the available complexity values

type Generator

type Generator interface {
	GenPublicKey() ([]byte, error)
	GenPrivateKey() ([]byte, error)
}

Generator interface describing what is a generator

func GetGenerator

func GetGenerator(o *Options) Generator

GetGenerator returns the generator matching the type of key

type KeySize

type KeySize interface {
	GetDefault() string
	GetValues() []string
	GetValue(v string) interface{}
}

KeySize interface describing how to retrieve KeySize struct

func GetKeySize

func GetKeySize(t Type) KeySize

GetKeySize returns the generator matching the type of key

type Options

type Options struct {
	KeyType    Type
	Host       string
	PassPhrase string
	PrivateKey string
	PublicKey  string
	Directory  string
	KeySize    interface{}
}

Options keys options

type RSAGenerator

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

RSAGenerator generates RSA private and public keys

func (*RSAGenerator) GenPrivateKey

func (g *RSAGenerator) GenPrivateKey() ([]byte, error)

GenPrivateKey generates a RSA private key

func (*RSAGenerator) GenPublicKey

func (g *RSAGenerator) GenPublicKey() ([]byte, error)

GenPublicKey generates a RSA public key

type RSAKeySize

type RSAKeySize struct{}

RSAKeySize RSA complexity implementation

func (*RSAKeySize) GetDefault

func (c *RSAKeySize) GetDefault() string

GetDefault returns the default complexity

func (*RSAKeySize) GetValue

func (c *RSAKeySize) GetValue(s string) interface{}

GetValue returns the complexity value

func (*RSAKeySize) GetValues

func (c *RSAKeySize) GetValues() []string

GetValues returns the available complexity values

type Type

type Type string

Type the type of the key, rsa, dsa, , etc...

const (
	RSA     Type = "rsa"
	ECDSA   Type = "ecdsa"
	ED25519 Type = "ed25519"
	INVALID Type = "invalid"
)

Types list

func GetDefaultType

func GetDefaultType() Type

GetDefaultType returns the default type

func GetKeyType

func GetKeyType(i string) Type

GetKeyType retrieves key type from user's input

Jump to

Keyboard shortcuts

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