Debian Codegraph @

example/signaturegenerator/plugin.go

raw symbols SCIP
1 // Copyright The Notary Project Authors.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package main
15
16 import (
17 "context"
18
19 "github.com/notaryproject/notation-plugin-framework-go/plugin"
20 )
21
22 type ExamplePlugin struct {
23 }
24
25 func NewExamplePlugin() (*ExamplePlugin, error) {
26 return &ExamplePlugin{}, nil
27 }
28
29 func (p *ExamplePlugin) DescribeKey(_ context.Context, req *plugin.DescribeKeyRequest) (*plugin.DescribeKeyResponse, error) {
30 return &plugin.DescribeKeyResponse{
31 KeyID: req.KeyID,
32 KeySpec: plugin.KeySpecRSA3072,
33 }, nil
34 }
35
36 func (p *ExamplePlugin) GenerateSignature(_ context.Context, req *plugin.GenerateSignatureRequest) (*plugin.GenerateSignatureResponse, error) {
37 return &plugin.GenerateSignatureResponse{
38 KeyID: req.KeyID,
39 Signature: []byte("generatedMockSignature"),
40 SigningAlgorithm: plugin.SignatureAlgorithmRSASSA_PSS_SHA384,
41 CertificateChain: [][]byte{[]byte("mockCert1"), []byte("mockCert2")},
42 }, nil
43 }
44
45 func (p *ExamplePlugin) GenerateEnvelope(_ context.Context, _ *plugin.GenerateEnvelopeRequest) (*plugin.GenerateEnvelopeResponse, error) {
46 return nil, plugin.NewUnsupportedError("GenerateSignature operation is not implemented by example plugin")
47 }
48
49 func (p *ExamplePlugin) VerifySignature(_ context.Context, req *plugin.VerifySignatureRequest) (*plugin.VerifySignatureResponse, error) {
50 upAttrs := req.Signature.UnprocessedAttributes
51 pAttrs := make([]interface{}, len(upAttrs))
52 for i := range upAttrs {
53 pAttrs[i] = upAttrs[i]
54 }
55
56 return &plugin.VerifySignatureResponse{
57 ProcessedAttributes: pAttrs,
58 VerificationResults: map[plugin.Capability]*plugin.VerificationResult{
59 plugin.CapabilityTrustedIdentityVerifier: {
60 Success: true,
61 Reason: "Valid trusted Identity",
62 },
63 plugin.CapabilityRevocationCheckVerifier: {
64 Success: true,
65 Reason: "Not revoked",
66 },
67 },
68 }, nil
69 }
70
71 func (p *ExamplePlugin) GetMetadata(_ context.Context, _ *plugin.GetMetadataRequest) (*plugin.GetMetadataResponse, error) {
72 return &plugin.GetMetadataResponse{
73 SupportedContractVersions: []string{plugin.ContractVersion},
74 Name: "com.example.plugin",
75 Description: "This is an description of example plugin",
76 URL: "https://example.com/notation/plugin",
77 Version: "1.0.0",
78 Capabilities: []plugin.Capability{
79 plugin.CapabilitySignatureGenerator,
80 plugin.CapabilityTrustedIdentityVerifier,
81 plugin.CapabilityRevocationCheckVerifier},
82 }, nil
83 }