You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
588 B

  1. package arbo
  2. import "math/big"
  3. // SwapEndianness swaps the order of the bytes in the byte slice.
  4. func SwapEndianness(b []byte) []byte {
  5. o := make([]byte, len(b))
  6. for i := range b {
  7. o[len(b)-1-i] = b[i]
  8. }
  9. return o
  10. }
  11. // BigIntToBytes converts a *big.Int into a byte array in Little-Endian
  12. func BigIntToBytes(bi *big.Int) []byte {
  13. var b [32]byte
  14. copy(b[:], SwapEndianness(bi.Bytes()))
  15. return b[:]
  16. }
  17. // BytesToBigInt converts a byte array in Little-Endian representation into
  18. // *big.Int
  19. func BytesToBigInt(b []byte) *big.Int {
  20. return new(big.Int).SetBytes(SwapEndianness(b))
  21. }