func (e *EasyPKI) Revoke(caName string, cert *x509.Certificate) error {
	if err := e.Store.Update(caName, cert.SerialNumber, certificate.Revoked); err != nil {
		return fmt.Errorf("failed revoking certificate: %v", err)
	}
	return nil
}
Revoke revokes the given certificate from the store.
package easypki
import (
	"crypto/rand"
	"crypto/rsa"
	"crypto/x509"
	"errors"
	"fmt"
	"time"
	"github.com/google/easypki/pkg/certificate"
	"github.com/google/easypki/pkg/store"
)
const (
	defaultPrivateKeySize = 2048
)
var (
	ErrCannotSelfSignNonCA = errors.New("cannot self sign non CA request")
	ErrMaxPathLenReached   = errors.New("max path len reached")
)
type Request struct {
	Name                string
	IsClientCertificate bool
	PrivateKeySize      int
	Template            *x509.Certificate
}
type EasyPKI struct {
	Store store.Store
}
func (e *EasyPKI) GetCA(name string) (*certificate.Bundle, error) {
	return e.GetBundle(name, name)
}
func (e *EasyPKI) GetBundle(caName, name string) (*certificate.Bundle, error) {
	k, c, err := e.Store.Fetch(caName, name)
	if err != nil {
		return nil, fmt.Errorf("failed fetching bundle %v within CA %v: %v", name, caName, err)
	}
	return certificate.RawToBundle(name, k, c)
}
func (e *EasyPKI) Sign(signer *certificate.Bundle, req *Request) error {
	if !req.Template.IsCA && signer == nil {
		return ErrCannotSelfSignNonCA
	}
	if req.Template.IsCA && signer != nil && signer.Cert.MaxPathLen == 0 {
		return ErrMaxPathLenReached
	}
	if req.PrivateKeySize == 0 {
		req.PrivateKeySize = defaultPrivateKeySize
	}
	privateKey, err := rsa.GenerateKey(rand.Reader, req.PrivateKeySize)
	if err != nil {
		return fmt.Errorf("failed generating private key: %v", err)
	}
	publicKey := privateKey.Public()
	if err := defaultTemplate(req, publicKey); err != nil {
		return fmt.Errorf("failed updating generation request: %v", err)
	}
	if req.Template.IsCA {
		var intermediateCA bool
		if signer != nil {
			intermediateCA = true
			if signer.Cert.MaxPathLen > 0 {
				req.Template.MaxPathLen = signer.Cert.MaxPathLen - 1
			}
		}
		if err := caTemplate(req, intermediateCA); err != nil {
			return fmt.Errorf("failed updating generation request for CA: %v", err)
		}
		if !intermediateCA {
			signer = &certificate.Bundle{Name: req.Name, Cert: req.Template, Key: privateKey}
		}
	} else {
		nonCATemplate(req)
	}
	rawCert, err := x509.CreateCertificate(rand.Reader, req.Template, signer.Cert, publicKey, signer.Key)
	if err != nil {
		return fmt.Errorf("failed creating and signing certificate: %v", err)
	}
	if err := e.Store.Add(signer.Name, req.Name, req.Template.IsCA, x509.MarshalPKCS1PrivateKey(privateKey), rawCert); err != nil {
		return fmt.Errorf("failed saving generated bundle: %v", err)
	}
	return nil
}