mirror of
https://github.com/status-im/keycard-go.git
synced 2025-02-20 23:58:13 +00:00
add appendDESPadding function
This commit is contained in:
parent
a2e6eec5b2
commit
e81db1f0bd
@ -37,3 +37,15 @@ func resizeKey24(key []byte) []byte {
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
func appendDESPadding(data []byte) []byte {
|
||||
length := len(data) + 1
|
||||
for ; length%8 != 0; length++ {
|
||||
}
|
||||
|
||||
newData := make([]byte, length)
|
||||
copy(newData, data)
|
||||
copy(newData[len(data):], []byte{0x80})
|
||||
|
||||
return newData
|
||||
}
|
||||
|
@ -24,3 +24,10 @@ func TestResizeKey24(t *testing.T) {
|
||||
expected := "404142434445464748494A4B4C4D4E4F4041424344454647"
|
||||
assert.Equal(t, expected, hexutils.BytesToHex(resized))
|
||||
}
|
||||
|
||||
func TestAppendDESPadding(t *testing.T) {
|
||||
data := hexutils.HexToBytes("AABB")
|
||||
result := appendDESPadding(data)
|
||||
expected := "AABB800000000000"
|
||||
assert.Equal(t, expected, hexutils.BytesToHex(result))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user