remove duplicate method

This commit is contained in:
Livio Amstutz 2021-08-20 07:40:06 +02:00
parent 807da0b27d
commit 5715d1528f

View file

@ -1,10 +1,7 @@
package oidc package oidc
import ( import (
"crypto/rsa"
"crypto/x509"
"encoding/json" "encoding/json"
"encoding/pem"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"time" "time"
@ -590,7 +587,7 @@ func AppendClientIDToAudience(clientID string, audience []string) []string {
} }
func GenerateJWTProfileToken(assertion JWTProfileAssertionClaims) (string, error) { func GenerateJWTProfileToken(assertion JWTProfileAssertionClaims) (string, error) {
privateKey, err := bytesToPrivateKey(assertion.GetPrivateKey()) privateKey, err := utils.BytesToPrivateKey(assertion.GetPrivateKey())
if err != nil { if err != nil {
return "", err return "", err
} }
@ -613,21 +610,3 @@ func GenerateJWTProfileToken(assertion JWTProfileAssertionClaims) (string, error
} }
return signedAssertion.CompactSerialize() return signedAssertion.CompactSerialize()
} }
func bytesToPrivateKey(priv []byte) (*rsa.PrivateKey, error) {
block, _ := pem.Decode(priv)
enc := x509.IsEncryptedPEMBlock(block)
b := block.Bytes
var err error
if enc {
b, err = x509.DecryptPEMBlock(block, nil)
if err != nil {
return nil, err
}
}
key, err := x509.ParsePKCS1PrivateKey(b)
if err != nil {
return nil, err
}
return key, nil
}