x509

package
v0.0.0-...-d4b7e32 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

package x509 implements Public Key Infrastructure X.509 formats.

Index

Constants

This section is empty.

Variables

View Source
var (
	// https://www.rfc-editor.org/rfc/rfc8410#section-3
	Algo_Ed25519 = oids.New(1, 3, 101, 112)
	Algo_Ed448   = oids.New(1, 3, 101, 113)
)

Functions

func EqualPublicKeys

func EqualPublicKeys(a, b *PublicKey) bool

EqualPublicKeys returns true if a and b are equal.

func MarshalPrivateKey

func MarshalPrivateKey(out []byte, x *PrivateKey) []byte

MarshalPrivateKey appends the marshalled bytes of x to out and returns the result.

func MarshalPublicKey

func MarshalPublicKey(out []byte, x *PublicKey) []byte

MarshalPublicKey appends the marshalled bytes of x to out and returns the result.

func ToStandardSigner

func ToStandardSigner(x *PrivateKey) (crypto.Signer, error)

Types

type Codec

type Codec struct {
	ParsePublic   func([]byte) (Verifier, error)
	MarshalPublic func(out []byte, v Verifier) []byte

	ParsePrivate   func([]byte) (Signer, error)
	MarshalPrivate func(out []byte, s Signer) []byte
}

A Codec contains functions for Parsing and Marshaling Verifiers and Signers

func NewCodec

func NewCodec[Private, Public any](sch sign.Scheme[Private, Public]) Codec

NewCodec returns a Codec for a signing scheme.

type ErrUnrecognizedAlgo

type ErrUnrecognizedAlgo struct {
	AlgorithmID oids.OID
}

func (ErrUnrecognizedAlgo) Error

func (e ErrUnrecognizedAlgo) Error() string

type PrivateKey

type PrivateKey struct {
	Algorithm oids.OID
	Data      []byte
}

func ParsePrivateKey

func ParsePrivateKey(input []byte) (PrivateKey, error)

ParsePrivateKey attempts to parse a PrivateKey from input, and returns the PrivateKey or an error.

func (*PrivateKey) IsZero

func (priv *PrivateKey) IsZero() bool

type PublicKey

type PublicKey struct {
	Algorithm oids.OID
	Data      []byte
}

PublicKey is an AlgorithmID and a marshaled public key

func ParsePublicKey

func ParsePublicKey(input []byte) (PublicKey, error)

ParsePublicKey attempts to parse a PublicKey from input, and returns the PublicKey or an error.

func (*PublicKey) IsZero

func (pub *PublicKey) IsZero() bool

type Registry

type Registry map[oids.OID]Codec

Registry mananges parsing Verifiers and Signers for a given set of algorithms.

func DefaultRegistry

func DefaultRegistry() Registry

func (Registry) LoadSigner

func (r Registry) LoadSigner(pk *PrivateKey) (Signer, error)

func (Registry) LoadVerifier

func (r Registry) LoadVerifier(pk *PublicKey) (Verifier, error)

func (Registry) ParseVerifier

func (r Registry) ParseVerifier(data []byte) (Verifier, error)

func (Registry) PublicFromPrivate

func (r Registry) PublicFromPrivate(private *PrivateKey) (ret PublicKey, _ error)

func (Registry) StoreSigner

func (r Registry) StoreSigner(algoID oids.OID, s Signer) (PrivateKey, error)

func (Registry) StoreVerifier

func (r Registry) StoreVerifier(algoID oids.OID, v Verifier) (PublicKey, error)

type Signer

type Signer interface {
	// Sign appends a signature for msg to out, and returns out, or an error
	Sign(out []byte, msg []byte) ([]byte, error)
	Verifier() Verifier
}

Signer contains the Sign method

func NewSigner

func NewSigner[Private, Public any](sch sign.Scheme[Private, Public], priv *Private) Signer

NewSigner returns a Signer from a sign.Scheme and a private key

func SignerFromStandard

func SignerFromStandard(x crypto.Signer) (oids.OID, Signer)

SignerFromStandard returns a Signer and oids.OID for a standard library crypto.Signer If the algorithm is not supported it returns the zero value for both

type Verifier

type Verifier interface {
	Verify(msg, sig []byte) bool
}

Verifier contains the verify method

func NewVerifier

func NewVerifier[Private, Public any](sch sign.Scheme[Private, Public], pub *Public) Verifier

NewVerifier creates a Verifier from a sign.Scheme and a public key

func VerifierFromStandard

func VerifierFromStandard(x crypto.PublicKey) (oids.OID, Verifier)

VerifierFromStandard returns a Verifier and oids.OID for a standard library crypto.PublicKey If the algorithm is not supported it returns the zero value for both

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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