kms.go 882 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package kms
  2. import (
  3. "context"
  4. "strings"
  5. "github.com/pkg/errors"
  6. "github.com/smallstep/certificates/kms/apiv1"
  7. // Enable default implementation
  8. _ "github.com/smallstep/certificates/kms/softkms"
  9. )
  10. // KeyManager is the interface implemented by all the KMS.
  11. type KeyManager = apiv1.KeyManager
  12. // CertificateManager is the interface implemented by the KMS that can load and
  13. // store x509.Certificates.
  14. type CertificateManager = apiv1.CertificateManager
  15. // New initializes a new KMS from the given type.
  16. func New(ctx context.Context, opts apiv1.Options) (KeyManager, error) {
  17. if err := opts.Validate(); err != nil {
  18. return nil, err
  19. }
  20. t := apiv1.Type(strings.ToLower(opts.Type))
  21. if t == apiv1.DefaultKMS {
  22. t = apiv1.SoftKMS
  23. }
  24. fn, ok := apiv1.LoadKeyManagerNewFunc(t)
  25. if !ok {
  26. return nil, errors.Errorf("unsupported kms type '%s'", t)
  27. }
  28. return fn(ctx, opts)
  29. }