refactor: remove unused extractCertificates function and tests

This commit is contained in:
xfy 2026-06-03 13:51:55 +08:00
parent bc0bc5fbbb
commit 37e20ae9a0
2 changed files with 0 additions and 59 deletions

View File

@ -25,7 +25,6 @@ import (
"bytes"
"crypto"
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"io"
@ -479,36 +478,4 @@ func (m *OCSPManager) GetStatus(serial string) (status OCSPStatus, hasResponse b
return resp.status, len(resp.response) > 0
}
// extractCertificates 解析 PEM 数据并返回证书列表。
//
// 参数:
// - pemData: PEM 编码的证书数据
//
// 返回值:
// - []*x509.Certificate: 解析后的证书列表
// - error: 解析失败时返回错误
func extractCertificates(pemData []byte) ([]*x509.Certificate, error) {
var certs []*x509.Certificate
rest := pemData
for {
block, remaining := pem.Decode(rest)
if block == nil {
break
}
if block.Type == "CERTIFICATE" {
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return nil, fmt.Errorf("failed to parse certificate: %w", err)
}
certs = append(certs, cert)
}
rest = remaining
}
if len(certs) == 0 {
return nil, errors.New("no certificates found in PEM data")
}
return certs, nil
}

View File

@ -308,32 +308,6 @@ func TestTLSManagerClose(t *testing.T) {
manager.Close()
}
func TestExtractCertificates(t *testing.T) {
// Create valid PEM data
certPEM, _ := generateTestCertWithOCSP(t, nil)
certs, err := extractCertificates(certPEM)
if err != nil {
t.Fatalf("extractCertificates() failed: %v", err)
}
if len(certs) == 0 {
t.Error("Expected at least one certificate")
}
}
func TestExtractCertificatesInvalidPEM(t *testing.T) {
invalidPEM := []byte("not valid pem data")
certs, err := extractCertificates(invalidPEM)
if err == nil {
t.Error("Expected error for invalid PEM data")
}
if certs != nil {
t.Error("Expected nil certs for invalid PEM data")
}
}
func TestOCSPManagerRegisterCertificate(t *testing.T) {
mgr := NewOCSPManager(nil)
defer mgr.Stop()