func (c *Client) enrollCommon(ctx context.Context, r *x509.CertificateRequest, renew bool) (*x509.Certificate, error) {
	reqBody := ioutil.NopCloser(bytes.NewBuffer(base64Encode(r.Raw)))
	var endpoint = enrollEndpoint
	if renew {
		endpoint = reenrollEndpoint
	}
	req, err := c.newRequest(ctx, http.MethodPost, endpoint, mimeTypePKCS10, encodingTypeBase64, mimeTypePKCS7, reqBody)
	if err != nil {
		return nil, err
	}
	resp, err := c.makeHTTPClient().Do(req)
	if err != nil {
		return nil, fmt.Errorf("failed to execute HTTP request: %w", err)
	}
	defer consumeAndClose(resp.Body)
	if err := checkResponseError(resp); err != nil {
		return nil, err
	}
	if err := verifyResponseType(resp, mimeTypePKCS7, encodingTypeBase64); err != nil {
		return nil, err
	}
	return readCertResponse(resp.Body)
}
Enroll requests a new certificate.
package est
import (
	"bytes"
	"context"
	"crypto/tls"
	"crypto/x509"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"mime"
	"mime/multipart"
	"net/http"
	"strconv"
	"strings"
	"time"
)
type Client struct {
	Host string
	AdditionalPathSegment string
	ExplicitAnchor *x509.CertPool
	ImplicitAnchor *x509.CertPool
	Certificates []*x509.Certificate
	PrivateKey interface{}
	AdditionalHeaders map[string]string
	HostHeader string
	Username string
	Password string
	DisableKeepAlives bool
	InsecureSkipVerify bool
}
const (
	estVersion = "v1.0.6"
	userAgent  = "GlobalSign EST Client " + estVersion + " github.com/globalsign/est"
)
func (c *Client) CACerts(ctx context.Context) ([]*x509.Certificate, error) {
	req, err := c.newRequest(ctx, http.MethodGet, cacertsEndpoint, "", "", mimeTypePKCS7, nil)
	if err != nil {
		return nil, err
	}
	resp, err := c.makeHTTPClient().Do(req)
	if err != nil {
		return nil, fmt.Errorf("failed to execute HTTP request: %w", err)
	}
	defer consumeAndClose(resp.Body)
	if err := checkResponseError(resp); err != nil {
		return nil, err
	}
	if err := verifyResponseType(resp, mimeTypePKCS7, encodingTypeBase64); err != nil {
		return nil, err
	}
	return readCertsResponse(resp.Body)
}
func (c *Client) CSRAttrs(ctx context.Context) (CSRAttrs, error) {
	req, err := c.newRequest(ctx, http.MethodGet, csrattrsEndpoint, "", "", mimeTypeCSRAttrs, nil)
	if err != nil {
		return CSRAttrs{}, err
	}
	resp, err := c.makeHTTPClient().Do(req)
	if err != nil {
		return CSRAttrs{}, fmt.Errorf("failed to execute HTTP request: %w", err)
	}
	defer consumeAndClose(resp.Body)
	if err := checkResponseError(resp); err != nil {
		var estErr Error
		if errors.As(err, &estErr); estErr.StatusCode() == http.StatusNotFound ||
			estErr.StatusCode() == http.StatusNoContent {
			return CSRAttrs{}, nil
		}
		return CSRAttrs{}, err
	}
	if err := verifyResponseType(resp, mimeTypeCSRAttrs, encodingTypeBase64); err != nil {
		return CSRAttrs{}, err
	}
	return readCSRAttrsResponse(resp.Body)
}
func (c *Client) Enroll(ctx context.Context, r *x509.CertificateRequest) (*x509.Certificate, error) {
	return c.enrollCommon(ctx, r, false)
}
func (c *Client) Reenroll(ctx context.Context, r *x509.CertificateRequest) (*x509.Certificate, error) {
	return c.enrollCommon(ctx, r, true)
}