Skip to content

Commit

Permalink
Split common_test
Browse files Browse the repository at this point in the history
  • Loading branch information
droppingin committed May 21, 2023
1 parent a81014c commit db3e080
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions common_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package crypto11

import (
"encoding/hex"
"fmt"
"testing"
)

func TestULongMasking(t *testing.T) {
func TestUlongToBytes(t *testing.T) {
ulongData := uint(0x33221100ddccbbaa)
ulongSlice := ulongToBytes(ulongData)

expected := "AABBCCDD00112233"
actual := fmt.Sprintf("%X", string(ulongSlice))
if expected != actual {
t.Errorf("expected %s != %s", expected, actual)
}
}

func TestBytesToUlong(t *testing.T) {
// Build an slice that is longer than the size of a ulong
extraLongSlice := append(ulongSlice, ulongSlice...)
extraLongSlice, _ := hex.DecodeString("AABBCCDD00112233AABBCCDD00112233")
ulongSlice := extraLongSlice[0:8]

tests := []struct {
slice []uint8
Expand All @@ -30,7 +41,7 @@ func TestULongMasking(t *testing.T) {
for _, test := range tests {
got := bytesToUlong(test.slice)
if test.expected != got {
t.Errorf("conversion failed: 0x%X != 0x%X", test.expected, got)
t.Errorf("conversion failed: expected 0x%X != 0x%X", test.expected, got)
}
}
}

0 comments on commit db3e080

Please sign in to comment.