Documentation ¶
Overview ¶
Package akp implements RFC 5958 Asymmetric Key Package.
Index ¶
- Constants
- Variables
- func Decode(encoded []byte) (priv interface{}, pub interface{}, extras []interface{}, err error)
- func Encode(priv interface{}, pub interface{}, options ...interface{}) (encoded []byte, err error)
- func Load(filename string) (priv interface{}, pub interface{}, extras []interface{}, err error)
- func Read(r io.Reader) (priv interface{}, pub interface{}, extras []interface{}, n int, err error)
- func Save(filename string, priv interface{}, pub interface{}, options ...interface{}) error
- func Write(w io.Writer, priv interface{}, pub interface{}, options ...interface{}) (int, error)
- type AsymmetricKeyPackage
- type Attribute
- type OneAsymmetricKey
- type Packer
- type PrivateKeyInfo
- type Unpacker
Constants ¶
const ( V1 = 0 // PublicKey is absent V2 = 1 // PublicKey is present )
AKP version
Variables ¶
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.
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.
var Packers packers
Packers is the global packer registry.
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.
var Unpackers unpackers
Unpackers is the global unpacker registry.
Functions ¶
func Decode ¶
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 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.
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.