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
	}
}
