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.

28 lines
678 B

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