Skip to content

The unpacker needs to divide the length by zero to get the bytes #366

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion field/packer_unpacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (p Track2Unpacker) Unpack(packedFieldValue []byte, spec *Spec) ([]byte, int
}

// decode the value
value, read, err := spec.Enc.Decode(packedFieldValue[prefBytes:], valueLength)
value, read, err := spec.Enc.Decode(packedFieldValue[prefBytes:], valueLength/2)
if err != nil {
return nil, 0, fmt.Errorf("failed to decode content: %w", err)
}
Expand Down
12 changes: 6 additions & 6 deletions field/packer_unpacker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func TestTrack2Packer(t *testing.T) {
s := &field.Spec{
Length: 37,
Description: "Track 2 Data",
Enc: encoding.ASCII,
Pref: prefix.ASCII.LL,
Enc: encoding.ASCIIHexToBytes,
Pref: prefix.Binary.L,
Pad: padding.Left('0'),
Packer: field.Track2Packer{},
Unpacker: field.Track2Unpacker{},
Expand All @@ -140,8 +140,8 @@ func TestTrack2Packer(t *testing.T) {
discretionaryData: "1474900373",
separator: "D",
expirationDate: expirationDate,
// Two bytes for length then: 44444444444444D31122011474900373
expectedPack: []byte{0x33, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x44, 0x33, 0x31, 0x31, 0x32, 0x32, 0x30, 0x31, 0x31, 0x34, 0x37, 0x34, 0x39, 0x30, 0x30, 0x33, 0x37, 0x33},
// One bytes for length then: 44444444444444D31122011474900373
expectedPack: []byte{0x22, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0xd3, 0x11, 0x22, 0x1, 0x14, 0x74, 0x90, 0x3, 0x73},
},
{
name: "odd length",
Expand All @@ -150,8 +150,8 @@ func TestTrack2Packer(t *testing.T) {
discretionaryData: "147",
separator: "D",
expirationDate: expirationDate,
// Two bytes for length then: 04444444444444444D3112201147
expectedPack: []byte{0x32, 0x37, 0x30, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x44, 0x33, 0x31, 0x31, 0x32, 0x32, 0x30, 0x31, 0x31, 0x34, 0x37},
// One bytes for length then: 04444444444444444D3112201147
expectedPack: []byte{0x1b, 0x4, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x4d, 0x31, 0x12, 0x20, 0x11, 0x47},
},
}

Expand Down
Loading