Files
runesmith/integrity.go
DaanSelen 278ce30593
All checks were successful
Cross-Compile Binaries / cross-compile (push) Successful in 37s
chore: setup workflow
2025-11-25 16:47:06 +01:00

44 lines
958 B
Go

package main
import (
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rsa"
"crypto/x509"
"log"
)
func checkPublicKey(cert *x509.Certificate) {
switch pub := cert.PublicKey.(type) {
case *rsa.PublicKey:
log.Println("RSA key:", pub.N.BitLen(), "bits")
case *ecdsa.PublicKey:
log.Println("ECDSA key:", pub.Curve.Params().Name)
case ed25519.PublicKey:
log.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
}
}