gokystr

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: Unlicense Imports: 9 Imported by: 0

README

📦 Gokystr

Gokystr is a simple implementation of a filebased keystore for private keys.

On initialization the keystore reads the private keys from a folder and keeps them in memory.

Additional added keys can be written back to the file system, if enabled.

The ID for the key equals the filename minus the fileextension.

💻 Example

package main

import "github.com/abecodes/gokystr"

func main() {
	kystr, err := gokystr.New("/folder/with/keyfiles")

	// Retrieving a key
	prvKey, err := kystr.PrivateKey("keyname")
	pubKey, err := kystr.PublicKey("keyname")

	// Adding a key
	err := kystr.Add("keyname", *rsa.PrivateKey)

	// Removing a key
	err := kystr.Remove("keyid")
}

📋 Options

Option Info Default
AcceptEmpty If true, the keystore will not throw if the passed folder does not contain any keys false
NoWrite If true, additional added keys will not be written to the filesystem false
SetKeyExt Change the fileextension used to identify keyfiles .pem

Documentation

Overview

Package gokystr is a simple implementation of a keystore for private keys.

A new keystore instance is created of a folder on the filesystem. The keystore adds private keyfiles present in the folder on initialization automatically to the internal store, if they are parseable.

The name of the keyfile is it's internal ID.

By default private keys will be recognized via the fileextension ".pem".

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoSuchKey is thrown if a key with the given ID is not in the store
	ErrNoSuchKey = errors.New("no matching key found")
	// ErrKeyExistsAlready is thrown if a key already exists in the store
	ErrKeyExistsAlready = errors.New("key is already in the store")
	// ErrNoKeyFound is thrown if the dir contains no valid key file
	ErrNoKeyFound = errors.New("no valid keyfiles found in root")
	// ErrNotADir is thrown if the passed dir is not a directory path
	ErrNotADir = errors.New("passed path is not a dir")
	// ErrWrongExtFormat is thrown if the passed key extension does not match '.<ext>' format
	ErrWrongExtFormat = errors.New("key extension does not match '.<ext>' format")
	// ErrWrongDirFormat is thrown if the passed dir is not a valid path to open.
	// Path names must not contain an element that is “.” or “..” or the empty string,
	// except for the special case that the root directory is named “.”.
	// Paths must not start or end with a slash: “/x” and “x/” are invalid.
	ErrWrongDirFormat = errors.New("directory is not in a valid format")
)

Functions

func AcceptEmpty

func AcceptEmpty() option

AcceptEmpty prevents the keystore from throwing when using a empty dir

func NoWrite

func NoWrite() option

NoWrite will prevent the keystore from writing keyfiles

func SetKeyExt

func SetKeyExt(ext string) option

SetKeyExt changes the default "pem" extension used to identify keyfiles

Types

type Keystore

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

Keystore holds all private keys

func New

func New(dir string, options ...option) (*Keystore, error)

New returns a new keystore instance

func (*Keystore) Add

func (k *Keystore) Add(kid string, key *rsa.PrivateKey) error

Add appends a private key to the keystore

func (*Keystore) PrivateKey

func (k *Keystore) PrivateKey(kid string) (*rsa.PrivateKey, error)

PrivateKey returns the private key from the keystore

func (*Keystore) PublicKey

func (k *Keystore) PublicKey(kid string) (*rsa.PublicKey, error)

PublicKey returns the public key from the keystore

func (*Keystore) Remove

func (k *Keystore) Remove(kid string) error

Remove deletes a private key from the keystore

Jump to

Keyboard shortcuts

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