akp

package
v0.0.0-...-1788661 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package akp implements RFC 5958 Asymmetric Key Package.

Index

Constants

View Source
const (
	V1 = 0 // PublicKey is absent
	V2 = 1 // PublicKey is present
)

AKP version

Variables

View Source
var ErrSkip = errors.New("skip")

ErrSkip is returned by a packer or an unpacker, for a private key with an unrecognized type or a key package with an unrecognized algorithm OID, respectively.

View Source
var Pack = Packers.Pack

Pack packs a private/public key pair into a key package.

The public key is optional.

Options may be specific to the key type. They may affect the encoding and/or key attributes.

It returns the key pair package struct or an error. pkg != nil ⇔ err == nil.

View Source
var Packers packers

Packers is the global packer registry.

View Source
var Unpack = Unpackers.Unpack

Unpack unpacks a key package into a private/public key pair.

It returns the unpacked key pair or an error. The public key is returned only if present in the key package.

It may also return a slice of extra information.

View Source
var Unpackers unpackers

Unpackers is the global unpacker registry.

Functions

func Decode

func Decode(encoded []byte) (
	priv interface{}, pub interface{}, extras []interface{}, err error,
)

Decode decodes an ASN.1-encoded key package into a private/public key pair.

It returns the unpacked key pair or an error. The public key is returned only if present in the key package.

It may also return a slice of extra information.

func Encode

func Encode(
	priv interface{}, pub interface{}, options ...interface{},
) (encoded []byte, err error)

Encode encodes a private/public key pair into a ASN.1-encoded key package.

The public key is optional.

Options may be specific to the key type. They may affect the encoding and/or key attributes.

It returns the key pair package bytes or an error. encoded != nil ⇔ err == nil.

func Load

func Load(filename string) (
	priv interface{}, pub interface{}, extras []interface{}, err error,
)

Load loads a private/public key pair from the given file.

func Read

func Read(r io.Reader) (
	priv interface{}, pub interface{}, extras []interface{}, n int, err error,
)

Read reads a private/public key pair from the given reader.

func Save

func Save(
	filename string, priv interface{}, pub interface{}, options ...interface{},
) error

Save saves the given private/public key pair in a file.

func Write

func Write(
	w io.Writer, priv interface{}, pub interface{}, options ...interface{},
) (int, error)

Write writes a private/public key pair to the given writer.

Types

type AsymmetricKeyPackage

type AsymmetricKeyPackage []OneAsymmetricKey

AsymmetricKeyPackage contains one or more OneAsymmetricKey elements.

type Attribute

type Attribute struct {
	Type   asn1.ObjectIdentifier
	Values []asn1.RawValue `asn1:"set"`
}

Attribute is a PKIX-defined general-purpose attribute.

type OneAsymmetricKey

type OneAsymmetricKey struct {
	// Version is V2 if PublicKey is present, otherwise V1
	Version int

	// PrivateKeyAlgorithm is an algorithm OID and optional key pair parameters.
	PrivateKeyAlgorithm pkix.AlgorithmIdentifier

	// PrivateKey contains the value of the private key.
	// The interpretation is defined in the registration of the
	// PrivateKeyAlgorithm.
	PrivateKey []byte

	// Attributes contains information corresponding to the public key,
	// e.g. certificates.
	Attributes []Attribute `asn1:"optional,tag:0,set"`

	// PublicKey, when present, contains the public key.
	// The structure within the bit string depends on the private key algorithm.
	PublicKey asn1.BitString `asn1:"optional,tag:1"`
}

OneAsymmetricKey is one private key.

type Packer

type Packer interface {
	Pack(
		priv interface{}, pub interface{}, options ...interface{},
	) (pkg *OneAsymmetricKey, err error)
}

Packer packs a private/public key pair into a key package.

The public key is optional.

Options may be specific to the key type. They may affect the encoding and/or key attributes.

It returns the key pair package struct or an error. pkg != nil ⇔ err == nil.

type PrivateKeyInfo

type PrivateKeyInfo = OneAsymmetricKey

PrivateKeyInfo is the old (RFC 5208) name of OneAsymmetricKey.

type Unpacker

type Unpacker interface {
	Unpack(pkg *OneAsymmetricKey) (
		priv interface{}, pub interface{}, extras []interface{}, err error,
	)
}

Unpacker unpacks a key package into a private/public key pair.

It returns the unpacked key pair or an error. The public key is returned only if present in the key package.

It may also return a slice of extra information.

Jump to

Keyboard shortcuts

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