package engine

import (
	"crypto"
	"crypto/ecdsa"
	"crypto/ed25519"
	"crypto/rsa"
)

// ZeroizeKey overwrites an asymmetric private key's sensitive material.
func ZeroizeKey(key crypto.PrivateKey) {
	if key == nil {
		return
	}
	switch k := key.(type) {
	case *ecdsa.PrivateKey:
		k.D.SetInt64(0)
	case *rsa.PrivateKey:
		k.D.SetInt64(0)
		for _, p := range k.Primes {
			p.SetInt64(0)
		}
	case ed25519.PrivateKey:
		for i := range k {
			k[i] = 0
		}
	}
}
