-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
6 changed files
with
179 additions
and
12 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
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,18 @@ | ||
package work | ||
|
||
// ZeroPadding Pn(. . . ) The octet-array zero-padding function (14.17 v0.5.2) | ||
func ZeroPadding(x []byte, n uint) []byte { | ||
if n == 0 { | ||
return x | ||
} | ||
|
||
// ((|x|+n-1) mod n)+1...n | ||
start, end := ((len(x)+int(n)-1)%int(n))+1, int(n) | ||
|
||
paddingLength := end - start | ||
if paddingLength <= 0 { | ||
return x | ||
} | ||
|
||
return append(x, make([]byte, paddingLength)...) | ||
} |
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,50 @@ | ||
package work_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/eigerco/strawberry/internal/work" | ||
) | ||
|
||
func TestZeroPadding(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input []byte | ||
multiple uint | ||
expectedOutput []byte | ||
}{ | ||
{ | ||
name: "No padding", | ||
input: []byte{1, 2, 3, 4}, | ||
multiple: 4, | ||
expectedOutput: []byte{1, 2, 3, 4}, | ||
}, | ||
{ | ||
name: "Needs padding", | ||
input: []byte{1, 2, 3, 4, 5}, | ||
multiple: 6, | ||
expectedOutput: []byte{1, 2, 3, 4, 5, 0}, | ||
}, | ||
{ | ||
name: "Needs padding", | ||
input: []byte("data"), | ||
multiple: 6, | ||
expectedOutput: []byte("data\x00\x00"), | ||
}, | ||
{ | ||
name: "Padding with zero n", | ||
input: []byte{1, 2, 3, 4}, | ||
multiple: 0, | ||
expectedOutput: []byte{1, 2, 3, 4}, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
output := work.ZeroPadding(tc.input, tc.multiple) | ||
assert.Equal(t, tc.expectedOutput, output) | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.