-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39e243b
commit b324c0e
Showing
2 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package paseto | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestPAE(t *testing.T) { | ||
testCases := []struct { | ||
pieces [][]byte | ||
want string | ||
}{ | ||
{ | ||
pieces: nil, | ||
want: "\x00\x00\x00\x00\x00\x00\x00\x00", | ||
}, | ||
{ | ||
pieces: [][]byte{}, | ||
want: "\x00\x00\x00\x00\x00\x00\x00\x00", | ||
}, | ||
{ | ||
pieces: [][]byte{nil}, | ||
want: "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", | ||
}, | ||
{ | ||
pieces: [][]byte{[]byte("test")}, | ||
want: "\x01\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00test", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
res := pae(tc.pieces...) | ||
have := string(res) | ||
|
||
if have != tc.want { | ||
t.Errorf("\nhave: %v\nwant: %v", have, tc.want) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkPAE(b *testing.B) { | ||
var nonce [32]byte | ||
var encryptedPayload [256]byte | ||
var footerBytes []byte | ||
|
||
pieces := [][]byte{ | ||
[]byte(v1LocHeader), | ||
nonce[:], | ||
encryptedPayload[:], | ||
footerBytes, | ||
} | ||
|
||
b.ReportAllocs() | ||
|
||
for i := 0; i < b.N; i++ { | ||
res := pae(pieces...) | ||
if len(res) == 0 { | ||
b.Fatal() | ||
} | ||
} | ||
} |