...

Source file src/github.com/MicahParks/keyfunc/given.go

Documentation: github.com/MicahParks/keyfunc

     1  package keyfunc
     2  
     3  import (
     4  	"crypto/ecdsa"
     5  	"crypto/ed25519"
     6  	"crypto/rsa"
     7  )
     8  
     9  // GivenKey represents a cryptographic key that resides in a JWKS. In conjuncture with Options.
    10  type GivenKey struct {
    11  	inter interface{}
    12  }
    13  
    14  // NewGiven creates a JWKS from a map of given keys.
    15  func NewGiven(givenKeys map[string]GivenKey) (jwks *JWKS) {
    16  	keys := make(map[string]parsedJWK)
    17  
    18  	for kid, given := range givenKeys {
    19  		keys[kid] = parsedJWK{public: given.inter}
    20  	}
    21  
    22  	return &JWKS{
    23  		keys: keys,
    24  	}
    25  }
    26  
    27  // NewGivenCustom creates a new GivenKey given an untyped variable. The key argument is expected to be a supported
    28  // by the jwt package used.
    29  //
    30  // See the https://pkg.go.dev/github.com/golang-jwt/jwt/v4#RegisterSigningMethod function for registering an unsupported
    31  // signing method.
    32  func NewGivenCustom(key interface{}) (givenKey GivenKey) {
    33  	return GivenKey{
    34  		inter: key,
    35  	}
    36  }
    37  
    38  // NewGivenECDSA creates a new GivenKey given an ECDSA public key.
    39  func NewGivenECDSA(key *ecdsa.PublicKey) (givenKey GivenKey) {
    40  	return GivenKey{
    41  		inter: key,
    42  	}
    43  }
    44  
    45  // NewGivenEdDSA creates a new GivenKey given an EdDSA public key.
    46  func NewGivenEdDSA(key ed25519.PublicKey) (givenKey GivenKey) {
    47  	return GivenKey{
    48  		inter: key,
    49  	}
    50  }
    51  
    52  // NewGivenHMAC creates a new GivenKey given an HMAC key in a byte slice.
    53  func NewGivenHMAC(key []byte) (givenKey GivenKey) {
    54  	return GivenKey{
    55  		inter: key,
    56  	}
    57  }
    58  
    59  // NewGivenRSA creates a new GivenKey given an RSA public key.
    60  func NewGivenRSA(key *rsa.PublicKey) (givenKey GivenKey) {
    61  	return GivenKey{
    62  		inter: key,
    63  	}
    64  }
    65  

View as plain text