certlib: fix CSR FileKind, add test cases.

This commit is contained in:
2025-11-19 22:09:24 -08:00
parent 80b3376fa5
commit e9c7fec86f
6 changed files with 240 additions and 28 deletions

View File

@@ -171,6 +171,9 @@ func (ka KeyAlgo) String() string {
case x509.RSA:
return fmt.Sprintf("RSA-%d", ka.Size)
case x509.ECDSA:
if ka.curve == nil {
return fmt.Sprintf("ECDSA (unknown %d)", ka.Size)
}
return fmt.Sprintf("ECDSA-%s", ka.curve.Params().Name)
case x509.Ed25519:
return "Ed25519"
@@ -242,7 +245,7 @@ func publicKeyAlgoFromCert(cert *x509.Certificate) KeyAlgo {
}
func publicKeyAlgoFromCSR(csr *x509.CertificateRequest) KeyAlgo {
return publicKeyAlgoFromPublicKey(csr.PublicKeyAlgorithm)
return publicKeyAlgoFromPublicKey(csr.PublicKey)
}
type FileType struct {
@@ -273,7 +276,7 @@ func FileKind(path string) (*FileType, error) {
ft.Type = strings.ToLower(block.Type)
ft.Format = FormatPEM
}
cert, err := x509.ParseCertificate(data)
if err == nil {
ft.Algo = publicKeyAlgoFromCert(cert)