@@ -320,30 +320,27 @@ func extractECDSAPublicKey(pubKeyBytes []byte) (*ecdsa.PublicKey, error) {
320320 if block == nil {
321321 return nil , fmt .Errorf ("no PEM block found in Fulcio public key" )
322322 }
323+ var rawPub any
323324 switch block .Type {
324325 case "PUBLIC KEY" :
325326 result , err := x509 .ParsePKIXPublicKey (block .Bytes )
326327 if err != nil {
327328 return nil , fmt .Errorf ("failed to parse public key: %w" , err )
328329 }
329- // cast to ecdsa.PublicKey as we use this in the verification
330- pub , ok := result .(* ecdsa.PublicKey )
331- if ! ok {
332- return nil , fmt .Errorf ("unexpected public key type: %T" , result )
333- }
334- return pub , nil
330+ rawPub = result
335331 case "CERTIFICATE" :
336332 cert , err := x509 .ParseCertificate (block .Bytes )
337333 if err != nil {
338334 return nil , fmt .Errorf ("failed to parse Fulcio certificate: %w" , err )
339335 }
340- // cast to ecdsa.PublicKey as we use this in the verification
341- pub , ok := cert .PublicKey .(* ecdsa.PublicKey )
342- if ! ok {
343- return nil , fmt .Errorf ("unexpected certificate public key type: %T" , cert .PublicKey )
344- }
345- return pub , nil
336+ rawPub = cert .PublicKey
346337 default :
347338 return nil , fmt .Errorf ("unsupported PEM block type: %s" , block .Type )
348339 }
340+ // cast to ecdsa.PublicKey as we use this in the verification
341+ pubKey , ok := rawPub .(* ecdsa.PublicKey )
342+ if ! ok {
343+ return nil , fmt .Errorf ("unexpected public key type: %T" , rawPub )
344+ }
345+ return pubKey , nil
349346}
0 commit comments