jws

package
v1.8.0 Latest Latest
Warning

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

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

Documentation

Overview

Package jws signs and verifies detached-payload JWS (RFC 7515) signatures. It is payload-agnostic: callers decide what bytes get signed. Like client/utils/cosign, it lives outside api/*, which is proto types and data-shape glue only, never crypto libraries or I/O.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PublicKeyFromJWK

func PublicKeyFromJWK(key jwk.Key) (crypto.PublicKey, bool)

PublicKeyFromJWK returns the signature-verification public key of key, skipping encryption-only keys and keys ToPublicKey rejects.

func Sign

func Sign(signer crypto.Signer, payload []byte) (string, error)

Sign produces a detached-payload JWS (RFC 7515) compact serialization over payload, using signer's own public key type to select the algorithm.

func ToPublicKey

func ToPublicKey(v any) (crypto.PublicKey, bool)

ToPublicKey returns v as a public key this package can verify with, or false for anything else (unsupported type, curve, or a too-small RSA key). Value-typed keys are returned as pointers.

func Verify

func Verify(jwsCompact string, payload []byte, keys ...crypto.PublicKey) error

Verify verifies a detached-payload JWS compact serialization signature over payload and succeeds if any of keys validates it. Each key's algorithm is derived from the key's own type (see jwsAlgorithmFor), not from the JWS's self-declared "alg" header. A key that can't be used (unsupported type) doesn't stop the remaining keys from being tried.

Types

type KeySigner

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

KeySigner signs with a PEM-encoded private key (EC, RSA, or Ed25519), optionally password-protected.

func NewKeySigner

func NewKeySigner(keyPEM, password []byte) (*KeySigner, error)

NewKeySigner loads a PEM-encoded private key (EC PRIVATE KEY, RSA PRIVATE KEY, PKCS8 PRIVATE KEY, or a password-protected ENCRYPTED PRIVATE KEY; the PKCS8 forms also cover Ed25519). password is only used for an encrypted key and is ignored otherwise; pass nil for an unencrypted key.

func (*KeySigner) Public

func (s *KeySigner) Public() crypto.PublicKey

func (*KeySigner) Sign

func (s *KeySigner) Sign(payload []byte) (string, error)

type Signer

type Signer interface {
	Sign(payload []byte) (jwsCompact string, err error)
	// Public returns the public key matching the signing key.
	Public() crypto.PublicKey
}

Signer produces a detached-payload JWS (RFC 7515) compact serialization over payload, using key material supplied at construction time.

Jump to

Keyboard shortcuts

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