...

Source file src/github.com/golang-jwt/jwt/test/helpers.go

Documentation: github.com/golang-jwt/jwt/test

     1  package test
     2  
     3  import (
     4  	"crypto/rsa"
     5  	"io/ioutil"
     6  
     7  	"github.com/golang-jwt/jwt"
     8  )
     9  
    10  func LoadRSAPrivateKeyFromDisk(location string) *rsa.PrivateKey {
    11  	keyData, e := ioutil.ReadFile(location)
    12  	if e != nil {
    13  		panic(e.Error())
    14  	}
    15  	key, e := jwt.ParseRSAPrivateKeyFromPEM(keyData)
    16  	if e != nil {
    17  		panic(e.Error())
    18  	}
    19  	return key
    20  }
    21  
    22  func LoadRSAPublicKeyFromDisk(location string) *rsa.PublicKey {
    23  	keyData, e := ioutil.ReadFile(location)
    24  	if e != nil {
    25  		panic(e.Error())
    26  	}
    27  	key, e := jwt.ParseRSAPublicKeyFromPEM(keyData)
    28  	if e != nil {
    29  		panic(e.Error())
    30  	}
    31  	return key
    32  }
    33  
    34  func MakeSampleToken(c jwt.Claims, key interface{}) string {
    35  	token := jwt.NewWithClaims(jwt.SigningMethodRS256, c)
    36  	s, e := token.SignedString(key)
    37  
    38  	if e != nil {
    39  		panic(e.Error())
    40  	}
    41  
    42  	return s
    43  }
    44  

View as plain text