@@ -10,6 +10,7 @@ import (
10
10
"github.com/notaryproject/notation-go/plugin"
11
11
)
12
12
13
+ // builtInPluginMetaData is the builtin metadata used by builtinProvider.
13
14
var builtInPluginMetaData = plugin.Metadata {
14
15
SupportedContractVersions : []string {plugin .ContractVersion },
15
16
Capabilities : []plugin.Capability {plugin .CapabilitySignatureGenerator },
@@ -26,14 +27,14 @@ type provider interface {
26
27
SetConfig (map [string ]string )
27
28
}
28
29
29
- // builtinPlugin is a builtin provider implementation.
30
- //
30
+ // builtinProvider is a builtin provider implementation
31
+ // which wraps the signature.Signature to support builtin signing method.
31
32
// It only supports describe key and metadata command.
32
- // It wraps signature.Signature to support builtin signing method.
33
33
type builtinProvider struct {
34
34
signature.LocalSigner
35
35
}
36
36
37
+ // newBuiltinProvider creates a builtinProvider to support local signing.
37
38
func newBuiltinProvider (key crypto.PrivateKey , certChain []* x509.Certificate ) (provider , error ) {
38
39
builtinSigner , err := signature .NewLocalSigner (certChain , key )
39
40
if err != nil {
@@ -44,21 +45,20 @@ func newBuiltinProvider(key crypto.PrivateKey, certChain []*x509.Certificate) (p
44
45
}, nil
45
46
}
46
47
48
+ // metadata provides metadata for builtinProvider.
47
49
func (* builtinProvider ) metadata () * plugin.Metadata {
48
50
// The only properties that are really relevant
49
51
// are the supported contract version and the capabilities.
50
52
// All other are just filled with meaningful data.
51
53
return & builtInPluginMetaData
52
54
}
53
55
54
- // SetConfig set config when signing.
55
- func (* builtinProvider ) SetConfig (map [string ]string ) {
56
-
57
- }
56
+ // SetConfig sets config when signing.
57
+ func (* builtinProvider ) SetConfig (map [string ]string ) {}
58
58
59
- // Run implement the plugin workflow.
59
+ // Run implements the plugin workflow.
60
60
//
61
- // builtinProvider only support metadata and describe key.
61
+ // builtinProvider only supports metadata and describe key.
62
62
func (p * builtinProvider ) Run (_ context.Context , req plugin.Request ) (interface {}, error ) {
63
63
switch req .Command () {
64
64
case plugin .CommandGetMetadata :
@@ -75,10 +75,10 @@ func (p *builtinProvider) Run(_ context.Context, req plugin.Request) (interface{
75
75
}
76
76
}
77
77
78
- // externalProvider is a external provider implementation which will interact with plugin.
78
+ // externalProvider is an external provider implementation which will interact with plugin.
79
79
// It supports all plugin commands.
80
80
//
81
- // The detail implementation depends on the real plugin.
81
+ // The detail implementation depends on the underlying plugin.
82
82
//
83
83
// It wraps a signature.Signature to support external signing.
84
84
type externalProvider struct {
@@ -96,12 +96,12 @@ func newExternalProvider(runner plugin.Runner, keyID string) provider {
96
96
}
97
97
}
98
98
99
- // SetConfig setups config used by signing.
99
+ // SetConfig sets up config used by signing.
100
100
func (p * externalProvider ) SetConfig (cfg map [string ]string ) {
101
101
p .config = cfg
102
102
}
103
103
104
- // describeKey invokes plugin's DescribleKey command.
104
+ // describeKey invokes plugin's DescribeKey command.
105
105
func (p * externalProvider ) describeKey (ctx context.Context ) (* plugin.DescribeKeyResponse , error ) {
106
106
req := & plugin.DescribeKeyRequest {
107
107
ContractVersion : plugin .ContractVersion ,
@@ -119,7 +119,7 @@ func (p *externalProvider) describeKey(ctx context.Context) (*plugin.DescribeKey
119
119
return resp , nil
120
120
}
121
121
122
- // Sign sign the digest by calling the underlying plugin.
122
+ // Sign signs the digest by calling the underlying plugin.
123
123
func (p * externalProvider ) Sign (payload []byte ) ([]byte , []* x509.Certificate , error ) {
124
124
// Execute plugin sign command.
125
125
keySpec , err := p .KeySpec ()
@@ -157,7 +157,7 @@ func (p *externalProvider) Sign(payload []byte) ([]byte, []*x509.Certificate, er
157
157
return resp .Signature , certs , nil
158
158
}
159
159
160
- // KeySpec returns the keySpec of a keyID by calling describleKey and do some keySpec validation.
160
+ // KeySpec returns the keySpec of a keyID by calling describeKey and do some keySpec validation.
161
161
func (p * externalProvider ) KeySpec () (signature.KeySpec , error ) {
162
162
if p .keySpec != InvalidKeySpec {
163
163
return p .keySpec , nil
0 commit comments