mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-27 13:39:04 +02:00
internal/cryptutil: fixed panic on nil pubkey
This commit is contained in:
parent
22fb3a0f7e
commit
c5bcc9bbef
5 changed files with 81 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
|||
// Package cryptutil provides encoding and decoding routines for various cryptographic structures.
|
||||
package cryptutil
|
||||
package cryptutil // import "github.com/pomerium/pomerium/internal/cryptutil"
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
|
@ -13,11 +13,9 @@ import (
|
|||
// DecodePublicKey decodes a PEM-encoded ECDSA public key.
|
||||
func DecodePublicKey(encodedKey []byte) (*ecdsa.PublicKey, error) {
|
||||
block, _ := pem.Decode(encodedKey)
|
||||
if block == nil || block.Type != "PUBLIC KEY" {
|
||||
return nil, fmt.Errorf("marshal: could not decode PEM block type %s", block.Type)
|
||||
|
||||
if block == nil {
|
||||
return nil, fmt.Errorf("marshal: decoded nil PEM block")
|
||||
}
|
||||
|
||||
pub, err := x509.ParsePKIXPublicKey(block.Bytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue