Files
runesmith/integrity.go

45 lines
965 B
Go
Raw Normal View History

2025-11-21 16:55:38 +01:00
package main
import (
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rsa"
"crypto/x509"
"fmt"
"log"
)
func checkPublicKey(cert *x509.Certificate) {
switch pub := cert.PublicKey.(type) {
case *rsa.PublicKey:
fmt.Println("RSA key:", pub.N.BitLen(), "bits")
case *ecdsa.PublicKey:
fmt.Println("ECDSA key:", pub.Curve.Params().Name)
case ed25519.PublicKey:
fmt.Println("Ed25519 key")
default:
log.Fatal("Unsupported public key type")
}
}
func checkCertKeyPair(certPub any, priv any) bool {
switch pub := certPub.(type) {
case *rsa.PublicKey:
privRSA, ok := priv.(*rsa.PrivateKey)
return ok && pub.N.Cmp(privRSA.N) == 0 && pub.E == privRSA.E
case *ecdsa.PublicKey:
privECDSA, ok := priv.(*ecdsa.PrivateKey)
return ok && pub.X.Cmp(privECDSA.X) == 0 && pub.Y.Cmp(privECDSA.Y) == 0
case ed25519.PublicKey:
privEd, ok := priv.(ed25519.PrivateKey)
return ok && pub.Equal(privEd.Public().(ed25519.PublicKey))
default:
return false
}
}