From 36ff8e18154488ae25515efdc263f4eb7761dff7 Mon Sep 17 00:00:00 2001 From: Sho KUSANO Date: Thu, 5 Nov 2026 09:33:20 +0900 Subject: [PATCH] feat: Supporting verification of a signature selected by label WithSignatureSelection makes Verify check only the signature named by WithLabel, so other signatures on the message don't affect the result. --- README.md | 16 ++ options.go | 34 ++++ options_test.go | 72 +++++++++ verification_policy.go | 2 + verifier.go | 64 ++++++-- verifier_test.go | 359 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 538 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 40f0e7c..aa11cb0 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,22 @@ verified, err := verifier.Verify(msg) // error handling goes here ``` +If your application picks the signature to check itself, for example because its protocol doesn't use tags, declare `WithSignatureSelection` and name the signature on each call with `WithLabel`. Only that signature is verified and the verifier's requirements apply to it. Other signatures don't affect the result, unless a `Signature-Input` or `Signature` field as a whole isn't valid Structured Fields. + +```go +verifier, err := httpsig.NewVerifier( + keyResolver, + httpsig.WithSignatureSelection(), + httpsig.WithComponents("@method", "@target-uri"), +) +// error handling goes here + +verified, err := verifier.Verify(msg, httpsig.WithLabel("sig1")) +// error handling goes here +``` + +`WithSignatureSelection` can't be combined with `WithValidateAllSignatures`, `WithRequiredTag`, or `WithSignatureNegotiation`. If the message has no signature with that label, `Verify` returns an error wrapping `NoApplicableSignatureError`. If `WithLabel` is missing, empty, or given more than once, or is used on a verifier without `WithSignatureSelection`, `Verify` returns an error wrapping `ErrParameter`. Labels aren't signed, so a label only chooses what to check and must not be treated as an identity or authorization claim. + Global verifier options act as defaults for required tags. Tag-specific options take precedence (for example, `WithComponents` replaces the global component list), while required, forbidden, and expected signature-parameter constraints are additive. Automatic signature negotiation uses these effective per-tag requirements. The same APIs also verify incoming requests and sign outgoing responses. Both `Signer.Sign` and `Verifier.Verify` operate on a `Message`, created for the corresponding HTTP direction: diff --git a/options.go b/options.go index c04a145..62d81d7 100644 --- a/options.go +++ b/options.go @@ -78,6 +78,8 @@ func (f verifierOptionFunc) applyVerifierOption(v *verifier, e *verificationPoli // WithLabel specifies the technical label for a signature or an // Accept-Signature request. An empty label leaves the current label unchanged. +// For Verify, it selects the signature to check; see WithSignatureSelection. +// There, an empty label is rejected. func WithLabel(label string) labelOption { return labelOption(label) } @@ -112,6 +114,24 @@ func (o labelOption) applySignatureNegotiationOption(opts *sigNegotiationOptions opts.opts = append(opts.opts, o) } +func (o labelOption) applyVerifyOption(policy *verificationPolicy) error { + if !policy.labelSelection { + return fmt.Errorf("%w: selecting a signature by label requires WithSignatureSelection", ErrParameter) + } + + if len(o) == 0 { + return fmt.Errorf("%w: signature label must not be empty", ErrParameter) + } + + if len(policy.selectedLabel) != 0 { + return fmt.Errorf("%w: signature label specified more than once", ErrParameter) + } + + policy.selectedLabel = string(o) + + return nil +} + // WithTTL specifies the interval between the created and expires signature // parameters. A non-positive duration omits expires. func WithTTL(ttl time.Duration) SignerOption { @@ -445,6 +465,20 @@ func WithValidateAllSignatures() VerifierOption { }) } +// WithSignatureSelection makes every Verify call check only the one signature +// chosen through WithLabel, which is then required on each call. The verifier's +// requirements apply to that signature and other signatures do not affect the +// result, except that the Signature-Input and Signature fields as a whole must +// be valid Structured Fields. It cannot be combined with WithValidateAllSignatures, +// WithRequiredTag, or WithSignatureNegotiation. +func WithSignatureSelection() VerifierOption { + return verifierOptionFunc(func(v *verifier, _ *verificationPolicy, _ bool) error { + v.signatureSelection = true + + return nil + }) +} + // WithCreatedTimestamp specifies whether the created parameter is required // during verification or requested in Accept-Signature. False makes it // optional during verification and omits it from Accept-Signature. diff --git a/options_test.go b/options_test.go index e5f2bb0..c25042b 100644 --- a/options_test.go +++ b/options_test.go @@ -830,6 +830,78 @@ func TestWithValidateAllSignatures(t *testing.T) { assert.True(t, v.validateAllSigs) } +func TestWithSignatureSelection(t *testing.T) { + t.Parallel() + + v := &verifier{} + + err := WithSignatureSelection().applyVerifierOption(v, &verificationPolicy{}, false) + + require.NoError(t, err) + assert.True(t, v.signatureSelection) + assert.False(t, v.validateAllSigs) +} + +func TestWithLabelForVerify(t *testing.T) { + t.Parallel() + + for uc, tc := range map[string]struct { + policy verificationPolicy + label string + assert func(t *testing.T, err error, policy *verificationPolicy) + }{ + "selects label": { + policy: verificationPolicy{labelSelection: true}, + label: "sig1", + assert: func(t *testing.T, err error, policy *verificationPolicy) { + t.Helper() + + require.NoError(t, err) + assert.Equal(t, "sig1", policy.selectedLabel) + }, + }, + "rejects empty label": { + policy: verificationPolicy{labelSelection: true}, + assert: func(t *testing.T, err error, _ *verificationPolicy) { + t.Helper() + + require.ErrorIs(t, err, ErrParameter) + require.ErrorContains(t, err, "must not be empty") + }, + }, + "rejects repeated label": { + policy: verificationPolicy{labelSelection: true, selectedLabel: "sig1"}, + label: "sig1", + assert: func(t *testing.T, err error, _ *verificationPolicy) { + t.Helper() + + require.ErrorIs(t, err, ErrParameter) + require.ErrorContains(t, err, "more than once") + }, + }, + "rejects verifier without signature selection": { + label: "sig1", + assert: func(t *testing.T, err error, policy *verificationPolicy) { + t.Helper() + + require.ErrorIs(t, err, ErrParameter) + require.ErrorContains(t, err, "WithSignatureSelection") + assert.Empty(t, policy.selectedLabel) + }, + }, + } { + t.Run(uc, func(t *testing.T) { + t.Parallel() + + policy := tc.policy + + err := WithLabel(tc.label).applyVerifyOption(&policy) + + tc.assert(t, err, &policy) + }) + } +} + func TestWithCreatedTimestampForVerifier(t *testing.T) { t.Parallel() diff --git a/verification_policy.go b/verification_policy.go index d5e77a3..a04a077 100644 --- a/verification_policy.go +++ b/verification_policy.go @@ -21,6 +21,8 @@ type verificationPolicy struct { requiredParameters []SignatureParameter forbiddenParameters []SignatureParameter expectedParameters []parameterOption + labelSelection bool + selectedLabel string } // clone copies the parameter slices for per-call options. Other fields are diff --git a/verifier.go b/verifier.go index 0240044..97ca9c7 100644 --- a/verifier.go +++ b/verifier.go @@ -52,11 +52,14 @@ type applicableSignature struct { } // NewVerifier creates a Verifier instance. -// Without WithValidateAllSignatures, at least one WithRequiredTag is necessary. +// Signatures must be selected through WithValidateAllSignatures, at least one +// WithRequiredTag, or WithSignatureSelection. The first two may be combined, +// while WithSignatureSelection excludes both. // By default, created and expires are required and signatures may be at most // 30 seconds old. Optional created or expires parameters are still checked // when present. Global WithSignatureNegotiation cannot be combined with -// WithValidateAllSignatures. More specific requirements can be set through opts. +// WithValidateAllSignatures or WithSignatureSelection. More specific requirements +// can be set through opts. // //nolint:cyclop func NewVerifier(resolver KeyResolver, opts ...VerifierOption) (Verifier, error) { @@ -81,7 +84,14 @@ func NewVerifier(resolver KeyResolver, opts ...VerifierOption) (Verifier, error) } } - if !ver.validateAllSigs && len(ver.tagPolicies) == 0 { + if ver.signatureSelection { + if ver.validateAllSigs || len(ver.tagPolicies) != 0 || globalPolicy.asb != nil { + return nil, fmt.Errorf("%w: signature selection cannot be combined with "+ + "validation of all signatures, required tags, or signature negotiation", ErrVerifierCreation) + } + + globalPolicy.labelSelection = true + } else if !ver.validateAllSigs && len(ver.tagPolicies) == 0 { return nil, fmt.Errorf("%w: validation of all signatures disabled, but no signature tags specified", ErrVerifierCreation) } @@ -97,7 +107,7 @@ func NewVerifier(resolver KeyResolver, opts ...VerifierOption) (Verifier, error) } } - if ver.validateAllSigs { + if ver.validateAllSigs || ver.signatureSelection { if err := globalPolicy.prepare(""); err != nil { return nil, fmt.Errorf("%w: %w", ErrVerifierCreation, err) } @@ -130,9 +140,10 @@ func newPayloadVerifier(verificationKey any, alg SignatureAlgorithm) (payloadVer } type verifier struct { - keyResolver KeyResolver - tagPolicies map[string]*verificationPolicy - validateAllSigs bool + keyResolver KeyResolver + tagPolicies map[string]*verificationPolicy + validateAllSigs bool + signatureSelection bool } func (v *verifier) Verify(msg *Message, opts ...VerifyOption) (VerificationResult, error) { @@ -141,7 +152,7 @@ func (v *verifier) Verify(msg *Message, opts ...VerifyOption) (VerificationResul return nil, fmt.Errorf("%w: %w", ErrVerificationFailed, err) } - sigRefs, err := getSignatureReferences(msg.Header.Values(headerSignatureInput)) + sigRefs, err := v.signatureReferences(msg, policiesByTag) if err != nil { return nil, fmt.Errorf("%w: %w", ErrVerificationFailed, err) } @@ -211,6 +222,37 @@ func (v *verifier) policiesForCall(opts []VerifyOption) (map[string]*verificatio return result, nil } +// signatureReferences returns the Signature-Input members to consider. With +// signature selection, only the selected member is kept, so a member the +// caller did not select cannot fail the call. Its absence yields an empty result. +func (v *verifier) signatureReferences( + msg *Message, + policiesByTag map[string]*verificationPolicy, +) (*httpsfv.Dictionary, error) { + values := msg.Header.Values(headerSignatureInput) + + if !v.signatureSelection { + return getSignatureReferences(values) + } + + label := policiesByTag[""].selectedLabel + if len(label) == 0 { + return nil, fmt.Errorf("%w: signature selection requires a label", ErrParameter) + } + + inputDict, err := httpsfv.UnmarshalDictionary(values) + if err != nil { + return nil, fmt.Errorf("%w: %w", ErrMalformedData, err) + } + + selected := httpsfv.NewDictionary() + if member, present := inputDict.Get(label); present { + selected.Add(label, member) + } + + return checkSignatureReferences(selected) +} + func (v *verifier) applicableSignatures(refs *httpsfv.Dictionary) ([]applicableSignature, error) { result := make([]applicableSignature, 0, len(refs.Names())) @@ -218,7 +260,7 @@ func (v *verifier) applicableSignatures(refs *httpsfv.Dictionary) ([]applicableS member, _ := refs.Get(label) list := member.(httpsfv.InnerList) //nolint:forcetypeassert - if !v.validateAllSigs { + if !v.validateAllSigs && !v.signatureSelection { tag, present := signatureTag(list) if !present { continue @@ -386,6 +428,10 @@ func getSignatureReferences(values []string) (*httpsfv.Dictionary, error) { return nil, fmt.Errorf("%w: %w", ErrMalformedData, err) } + return checkSignatureReferences(inputDict) +} + +func checkSignatureReferences(inputDict *httpsfv.Dictionary) (*httpsfv.Dictionary, error) { // Check member types without converting values that require semantic validation. for _, label := range inputDict.Names() { m, _ := inputDict.Get(label) diff --git a/verifier_test.go b/verifier_test.go index 4a05859..0581a44 100644 --- a/verifier_test.go +++ b/verifier_test.go @@ -98,6 +98,60 @@ func TestNewVerifier(t *testing.T) { require.ErrorContains(t, err, "validation of all signatures disabled, but no signature tags specified") }, }, + "with signature selection": { + resolver: &KeyResolverMock{}, + opts: []VerifierOption{WithSignatureSelection()}, + assert: func(t *testing.T, err error, v *verifier) { + t.Helper() + + require.NoError(t, err) + assert.True(t, v.signatureSelection) + assert.False(t, v.validateAllSigs) + require.Contains(t, v.tagPolicies, "") + assert.True(t, v.tagPolicies[""].labelSelection) + assert.Empty(t, v.tagPolicies[""].selectedLabel) + }, + }, + "with signature selection and validation of all signatures": { + resolver: &KeyResolverMock{}, + opts: []VerifierOption{WithSignatureSelection(), WithValidateAllSignatures()}, + assert: func(t *testing.T, err error, _ *verifier) { + t.Helper() + + require.ErrorIs(t, err, ErrVerifierCreation) + require.ErrorContains(t, err, "signature selection cannot be combined") + }, + }, + "with signature selection and required tag": { + resolver: &KeyResolverMock{}, + opts: []VerifierOption{WithRequiredTag("foo"), WithSignatureSelection()}, + assert: func(t *testing.T, err error, _ *verifier) { + t.Helper() + + require.ErrorIs(t, err, ErrVerifierCreation) + require.ErrorContains(t, err, "signature selection cannot be combined") + }, + }, + "with signature selection nested in required tag": { + resolver: &KeyResolverMock{}, + opts: []VerifierOption{WithRequiredTag("foo", WithSignatureSelection())}, + assert: func(t *testing.T, err error, _ *verifier) { + t.Helper() + + require.ErrorIs(t, err, ErrVerifierCreation) + require.ErrorContains(t, err, "signature selection cannot be combined") + }, + }, + "with signature selection and signature negotiation": { + resolver: &KeyResolverMock{}, + opts: []VerifierOption{WithSignatureSelection(), WithSignatureNegotiation()}, + assert: func(t *testing.T, err error, _ *verifier) { + t.Helper() + + require.ErrorIs(t, err, ErrVerifierCreation) + require.ErrorContains(t, err, "signature selection cannot be combined") + }, + }, "with component identifiers configuration error": { resolver: &KeyResolverMock{}, opts: []VerifierOption{ @@ -2067,6 +2121,311 @@ func TestVerifierVerify(t *testing.T) { }) } +func TestVerifierSignatureSelection(t *testing.T) { + block, _ := pem.Decode([]byte(testPubKeyEd25519)) + require.NotNil(t, block, "failed to parse PEM block containing the public key") + + key, err := x509.ParsePKIXPublicKey(block.Bytes) + require.NoError(t, err, "could not decode test public key") + + pubKey, ok := key.(ed25519.PublicKey) + require.True(t, ok) + + testURL, err := url.Parse("http://example.com/foo?param=Value&Pet=dog") + require.NoError(t, err) + + const ( + validInput = `sig-b26=("date" "@method" "@path" "@authority" "content-type" "content-length");` + + `created=1618884473;keyid="test-key-ed25519"` + validSignature = "sig-b26=:wqcAqbmYJ2ji2glfAMaRy4gruYYnx2nEFN2HN6jrnDnQCK1u02Gb04v9EDgwUPiu4A0w6vuQv5l" + + "Ip5WPpBKRCw==:" + ) + + newMessage := func(input, signature string) *Message { + return &Message{ + Method: http.MethodPost, + Authority: "example.com", + URL: testURL, + Header: http.Header{ + "Date": []string{"Tue, 20 Apr 2021 02:07:55 GMT"}, + "Content-Type": []string{"application/json"}, + "Content-Length": []string{"18"}, + "Signature-Input": []string{input}, + "Signature": []string{signature}, + }, + Context: t.Context(), + IsRequest: true, + } + } + + resolver := func(t *testing.T) *KeyResolverMock { + t.Helper() + + kr := NewKeyResolverMock(t) + kr.EXPECT().ResolveKey(mock.Anything, mock.MatchedBy(func(si SignatureInfo) bool { + return si.Label == "sig-b26" + })).Return(KeyInfo{ + Key: Key{Algorithm: Ed25519, Material: pubKey}, + }, nil).Once() + + return kr + } + + noResolver := func(t *testing.T) *KeyResolverMock { + t.Helper() + + return NewKeyResolverMock(t) + } + + for uc, tc := range map[string]struct { + opts []VerifierOption + verifyOpts []VerifyOption + msg *Message + resolver func(t *testing.T) *KeyResolverMock + assert func(t *testing.T, err error, results VerificationResult) + }{ + "verifies the selected signature": { + opts: []VerifierOption{WithExpiresTimestamp(false)}, + verifyOpts: []VerifyOption{WithLabel("sig-b26")}, + msg: newMessage(validInput, validSignature), + resolver: resolver, + assert: func(t *testing.T, err error, results VerificationResult) { + t.Helper() + + require.NoError(t, err) + require.Len(t, results, 1) + assert.Equal(t, "sig-b26", results[0].Label) + }, + }, + "ignores an unrelated invalid signature": { + opts: []VerifierOption{WithExpiresTimestamp(false)}, + verifyOpts: []VerifyOption{WithLabel("sig-b26")}, + msg: newMessage(validInput+`, proxy=("@method");created=1;keyid="unknown"`, + validSignature+", proxy=:AAAA:"), + resolver: resolver, + assert: func(t *testing.T, err error, results VerificationResult) { + t.Helper() + + require.NoError(t, err) + require.Len(t, results, 1) + assert.Equal(t, "sig-b26", results[0].Label) + }, + }, + "ignores an unrelated malformed signature input member": { + opts: []VerifierOption{WithExpiresTimestamp(false)}, + verifyOpts: []VerifyOption{WithLabel("sig-b26")}, + msg: newMessage(validInput+`, broken=();keyid=token, scalar=1`, + validSignature+`, scalar="not-a-signature"`), + resolver: resolver, + assert: func(t *testing.T, err error, results VerificationResult) { + t.Helper() + + require.NoError(t, err) + require.Len(t, results, 1) + assert.Equal(t, "sig-b26", results[0].Label) + }, + }, + "applies the verifier policy to a tagged signature": { + verifyOpts: []VerifyOption{WithLabel("sig")}, + msg: newMessage(`sig=("@method");tag="foo";keyid="k"`, "sig=:AAAA:"), + resolver: noResolver, + assert: func(t *testing.T, err error, _ VerificationResult) { + t.Helper() + + // The default policy requires created and expires. + require.ErrorIs(t, err, ErrVerificationFailed) + require.ErrorIs(t, err, &NoApplicableSignatureError{}) + }, + }, + "applies the verifier requirements": { + opts: []VerifierOption{WithExpiresTimestamp(false), WithComponents("x-missing")}, + verifyOpts: []VerifyOption{WithLabel("sig-b26")}, + msg: newMessage(validInput, validSignature), + resolver: noResolver, + assert: func(t *testing.T, err error, _ VerificationResult) { + t.Helper() + + require.ErrorIs(t, err, ErrVerificationFailed) + require.ErrorIs(t, err, &NoApplicableSignatureError{}) + }, + }, + "applies per-call requirements": { + opts: []VerifierOption{WithExpiresTimestamp(false)}, + verifyOpts: []VerifyOption{WithLabel("sig-b26"), WithRequiredParameters(Nonce)}, + msg: newMessage(validInput, validSignature), + resolver: noResolver, + assert: func(t *testing.T, err error, _ VerificationResult) { + t.Helper() + + require.ErrorIs(t, err, ErrVerificationFailed) + require.ErrorIs(t, err, ErrParameter) + }, + }, + "fails if the selected signature is invalid": { + opts: []VerifierOption{WithExpiresTimestamp(false)}, + verifyOpts: []VerifyOption{WithLabel("sig-b26")}, + msg: newMessage(validInput, "sig-b26=:AAAA:"), + resolver: resolver, + assert: func(t *testing.T, err error, results VerificationResult) { + t.Helper() + + require.ErrorIs(t, err, ErrVerificationFailed) + require.NotErrorIs(t, err, &NoApplicableSignatureError{}) + assert.Empty(t, results) + }, + }, + "fails if the selected member is malformed": { + verifyOpts: []VerifyOption{WithLabel("broken")}, + msg: newMessage(`broken=();keyid=token`, "broken=:AAAA:"), + resolver: noResolver, + assert: func(t *testing.T, err error, _ VerificationResult) { + t.Helper() + + require.ErrorIs(t, err, ErrVerificationFailed) + require.ErrorIs(t, err, ErrMalformedData) + }, + }, + "fails if the selected member is not an inner list": { + verifyOpts: []VerifyOption{WithLabel("scalar")}, + msg: newMessage(`scalar=1`, "scalar=:AAAA:"), + resolver: noResolver, + assert: func(t *testing.T, err error, _ VerificationResult) { + t.Helper() + + require.ErrorIs(t, err, ErrVerificationFailed) + require.ErrorIs(t, err, ErrMalformedData) + }, + }, + "fails if the signature value is missing": { + opts: []VerifierOption{WithExpiresTimestamp(false)}, + verifyOpts: []VerifyOption{WithLabel("sig-b26")}, + msg: newMessage(validInput, "other=:AAAA:"), + resolver: noResolver, + assert: func(t *testing.T, err error, _ VerificationResult) { + t.Helper() + + require.ErrorIs(t, err, ErrVerificationFailed) + require.ErrorIs(t, err, ErrMalformedData) + }, + }, + "fails if the field is not valid structured fields": { + verifyOpts: []VerifyOption{WithLabel("sig-b26")}, + msg: newMessage(validInput+`, (`, validSignature), + resolver: noResolver, + assert: func(t *testing.T, err error, _ VerificationResult) { + t.Helper() + + require.ErrorIs(t, err, ErrVerificationFailed) + require.ErrorIs(t, err, ErrMalformedData) + }, + }, + "no signature with the label": { + verifyOpts: []VerifyOption{WithLabel("other")}, + msg: newMessage(validInput, validSignature), + resolver: noResolver, + assert: func(t *testing.T, err error, _ VerificationResult) { + t.Helper() + + require.ErrorIs(t, err, ErrVerificationFailed) + require.ErrorIs(t, err, &NoApplicableSignatureError{}) + }, + }, + "without label": { + msg: newMessage(validInput, validSignature), + resolver: noResolver, + assert: func(t *testing.T, err error, _ VerificationResult) { + t.Helper() + + require.ErrorIs(t, err, ErrVerificationFailed) + require.ErrorIs(t, err, ErrParameter) + }, + }, + "without label but with other per-call options": { + verifyOpts: []VerifyOption{WithRequiredParameters(Nonce)}, + msg: newMessage(validInput, validSignature), + resolver: noResolver, + assert: func(t *testing.T, err error, _ VerificationResult) { + t.Helper() + + require.ErrorIs(t, err, ErrVerificationFailed) + require.ErrorIs(t, err, ErrParameter) + }, + }, + "with empty label": { + verifyOpts: []VerifyOption{WithLabel("")}, + msg: newMessage(validInput, validSignature), + resolver: noResolver, + assert: func(t *testing.T, err error, _ VerificationResult) { + t.Helper() + + require.ErrorIs(t, err, ErrVerificationFailed) + require.ErrorIs(t, err, ErrParameter) + }, + }, + "with label given more than once": { + verifyOpts: []VerifyOption{WithLabel("sig-b26"), WithLabel("sig-b26")}, + msg: newMessage(validInput, validSignature), + resolver: noResolver, + assert: func(t *testing.T, err error, _ VerificationResult) { + t.Helper() + + require.ErrorIs(t, err, ErrVerificationFailed) + require.ErrorIs(t, err, ErrParameter) + }, + }, + } { + t.Run(uc, func(t *testing.T) { + withRFC9421Time(t, func(t *testing.T) { + t.Helper() + + kr := tc.resolver(t) + + ver, err := NewVerifier(kr, append([]VerifierOption{WithSignatureSelection()}, tc.opts...)...) + require.NoError(t, err) + + results, err := ver.Verify(tc.msg, tc.verifyOpts...) + + tc.assert(t, err, results) + }) + }) + } + + t.Run("label is rejected without signature selection", func(t *testing.T) { + for uc, opts := range map[string][]VerifierOption{ + "validate all signatures": {WithValidateAllSignatures()}, + "required tag": {WithRequiredTag("foo")}, + } { + t.Run(uc, func(t *testing.T) { + ver, err := NewVerifier(NewKeyResolverMock(t), opts...) + require.NoError(t, err) + + _, err = ver.Verify(newMessage(validInput, validSignature), WithLabel("sig-b26")) + + require.ErrorIs(t, err, ErrVerificationFailed) + require.ErrorIs(t, err, ErrParameter) + }) + } + }) + + t.Run("label does not persist between calls", func(t *testing.T) { + withRFC9421Time(t, func(t *testing.T) { + t.Helper() + + ver, err := NewVerifier(resolver(t), WithSignatureSelection(), WithExpiresTimestamp(false)) + require.NoError(t, err) + + msg := newMessage(validInput, validSignature) + + results, err := ver.Verify(msg, WithLabel("sig-b26")) + require.NoError(t, err) + require.Len(t, results, 1) + + _, err = ver.Verify(msg) + require.ErrorIs(t, err, ErrParameter) + }) + }) +} + func TestSignatureTag(t *testing.T) { t.Parallel()