util

package
v0.0.0-...-de4bb62 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToPrivKey

func BytesToPrivKey(keyBytes []byte, kt KeyType) (crypto.PrivateKey, error)

BytesToPrivKey reconstructs a private key given some bytes and a target key type It is assumed the key was turned into byte form using the sibling method `PrivKeyToBytes`

func BytesToPubKey

func BytesToPubKey(keyBytes []byte, kt KeyType, opts ...Option) (crypto.PublicKey, error)

BytesToPubKey reconstructs a public key given some bytes and a target key type It is assumed the key was turned into byte form using the sibling method `PubKeyToBytes`

func Contains

func Contains(needle string, haystack []string) bool

func Copy

func Copy(src any, dst any) error

Copy makes a 1:1 copy of src into dst.

func GenerateEd25519Key

func GenerateEd25519Key() (ed25519.PublicKey, ed25519.PrivateKey, error)

func GenerateJWK

func GenerateJWK(eca jwa.EllipticCurveAlgorithm) (jwk.Key, error)

GenerateJWK creates a new JWK key pair for the given elliptic curve algorithm The key ID is set to the base64 URL-encoded SHA-256 thumbprint of the key.

func GenerateKeyByEllipticCurveAlgorithm

func GenerateKeyByEllipticCurveAlgorithm(eca jwa.EllipticCurveAlgorithm) (crypto.PublicKey, crypto.PrivateKey, error)

GenerateKeyByEllipticCurveAlgorithm creates a brand-new key, returning the public and private key for the given elliptic curve algorithm

func GenerateKeyByKeyType

func GenerateKeyByKeyType(kt KeyType) (crypto.PublicKey, crypto.PrivateKey, error)

GenerateKeyByKeyType creates a brand-new key, returning the public and private key for the given key type

func GenerateP224Key

func GenerateP224Key() (ecdsa.PublicKey, ecdsa.PrivateKey, error)

func GenerateP256Key

func GenerateP256Key() (ecdsa.PublicKey, ecdsa.PrivateKey, error)

func GenerateP384Key

func GenerateP384Key() (ecdsa.PublicKey, ecdsa.PrivateKey, error)

func GenerateP521Key

func GenerateP521Key() (ecdsa.PublicKey, ecdsa.PrivateKey, error)

func GenerateSECP256k1Key

func GenerateSECP256k1Key() (secp.PublicKey, secp.PrivateKey, error)

func GenerateX25519Key

func GenerateX25519Key() (x25519.PublicKey, x25519.PrivateKey, error)

func IsSupportedKeyType

func IsSupportedKeyType(kt KeyType) bool

IsSupportedKeyType returns true if the key type is supported

func IsValidStruct

func IsValidStruct(data any) error

func NewValidator

func NewValidator() *validator.Validate

func PrettyJSON

func PrettyJSON(data any) ([]byte, error)

PrettyJSON JSON-ifies data in a 'pretty-print' fashion

func PrivKeyToBytes

func PrivKeyToBytes(key crypto.PrivateKey) ([]byte, error)

PrivKeyToBytes constructs a byte representation of a private key, for a set number of supported key types

func PubKeyToBytes

func PubKeyToBytes(key crypto.PublicKey, opts ...Option) ([]byte, error)

PubKeyToBytes constructs a byte representation of a public key, for a set number of supported key types

func SECP256k1ECDSAPubKeyToSECP256k1

func SECP256k1ECDSAPubKeyToSECP256k1(key ecdsa.PublicKey) secp.PublicKey

SECP256k1ECDSAPubKeyToSECP256k1 converts an ecdsa.PublicKey to a secp.PublicKey

func SECP256k1ECDSASPrivKeyToSECP256k1

func SECP256k1ECDSASPrivKeyToSECP256k1(key ecdsa.PrivateKey) secp.PrivateKey

SECP256k1ECDSASPrivKeyToSECP256k1 converts an ecdsa.PrivateKey to a secp.PrivateKey

Types

type HashType

type HashType string

type KeyType

type KeyType string
const (
	Ed25519        KeyType = "Ed25519"
	X25519         KeyType = "X25519"
	SECP256k1      KeyType = "secp256k1"
	SECP256k1ECDSA KeyType = "secp256k1-ECDSA"
	P224           KeyType = "P-224"
	P256           KeyType = "P-256"
	P384           KeyType = "P-384"
	P521           KeyType = "P-521"
)

func GetKeyTypeFromPrivateKey

func GetKeyTypeFromPrivateKey(key crypto.PrivateKey) (KeyType, error)

GetKeyTypeFromPrivateKey returns the key type for a private key for known key types

func GetSupportedJWKKeyTypes

func GetSupportedJWKKeyTypes() []KeyType

GetSupportedJWKKeyTypes returns a list of supported JWK key types RSA, secp256k1, and P-224 are not supported by the lib we use for JWK

func GetSupportedKeyTypes

func GetSupportedKeyTypes() []KeyType

GetSupportedKeyTypes returns a list of supported key types

func (KeyType) String

func (kt KeyType) String() string

type Option

type Option int
const (
	ECDSAMarshalCompressed Option = iota
	ECDSAUnmarshalCompressed
)

type Proof

type Proof any

type SignatureAlgorithm

type SignatureAlgorithm string

type SingleOrArray

type SingleOrArray[T any] []T

SingleOrArray represents a value that can be either a single item or an array of items

func (SingleOrArray[T]) MarshalJSON

func (sa SingleOrArray[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements custom marshaling for SingleOrArray

func (*SingleOrArray[T]) UnmarshalJSON

func (sa *SingleOrArray[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom unmarshaling for SingleOrArray

Jump to

Keyboard shortcuts

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