keygen

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: MIT Imports: 15 Imported by: 19

README

Keygen

Latest Release GoDoc Build Status Go ReportCard

An SSH key pair generator. Supports generating RSA and Ed25519 keys.

Example

k, err := NewSSHKeyPair(".ssh", "my_awesome_key", []byte(""), "ed25519")
if err != nil {
	fmt.Printf("error creating SSH key pair: %v", err)
	os.Exit(1)
}
if !k.KeyPairExist() {
	err = k.WriteKeys()
	if err != nil {
		fmt.Printf("error writing SSH key pair: %v", err)
		os.Exit(1)
	}
}

License

MIT


Part of Charm.

the Charm logo

Charm热爱开源 • Charm loves open source

Documentation

Overview

Package keygen handles the creation of new SSH key pairs.

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingSSHKeys = errors.New("missing one or more keys; did something happen to them after they were generated?")

ErrMissingSSHKeys indicates we're missing some keys that we expected to have after generating. This should be an extreme edge case.

Functions

This section is empty.

Types

type FilesystemErr

type FilesystemErr struct {
	Err error
}

FilesystemErr is used to signal there was a problem creating keys at the filesystem-level. For example, when we're unable to create a directory to store new SSH keys in.

func (FilesystemErr) Error

func (e FilesystemErr) Error() string

Error returns a human-readable string for the erorr. It implements the error interface.

func (FilesystemErr) Unwrap

func (e FilesystemErr) Unwrap() error

Unwrap returne the underlying error.

type SSHKeyPair

type SSHKeyPair struct {
	PrivateKeyPEM []byte
	PublicKey     []byte
	KeyDir        string
	Filename      string // private key filename; public key will have .pub appended
}

SSHKeyPair holds a pair of SSH keys and associated methods.

func NewSSHKeyPair

func NewSSHKeyPair(path string, name string, passphrase []byte, keyType string) (*SSHKeyPair, error)

NewSSHKeyPair generates an SSHKeyPair, which contains a pair of SSH keys. The keys are written to disk.

func (*SSHKeyPair) KeyPairExist

func (s *SSHKeyPair) KeyPairExist() bool

func (*SSHKeyPair) WriteKeys

func (s *SSHKeyPair) WriteKeys() error

WriteKeys writes the SSH key pair to disk.

type SSHKeysAlreadyExistErr

type SSHKeysAlreadyExistErr struct {
	Path string
}

SSHKeysAlreadyExistErr indicates that files already exist at the location at which we're attempting to create SSH keys.

func (SSHKeysAlreadyExistErr) Error

func (e SSHKeysAlreadyExistErr) Error() string

Error returns the a human-readable error message for SSHKeysAlreadyExistErr. It satisfies the error interface.

Jump to

Keyboard shortcuts

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