12
12
// limitations under the License.
13
13
14
14
// Package notation provides signer and verifier for notation Sign
15
- // and Verification.
15
+ // and Verification. It supports both OCI artifact and arbitrary blob.
16
16
package notation
17
17
18
18
import (
@@ -48,7 +48,7 @@ var errDoneVerification = errors.New("done verification")
48
48
49
49
var reservedAnnotationPrefixes = [... ]string {"io.cncf.notary" }
50
50
51
- // SignerSignOptions contains parameters for Signer.Sign .
51
+ // SignerSignOptions contains parameters for [ Signer] and [BlobSigner] .
52
52
type SignerSignOptions struct {
53
53
// SignatureMediaType is the envelope type of the signature.
54
54
// Currently, both `application/jose+json` and `application/cose` are
@@ -86,18 +86,21 @@ type Signer interface {
86
86
Sign (ctx context.Context , desc ocispec.Descriptor , opts SignerSignOptions ) ([]byte , * signature.SignerInfo , error )
87
87
}
88
88
89
- // SignBlobOptions contains parameters for notation.SignBlob.
89
+ // SignBlobOptions contains parameters for [ notation.SignBlob] .
90
90
type SignBlobOptions struct {
91
91
SignerSignOptions
92
+
92
93
// ContentMediaType is the media-type of the blob being signed.
93
94
ContentMediaType string
95
+
94
96
// UserMetadata contains key-value pairs that are added to the signature
95
97
// payload
96
98
UserMetadata map [string ]string
97
99
}
98
100
99
101
// BlobDescriptorGenerator creates descriptor using the digest Algorithm.
100
- // Below is the example of minimal descriptor, it must contain mediatype, digest and size of the artifact
102
+ // Below is the example of minimal descriptor, it must contain mediatype,
103
+ // digest and size of the artifact.
101
104
//
102
105
// {
103
106
// "mediaType": "application/octet-stream",
@@ -110,8 +113,8 @@ type BlobDescriptorGenerator func(digest.Algorithm) (ocispec.Descriptor, error)
110
113
// The interface allows signing with local or remote keys,
111
114
// and packing in various signature formats.
112
115
type BlobSigner interface {
113
- // SignBlob signs the descriptor returned by genDesc ,
114
- // and returns the signature and SignerInfo
116
+ // SignBlob signs the descriptor returned by genDesc, and returns the
117
+ // signature and SignerInfo.
115
118
SignBlob (ctx context.Context , genDesc BlobDescriptorGenerator , opts SignerSignOptions ) ([]byte , * signature.SignerInfo , error )
116
119
}
117
120
@@ -122,7 +125,7 @@ type signerAnnotation interface {
122
125
PluginAnnotations () map [string ]string
123
126
}
124
127
125
- // SignOptions contains parameters for notation.Sign.
128
+ // SignOptions contains parameters for [ notation.Sign] .
126
129
type SignOptions struct {
127
130
SignerSignOptions
128
131
@@ -200,7 +203,8 @@ func Sign(ctx context.Context, signer Signer, repo registry.Repository, signOpts
200
203
return targetDesc , nil
201
204
}
202
205
203
- // SignBlob signs the arbitrary data and returns the signature
206
+ // SignBlob signs the arbitrary data from blobReader and returns
207
+ // the signature and SignerInfo.
204
208
func SignBlob (ctx context.Context , signer BlobSigner , blobReader io.Reader , signBlobOpts SignBlobOptions ) ([]byte , * signature.SignerInfo , error ) {
205
209
// sanity checks
206
210
if err := validateSignArguments (signer , signBlobOpts .SignerSignOptions ); err != nil {
@@ -325,7 +329,8 @@ func (outcome *VerificationOutcome) UserMetadata() (map[string]string, error) {
325
329
return payload .TargetArtifact .Annotations , nil
326
330
}
327
331
328
- // VerifierVerifyOptions contains parameters for Verifier.Verify used for verifying OCI artifact.
332
+ // VerifierVerifyOptions contains parameters for [Verifier.Verify] used for
333
+ // verifying OCI artifact.
329
334
type VerifierVerifyOptions struct {
330
335
// ArtifactReference is the reference of the artifact that is being
331
336
// verified against to. It must be a full reference.
@@ -344,17 +349,17 @@ type VerifierVerifyOptions struct {
344
349
UserMetadata map [string ]string
345
350
}
346
351
347
- // Verifier is a interface for verifying an OCI artifact.
352
+ // Verifier is a generic interface for verifying an OCI artifact.
348
353
type Verifier interface {
349
354
// Verify verifies the `signature` associated with the target OCI artifact
350
- //with manifest descriptor `desc`, and returns the outcome upon
355
+ // with manifest descriptor `desc`, and returns the outcome upon
351
356
// successful verification.
352
357
// If nil signature is present and the verification level is not 'skip',
353
358
// an error will be returned.
354
359
Verify (ctx context.Context , desc ocispec.Descriptor , signature []byte , opts VerifierVerifyOptions ) (* VerificationOutcome , error )
355
360
}
356
361
357
- // BlobVerifierVerifyOptions contains parameters for BlobVerifier.Verify.
362
+ // BlobVerifierVerifyOptions contains parameters for [ BlobVerifier.Verify] .
358
363
type BlobVerifierVerifyOptions struct {
359
364
// SignatureMediaType is the envelope type of the signature.
360
365
// Currently only `application/jose+json` and `application/cose` are
@@ -375,7 +380,7 @@ type BlobVerifierVerifyOptions struct {
375
380
376
381
// BlobVerifier is a generic interface for verifying a blob.
377
382
type BlobVerifier interface {
378
- // VerifyBlob verifies the `signature` against the target artifact using the
383
+ // VerifyBlob verifies the `signature` against the target blob using the
379
384
// descriptor returned by descGenFunc parameter and
380
385
// returns the outcome upon successful verification.
381
386
VerifyBlob (ctx context.Context , descGenFunc BlobDescriptorGenerator , signature []byte , opts BlobVerifierVerifyOptions ) (* VerificationOutcome , error )
@@ -386,7 +391,7 @@ type verifySkipper interface {
386
391
SkipVerify (ctx context.Context , opts VerifierVerifyOptions ) (bool , * trustpolicy.VerificationLevel , error )
387
392
}
388
393
389
- // VerifyOptions contains parameters for notation.Verify.
394
+ // VerifyOptions contains parameters for [ notation.Verify] .
390
395
type VerifyOptions struct {
391
396
// ArtifactReference is the reference of the artifact that is being
392
397
// verified against to.
@@ -405,7 +410,7 @@ type VerifyOptions struct {
405
410
UserMetadata map [string ]string
406
411
}
407
412
408
- // VerifyBlobOptions contains parameters for notation.VerifyBlob.
413
+ // VerifyBlobOptions contains parameters for [ notation.VerifyBlob] .
409
414
type VerifyBlobOptions struct {
410
415
BlobVerifierVerifyOptions
411
416
@@ -414,9 +419,9 @@ type VerifyBlobOptions struct {
414
419
}
415
420
416
421
// VerifyBlob performs signature verification for a blob using notation supported
417
- // verification types (like integrity, authenticity, etc.) and return the
418
- // successful signature verification outcome. The blob is read using blobReader and
419
- // upon successful verification, it returns the descriptor of the blob.
422
+ // verification types (like integrity, authenticity, etc.) and returns the
423
+ // successful signature verification outcome. The blob is read using blobReader,
424
+ // and upon successful verification, it returns the descriptor of the blob.
420
425
// For more details on signature verification, see
421
426
// https://github.com/notaryproject/notaryproject/blob/main/specs/trust-store-trust-policy.md#signature-verification
422
427
func VerifyBlob (ctx context.Context , blobVerifier BlobVerifier , blobReader io.Reader , signature []byte , verifyBlobOpts VerifyBlobOptions ) (ocispec.Descriptor , * VerificationOutcome , error ) {
0 commit comments