refactor: remove unused extractCertificates function and tests
This commit is contained in:
parent
bc0bc5fbbb
commit
37e20ae9a0
@ -25,7 +25,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -479,36 +478,4 @@ func (m *OCSPManager) GetStatus(serial string) (status OCSPStatus, hasResponse b
|
|||||||
return resp.status, len(resp.response) > 0
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
@ -308,32 +308,6 @@ func TestTLSManagerClose(t *testing.T) {
|
|||||||
manager.Close()
|
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) {
|
func TestOCSPManagerRegisterCertificate(t *testing.T) {
|
||||||
mgr := NewOCSPManager(nil)
|
mgr := NewOCSPManager(nil)
|
||||||
defer mgr.Stop()
|
defer mgr.Stop()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user