MCPcopy
hub / github.com/canopy-network/canopy / encodeBigInt

Function encodeBigInt

lib/crypto/classgroup.go:443–455  ·  view source on GitHub ↗

encodeBigInt() encodes a big integer as a big-endian byte slice but preserves the sign using the first byte

(i *big.Int)

Source from the content-addressed store, hash-verified

441
442// encodeBigInt() encodes a big integer as a big-endian byte slice but preserves the sign using the first byte
443func encodeBigInt(i *big.Int) []byte {
444 x := bip.New().Set(i)
445 defer bip.Recycle(x)
446 buf := new(bytes.Buffer)
447 if x.Sign() < 0 {
448 buf.WriteByte(1) // Negative sign
449 x.Neg(i)
450 } else {
451 buf.WriteByte(0) // Positive sign
452 }
453 buf.Write(x.Bytes())
454 return buf.Bytes()
455}
456
457// decodeBigInt() decodes a big integer from a big-endian byte slice with a sign byte
458func decodeBigInt(data []byte) *big.Int {

Callers 1

EncodeMethod · 0.85

Calls 6

RecycleMethod · 0.80
WriteMethod · 0.80
SetMethod · 0.65
NewMethod · 0.65
SignMethod · 0.65
BytesMethod · 0.65

Tested by

no test coverage detected