From 9dccfe27f494290444c6600da34d7578c6d8ff36 Mon Sep 17 00:00:00 2001 From: kdeme Date: Wed, 2 Oct 2019 14:12:38 +0200 Subject: [PATCH] Use stew/endians2 for endianness conversion --- eth/p2p/rlpx_protocols/whisper_protocol.nim | 32 ++++++--------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/eth/p2p/rlpx_protocols/whisper_protocol.nim b/eth/p2p/rlpx_protocols/whisper_protocol.nim index 07b51ac..698d0b3 100644 --- a/eth/p2p/rlpx_protocols/whisper_protocol.nim +++ b/eth/p2p/rlpx_protocols/whisper_protocol.nim @@ -7,10 +7,10 @@ ## or long-lived messages must spend more work. import - algorithm, bitops, endians, math, options, sequtils, strutils, tables, times, - secp256k1, chronicles, chronos, eth/common/eth_types, eth/[keys, rlp, async_utils], - hashes, stew/byteutils, nimcrypto/[bcmode, hash, keccak, rijndael, sysrand], - eth/p2p, ../ecies + algorithm, bitops, math, options, sequtils, strutils, tables, times, chronos, + secp256k1, chronicles, hashes, stew/[byteutils, endians2], + nimcrypto/[bcmode, hash, keccak, rijndael, sysrand], + eth/common/eth_types, eth/[keys, rlp, async_utils, p2p], eth/p2p/ecies logScope: topics = "whisper" @@ -129,22 +129,6 @@ type # Utilities -------------------------------------------------------------------- -proc toBE(v: uint64): array[8, byte] = - # return uint64 as bigendian array - for easy consumption with hash function - var v = cast[array[8, byte]](v) - bigEndian64(result.addr, v.addr) -proc toLE(v: uint32): array[4, byte] = - # return uint32 as bigendian array - for easy consumption with hash function - var v = cast[array[4, byte]](v) - littleEndian32(result.addr, v.addr) - -# XXX: get rid of pointer -proc fromLE32(v: array[4, byte]): uint32 = - var v = v - var ret: array[4, byte] - littleEndian32(ret.addr, v.addr) - result = cast[uint32](ret) - proc leadingZeroBits(hash: MDigest): int = ## Number of most significant zero bits before the first one for h in hash.data: @@ -287,7 +271,7 @@ proc encode*(self: Payload): Option[Bytes] = # next, length of payload - little endian (who comes up with this stuff? why # can't the world just settle on one endian?) - let payloadLenLE = self.payload.len.uint32.toLE + let payloadLenLE = self.payload.len.uint32.toBytesLE # No, I have no love for nim closed ranges - such a mess to remember the extra # < or risk off-by-ones when working with lengths.. @@ -386,7 +370,7 @@ proc decode*(data: openarray[byte], dst = none[PrivateKey](), for i in 0..