Skip to content

Commit 1966c4a

Browse files
authored
Merge pull request #6 from adityasaky/update-pae
Update PAE to expect byte sequence for payload
2 parents 9da84e7 + 293854d commit 1966c4a

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

dsse/sign.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type Signature struct {
4848
PAE implementes the DSSE Pre-Authentic Encoding
4949
https://github.com/secure-systems-lab/dsse/blob/master/protocol.md#signature-definition
5050
*/
51-
func PAE(payloadType, payload string) []byte {
51+
func PAE(payloadType string, payload []byte) []byte {
5252
return []byte(fmt.Sprintf("DSSEv1 %d %s %d %s",
5353
len(payloadType), payloadType,
5454
len(payload), payload))
@@ -124,7 +124,7 @@ func (es *EnvelopeSigner) SignPayload(payloadType string, body []byte) (*Envelop
124124
PayloadType: payloadType,
125125
}
126126

127-
paeEnc := PAE(payloadType, string(body))
127+
paeEnc := PAE(payloadType, body)
128128

129129
for _, signer := range es.providers {
130130
sig, keyID, err := signer.Sign(paeEnc)

dsse/sign_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ func TestPAE(t *testing.T) {
2020
t.Run("Empty", func(t *testing.T) {
2121
var want = []byte("DSSEv1 0 0 ")
2222

23-
got := PAE("", "")
23+
got := PAE("", []byte{})
2424
assert.Equal(t, want, got, "Wrong encoding")
2525
})
2626
t.Run("Hello world", func(t *testing.T) {
2727
var want = []byte("DSSEv1 29 http://example.com/HelloWorld 11 hello world")
2828

29-
got := PAE("http://example.com/HelloWorld", "hello world")
29+
got := PAE("http://example.com/HelloWorld", []byte("hello world"))
30+
assert.Equal(t, want, got, "Wrong encoding")
31+
})
32+
t.Run("Unicode-only", func(t *testing.T) {
33+
var want = []byte("DSSEv1 29 http://example.com/HelloWorld 3 ಠ")
34+
35+
got := PAE("http://example.com/HelloWorld", []byte("ಠ"))
3036
assert.Equal(t, want, got, "Wrong encoding")
3137
})
3238
}
@@ -144,7 +150,7 @@ func TestNoSigners(t *testing.T) {
144150
func TestNilSign(t *testing.T) {
145151
var keyID = "nil"
146152
var payloadType = "http://example.com/HelloWorld"
147-
var payload = "hello world"
153+
var payload = []byte("hello world")
148154

149155
pae := PAE(payloadType, payload)
150156
want := Envelope{

dsse/verify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (ev *EnvelopeVerifier) Verify(e *Envelope) error {
2929
return err
3030
}
3131
// Generate PAE(payloadtype, serialized body)
32-
paeEnc := PAE(e.PayloadType, string(body))
32+
paeEnc := PAE(e.PayloadType, body)
3333

3434
// If *any* signature is found to be incorrect, the entire verification
3535
// step fails even if *some* signatures are correct.

0 commit comments

Comments
 (0)