keypairs/doc.go

41 lines
1.4 KiB
Go
Raw Normal View History

2019-02-21 00:10:42 +00:00
/*
Package keypairs complements Go's standard keypair-related packages
(encoding/pem, crypto/x509, crypto/rsa, crypto/ecdsa, crypto/elliptic)
with JWK encoding support and typesafe PrivateKey and PublicKey interfaces.
Basics
key, err := keypairs.ParsePrivateKey(bytesForJWKOrPEMOrDER)
pub, err := keypairs.ParsePublicKey(bytesForJWKOrPEMOrDER)
jwk, err := keypairs.MarshalJWKPublicKey(pub, time.Now().Add(2 * time.Day))
kid, err := keypairs.ThumbprintPublicKey(pub)
Convenience functions are available which will fetch keys
(or retrieve them from cache) via OIDC, .well-known/jwks.json, and direct urls.
All keys are cached by Thumbprint, as well as kid(@issuer), if available.
2020-05-10 18:34:01 +00:00
import "git.rootprojects.org/root/keypairs/keyfetch"
2019-02-21 00:10:42 +00:00
pubs, err := keyfetch.OIDCJWKs("https://example.com/")
2019-02-21 00:12:31 +00:00
pubs, err := keyfetch.OIDCJWK(ThumbOrKeyID, "https://example.com/")
2019-02-21 00:10:42 +00:00
pubs, err := keyfetch.WellKnownJWKs("https://example.com/")
2019-02-21 00:12:31 +00:00
pubs, err := keyfetch.WellKnownJWK(ThumbOrKeyID, "https://example.com/")
2019-02-21 00:10:42 +00:00
pubs, err := keyfetch.JWKs("https://example.com/path/to/jwks/")
2019-02-21 00:14:28 +00:00
pubs, err := keyfetch.JWK(ThumbOrKeyID, "https://example.com/path/to/jwks/")
2019-02-21 00:10:42 +00:00
2019-02-21 00:14:28 +00:00
// From URL
pub, err := keyfetch.Fetch("https://example.com/jwk.json")
// From Cache only
pub := keyfetch.Get(thumbprint, "https://example.com/jwk.json")
2019-02-21 00:10:42 +00:00
A non-caching version with the same capabilities is also available.
*/
package keypairs