| 1 |
package fake |
| 2 |
|
| 3 |
import ( |
| 4 |
"crypto" |
| 5 |
_ "embed" |
| 6 |
"fmt" |
| 7 |
|
| 8 |
"github.com/golang-jwt/jwt/v4" |
| 9 |
) |
| 10 |
|
| 11 |
//go:embed signer_rsa |
| 12 |
var testPrivateKeyBytes []byte |
| 13 |
|
| 14 |
//go:embed signer_rsa.pub |
| 15 |
var testPublicKeyBytes []byte |
| 16 |
|
| 17 |
var testPrivateKey crypto.Signer |
| 18 |
var testPublicKey crypto.PublicKey |
| 19 |
|
| 20 |
func init() { |
| 21 |
var err error |
| 22 |
testPrivateKey, err = jwt.ParseRSAPrivateKeyFromPEM(testPrivateKeyBytes) |
| 23 |
if err != nil { |
| 24 |
panic(fmt.Sprintf("failed to parse embedded private key: %v", err)) |
| 25 |
} |
| 26 |
testPublicKey, err = jwt.ParseRSAPublicKeyFromPEM(testPublicKeyBytes) |
| 27 |
if err != nil { |
| 28 |
panic(fmt.Sprintf("failed to parse embedded public key: %v", err)) |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
// TestPrivateKey returns the fake private key used for signing. |
| 33 |
func TestPrivateKey() crypto.Signer { |
| 34 |
return testPrivateKey |
| 35 |
} |
| 36 |
|
| 37 |
// TestPublicKey returns the public key corresponding to the fake private key. |
| 38 |
func TestPublicKey() any { |
| 39 |
return testPublicKey |
| 40 |
} |