File: kms.go

package info (click to toggle)
golang-github-smallstep-crypto 0.63.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,800 kB
  • sloc: sh: 66; makefile: 50
file content (56 lines) | stat: -rw-r--r-- 1,400 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package kms

import (
	"context"

	"github.com/pkg/errors"
	"go.step.sm/crypto/kms/apiv1"

	// Enable default implementation
	"go.step.sm/crypto/kms/softkms"
)

// KeyManager is the interface implemented by all the KMS.
type KeyManager = apiv1.KeyManager

// CertificateManager is the interface implemented by the KMS that can load and
// store x509.Certificates.
type CertificateManager = apiv1.CertificateManager

// Attester is the interface implemented by the KMS that can respond with an
// attestation certificate or key.
//
// # Experimental
//
// Notice: This API is EXPERIMENTAL and may be changed or removed in a later
// release.
type Attester = apiv1.Attester

// Options are the KMS options. They represent the kms object in the ca.json.
type Options = apiv1.Options

// Type represents the KMS type used.
type Type = apiv1.Type

// TypeOf returns the KMS type of the given uri.
var TypeOf = apiv1.TypeOf

// Default is the implementation of the default KMS.
var Default = &softkms.SoftKMS{}

// New initializes a new KMS from the given type.
func New(ctx context.Context, opts apiv1.Options) (KeyManager, error) {
	if err := opts.Validate(); err != nil {
		return nil, err
	}

	typ, err := opts.GetType()
	if err != nil {
		return nil, err
	}
	fn, ok := apiv1.LoadKeyManagerNewFunc(typ)
	if !ok {
		return nil, errors.Errorf("unsupported kms type '%s'", typ)
	}
	return fn(ctx, opts)
}