Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Signer interface in EnvelopeSigner #57

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions dsse/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,19 @@ var ErrNoSigners = errors.New("no signers provided")

// EnvelopeSigner creates signed Envelopes.
type EnvelopeSigner struct {
providers []SignerVerifier
providers []Signer
}

/*
NewEnvelopeSigner creates an EnvelopeSigner that uses 1+ Signer algorithms to
sign the data. Creates a verifier with threshold=1, at least one of the
providers must validate signatures successfully.
sign the data.
*/
func NewEnvelopeSigner(p ...SignerVerifier) (*EnvelopeSigner, error) {
return NewMultiEnvelopeSigner(1, p...)
}

/*
NewMultiEnvelopeSigner creates an EnvelopeSigner that uses 1+ Signer
algorithms to sign the data. Creates a verifier with threshold. Threshold
indicates the amount of providers that must validate the envelope.
*/
func NewMultiEnvelopeSigner(threshold int, p ...SignerVerifier) (*EnvelopeSigner, error) {
adityasaky marked this conversation as resolved.
Show resolved Hide resolved
var providers []SignerVerifier
func NewEnvelopeSigner(p ...Signer) (*EnvelopeSigner, error) {
var providers []Signer

for _, sv := range p {
if sv != nil {
providers = append(providers, sv)
for _, s := range p {
if s != nil {
providers = append(providers, s)
}
}

Expand Down
2 changes: 1 addition & 1 deletion dsse/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestNoSigners(t *testing.T) {
})

t.Run("empty slice", func(t *testing.T) {
signer, err := NewEnvelopeSigner([]SignerVerifier{}...)
signer, err := NewEnvelopeSigner([]Signer{}...)
assert.Nil(t, signer, "unexpected signer")
assert.NotNil(t, err, "error expected")
assert.Equal(t, ErrNoSigners, err, "wrong error")
Expand Down
2 changes: 1 addition & 1 deletion dsse/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestVerifyMultipleProviderThreshold(t *testing.T) {

var ns nilSignerVerifier
var null nullSignerVerifier
signer, err := NewMultiEnvelopeSigner(2, ns, null)
signer, err := NewEnvelopeSigner(ns, null)
assert.Nil(t, err)
env, err := signer.SignPayload(context.TODO(), payloadType, []byte(payload))
assert.Nil(t, err, "sign failed")
Expand Down
Loading