github.com/letsencrypt/boulder@v0.20251208.0/mocks/ca.go (about)

     1  package mocks
     2  
     3  import (
     4  	"context"
     5  	"crypto/x509"
     6  	"encoding/pem"
     7  	"fmt"
     8  
     9  	"google.golang.org/grpc"
    10  
    11  	capb "github.com/letsencrypt/boulder/ca/proto"
    12  )
    13  
    14  // MockCA is a mock of a CA that always returns the cert from PEM in response to
    15  // IssueCertificate.
    16  type MockCA struct {
    17  	PEM []byte
    18  }
    19  
    20  // IssueCertificate is a mock
    21  func (ca *MockCA) IssueCertificate(ctx context.Context, req *capb.IssueCertificateRequest, _ ...grpc.CallOption) (*capb.IssueCertificateResponse, error) {
    22  	if ca.PEM == nil {
    23  		return nil, fmt.Errorf("MockCA's PEM field must be set before calling IssueCertificate")
    24  	}
    25  	block, _ := pem.Decode(ca.PEM)
    26  	sampleDER, err := x509.ParseCertificate(block.Bytes)
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  	return &capb.IssueCertificateResponse{DER: sampleDER.Raw}, nil
    31  }
    32  
    33  type MockCRLGenerator struct{}
    34  
    35  // GenerateCRL is a mock
    36  func (ca *MockCRLGenerator) GenerateCRL(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[capb.GenerateCRLRequest, capb.GenerateCRLResponse], error) {
    37  	return nil, nil
    38  }