crypto

package
v0.75.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package crypto describes the keys and algorithms that every source format has in common. Reading a container is left to the parser of that format.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoCanonicalForm = errors.New("key has no canonical form")

ErrNoCanonicalForm reports a key that cannot be reduced to SubjectPublicKeyInfo, such as the absent key of a certificate whose algorithm crypto/x509 does not recognize.

Functions

func DescribeAlgorithm

func DescribeAlgorithm(oid string, size int, curve string) ftypes.CryptoAssetInfo

DescribeAlgorithm describes the algorithm an OID identifies. The size and the curve belong to the key the algorithm is used with and are zero for a signature algorithm.

func DescribeEncryptedKey

func DescribeEncryptedKey(
	method ftypes.CryptoIdentityMethod,
	canonical []byte,
	format ftypes.CryptoKeyFormat,
) ftypes.CryptoAssetInfo

DescribeEncryptedKey describes an encrypted private key container. Its algorithm, size and curve live inside the encrypted payload and stay unset.

func DescribeKey

func DescribeKey(
	pub stdcrypto.PublicKey,
	keyType ftypes.CryptoKeyType,
) (key, keyAlgorithm ftypes.CryptoAssetInfo, err error)

DescribeKey describes a key and the algorithm it belongs to. A private key is described through its public projection, so it differs from a public key only in its key type.

A key that cannot be encoded is reported with ErrNoCanonicalForm. Any other error means the SubjectPublicKeyInfo produced here does not parse back, and the encoder is wrong.

func LinkKeyPairs

func LinkKeyPairs(assets []ftypes.CryptoAsset)

LinkKeyPairs points every private key at the public key derived from it, when both were found. A public key states nothing about the existence of a private one, so the reference runs in one direction only.

The two halves are told apart by the key type and share an identity, since a key is identified by the digest of its SubjectPublicKeyInfo. An encrypted container is left alone, because its identity is the digest of the container, which never equals the digest of a SubjectPublicKeyInfo.

func MarshalPublicKey

func MarshalPublicKey(pub stdcrypto.PublicKey) ([]byte, error)

MarshalPublicKey encodes a public key as PKIX SubjectPublicKeyInfo, the canonical form a key is identified by. A DSA key is encoded here, because crypto/x509 parses that form but cannot produce it.

Types

This section is empty.

Directories

Path Synopsis
parser

Jump to

Keyboard shortcuts

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