2018-03-02 15:24:09 +00:00
|
|
|
package util
|
|
|
|
|
2019-10-22 14:56:03 +00:00
|
|
|
// ArrayReverse returns a reversed version of the given byte slice.
|
2018-03-02 15:24:09 +00:00
|
|
|
func ArrayReverse(b []byte) []byte {
|
|
|
|
// Protect from big.Ints that have 1 len bytes.
|
|
|
|
if len(b) < 2 {
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
dest := make([]byte, len(b))
|
2019-02-05 12:22:10 +00:00
|
|
|
for i, j := 0, len(b)-1; i <= j; i, j = i+1, j-1 {
|
2018-03-02 15:24:09 +00:00
|
|
|
dest[i], dest[j] = b[j], b[i]
|
|
|
|
}
|
|
|
|
return dest
|
|
|
|
}
|