-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.go
More file actions
36 lines (29 loc) · 697 Bytes
/
utils.go
File metadata and controls
36 lines (29 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"encoding/hex"
"fmt"
"math/big"
)
// hexEncodeBytes returns a string contains the hex-encoding of the provided
// slice of bytes.
func hexEncodeBytes(b []byte) string {
dst := make([]byte, hex.EncodedLen(len(b)))
hex.Encode(dst, b)
return string(dst)
}
// outputBigInt outputs a big integer on multiple lines, with the label
// only on the first line.
func outputBigInt(label string, fw int, n *big.Int) {
b := n.Bytes()
const bytesPerLine = 16
for i := 0; i < len(b); i += bytesPerLine {
if i != 0 {
label = ""
}
var end = i + bytesPerLine
if end > len(b) {
end = len(b)
}
fmt.Printf("%-*s: %s\n", fw, label, hexEncodeBytes(b[i:end]))
}
}