Skip to content

Commit fa82ee3

Browse files
authoredJan 24, 2025
Merge pull request #304 from vulncheck-oss/pack
Add transform.PackBigInt64
2 parents b49fee3 + 7bd2b92 commit fa82ee3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
 

‎transform/encode.go

+12
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,15 @@ func PackBigInt32(n int) string {
197197

198198
return packed.String()
199199
}
200+
201+
// PackBigInt64 packs a big-endian 64-bit integer as a string.
202+
func PackBigInt64(n int) string {
203+
var packed strings.Builder
204+
205+
err := binary.Write(&packed, binary.BigEndian, int64(n))
206+
if err != nil {
207+
output.PrintFrameworkError(err.Error())
208+
}
209+
210+
return packed.String()
211+
}

‎transform/encode_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ func TestPackBigInt32(t *testing.T) {
174174
t.Log(packed)
175175
}
176176

177+
func TestPackBigInt64(t *testing.T) {
178+
packed := PackBigInt64(0x4142434445464748)
179+
180+
if packed != "ABCDEFGH" {
181+
t.Fatal(packed)
182+
}
183+
184+
t.Log(packed)
185+
}
186+
177187
func TestInflate(t *testing.T) {
178188
compressed := "\x1f\x8b\x08\x08\xf4\xe9\x97\x66\x00\x03\x77\x61\x74\x00\x2b\x2b\xcd\xc9\x4b\xce\x48\x4d\xce\xe6\x02\x00\x3d\xf1\xb3\xf9\x0a\x00\x00\x00"
179189
inflated, ok := Inflate([]byte(compressed))

0 commit comments

Comments
 (0)
Failed to load comments.