oauth2/internal: provide better error messaging if key parse fails

Change-Id: I4ad794fbcb58fa16e4f2bf7e113cab2451deab25
Reviewed-on: https://go-review.googlesource.com/5423
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Burcu Dogan 2015-02-20 17:01:46 -08:00
parent 5738e56ec6
commit a0fac97f6e
1 changed files with 2 additions and 2 deletions

View File

@ -30,12 +30,12 @@ func ParseKey(key []byte) (*rsa.PrivateKey, error) {
if err != nil { if err != nil {
parsedKey, err = x509.ParsePKCS1PrivateKey(key) parsedKey, err = x509.ParsePKCS1PrivateKey(key)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("private key should be a PEM or plain PKSC1 or PKCS8; parse error: %v", err)
} }
} }
parsed, ok := parsedKey.(*rsa.PrivateKey) parsed, ok := parsedKey.(*rsa.PrivateKey)
if !ok { if !ok {
return nil, errors.New("oauth2: private key is invalid") return nil, errors.New("private key is invalid")
} }
return parsed, nil return parsed, nil
} }