jws

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidKey = errors.New("invalid JWK")

ErrInvalidKey is returned when passed JWK is invalid.

Functions

func GetED25519PublicKey

func GetED25519PublicKey(jwk *jws.JWK) (ed25519.PublicKey, error)

GetED25519PublicKey retunns ed25519 public key.

func IsCompactJWS

func IsCompactJWS(s string) bool

IsCompactJWS checks weather input is a compact JWS (based on https://tools.ietf.org/html/rfc7516#section-9)

func VerifySignature

func VerifySignature(jwk *jws.JWK, signature, msg []byte) error

VerifySignature verifies signature against public key in JWK format.

Types

type JSONWebSignature

type JSONWebSignature struct {
	ProtectedHeaders   jws.Headers
	UnprotectedHeaders jws.Headers
	Payload            []byte
	// contains filtered or unexported fields
}

JSONWebSignature defines JSON Web Signature (https://tools.ietf.org/html/rfc7515)

func NewJWS

func NewJWS(protectedHeaders, unprotectedHeaders jws.Headers, payload []byte, signer Signer) (*JSONWebSignature, error)

NewJWS creates JSON Web Signature.

func ParseJWS

func ParseJWS(jws string, opts ...ParseOpt) (*JSONWebSignature, error)

ParseJWS parses serialized JWS. Currently only JWS Compact Serialization parsing is supported.

func VerifyJWS added in v0.1.4

func VerifyJWS(jws string, jwk *jws.JWK, opts ...ParseOpt) (*JSONWebSignature, error)

VerifyJWS parses and validates serialized JWS. Currently only JWS Compact Serialization parsing is supported.

func (JSONWebSignature) SerializeCompact

func (s JSONWebSignature) SerializeCompact(detached bool) (string, error)

SerializeCompact makes JWS Compact Serialization (https://tools.ietf.org/html/rfc7515#section-7.1)

func (JSONWebSignature) Signature

func (s JSONWebSignature) Signature() []byte

Signature returns a copy of JWS signature.

type JWK

type JWK struct {
	jose.JSONWebKey

	Kty string
	Crv string
}

JWK (JSON Web Key) is a JSON data structure that represents a cryptographic key.

func (*JWK) MarshalJSON

func (j *JWK) MarshalJSON() ([]byte, error)

MarshalJSON serializes the given key to its JSON representation.

func (*JWK) PublicKeyBytes

func (j *JWK) PublicKeyBytes() ([]byte, error)

PublicKeyBytes converts a public key to bytes.

func (*JWK) UnmarshalJSON

func (j *JWK) UnmarshalJSON(jwkBytes []byte) error

UnmarshalJSON reads a key from its JSON representation.

type ParseOpt

type ParseOpt func(opts *jwsParseOpts)

ParseOpt is the JWS Parser option.

func WithJWSDetachedPayload

func WithJWSDetachedPayload(payload []byte) ParseOpt

WithJWSDetachedPayload option is for definition of JWS detached payload.

type Signer

type Signer interface {
	// Sign signs.
	Sign(data []byte) ([]byte, error)

	// Headers provides JWS headers. "alg" header must be provided (see https://tools.ietf.org/html/rfc7515#section-4.1)
	Headers() jws.Headers
}

Signer defines JWS Signer interface. It makes signing of data and provides custom JWS headers relevant to the signer.

Jump to

Keyboard shortcuts

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