From d484c2ff6bbdf18ef029bc2256beb887f2dceda2 Mon Sep 17 00:00:00 2001 From: data-man Date: Thu, 17 May 2018 13:32:50 +0300 Subject: [PATCH 1/3] Fixes hexDump's bug --- ethp2p/hexdump.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethp2p/hexdump.nim b/ethp2p/hexdump.nim index 38498d9..5d93826 100644 --- a/ethp2p/hexdump.nim +++ b/ethp2p/hexdump.nim @@ -40,7 +40,7 @@ proc dumpHex*(pbytes: pointer, nbytes: int, items = 1, ascii = true): string = var k = 0 while k < items: var ch = cast[ptr char](cast[uint](slider) + k.uint)[] - if ord(ch) > 31 and ord(ch) < 127: asciiText &= ch else: asciiText &= "." + if ascii or (ord(ch) > 31 and ord(ch) < 127): asciiText &= ch else: asciiText &= "." inc(k) case items: of 1: From 02ea6cea084b6ddfe780e87cd689ff28cda0a851 Mon Sep 17 00:00:00 2001 From: data-man Date: Thu, 17 May 2018 15:32:52 +0300 Subject: [PATCH 2/3] Remove unused hexdump module --- ethp2p/hexdump.nim | 92 ---------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 ethp2p/hexdump.nim diff --git a/ethp2p/hexdump.nim b/ethp2p/hexdump.nim deleted file mode 100644 index 5d93826..0000000 --- a/ethp2p/hexdump.nim +++ /dev/null @@ -1,92 +0,0 @@ -# -# Copyright (c) 2016 Eugene Kabanov -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# - -from strutils import toHex, repeat - -proc dumpHex*(pbytes: pointer, nbytes: int, items = 1, ascii = true): string = - ## Return hexadecimal memory dump representation pointed by ``p``. - ## ``nbytes`` - number of bytes to show - ## ``items`` - number of bytes in group (supported ``items`` count is - ## 1, 2, 4, 8) - ## ``ascii`` - if ``true`` show ASCII representation of memory dump. - result = "" - let hexSize = items * 2 - var i = 0 - var slider = pbytes - var asciiText = "" - while i < nbytes: - if i %% 16 == 0: - result = result & toHex(cast[BiggestInt](slider), - sizeof(BiggestInt) * 2) & ": " - var k = 0 - while k < items: - var ch = cast[ptr char](cast[uint](slider) + k.uint)[] - if ascii or (ord(ch) > 31 and ord(ch) < 127): asciiText &= ch else: asciiText &= "." - inc(k) - case items: - of 1: - result = result & toHex(cast[BiggestInt](cast[ptr uint8](slider)[]), - hexSize) - of 2: - result = result & toHex(cast[BiggestInt](cast[ptr uint16](slider)[]), - hexSize) - of 4: - result = result & toHex(cast[BiggestInt](cast[ptr uint32](slider)[]), - hexSize) - of 8: - result = result & toHex(cast[BiggestInt](cast[ptr uint64](slider)[]), - hexSize) - else: - raise newException(ValueError, "Wrong items size!") - result = result & " " - slider = cast[pointer](cast[uint](slider) + items.uint) - i = i + items - if i %% 16 == 0: - result = result & " " & asciiText - asciiText.setLen(0) - result = result & "\n" - - if i %% 16 != 0: - var spacesCount = ((16 - (i %% 16)) div items) * (hexSize + 1) + 1 - result = result & repeat(' ', spacesCount) - result = result & asciiText - result = result & "\n" - -proc dumpHex*[T](v: openarray[T], items: int = 0, ascii = true): string = - ## Return hexadecimal memory dump representation of openarray[T] ``v``. - ## ``items`` - number of bytes in group (supported ``items`` count is - ## 0, 1, 2, 4, 8). If ``items`` is ``0`` group size will depend on - ## ``sizeof(T)``. - ## ``ascii`` - if ``true`` show ASCII representation of memory dump. - var i = 0 - if items == 0: - when sizeof(T) == 2: - i = 2 - elif sizeof(T) == 4: - i = 4 - elif sizeof(T) == 8: - i = 8 - else: - i = 1 - else: - i = items - result = dumpHex(unsafeAddr v[0], sizeof(T) * len(v), i, ascii) From b6b511c1ad4bf4620d51f904b6818e6d6333accb Mon Sep 17 00:00:00 2001 From: data-man Date: Thu, 17 May 2018 15:49:22 +0300 Subject: [PATCH 3/3] Fix tests --- ethp2p.nim | 4 ++-- tests/testauth.nim | 3 +-- tests/testcrypt.nim | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ethp2p.nim b/ethp2p.nim index 4e1c3f6..e5e1ba0 100644 --- a/ethp2p.nim +++ b/ethp2p.nim @@ -8,5 +8,5 @@ # MIT license (LICENSE-MIT) # -import ethp2p/[ecies, auth, hexdump, enode, rlpxcrypt, discovery, kademlia] -export ecies, auth, enode, hexdump, rlpxcrypt, discovery, kademlia +import ethp2p/[ecies, auth, enode, rlpxcrypt, discovery, kademlia] +export ecies, auth, enode, rlpxcrypt, discovery, kademlia diff --git a/tests/testauth.nim b/tests/testauth.nim index cc890b0..74b551c 100644 --- a/tests/testauth.nim +++ b/tests/testauth.nim @@ -8,8 +8,7 @@ # import unittest -import eth_keys, ethp2p/auth, nimcrypto/utils, nimcrypto/keccak, - ethp2p/hexdump +import eth_keys, ethp2p/auth, nimcrypto/utils, nimcrypto/keccak # This was generated by `print` actual auth message generated by # https://github.com/ethereum/py-evm/blob/master/tests/p2p/test_auth.py diff --git a/tests/testcrypt.nim b/tests/testcrypt.nim index ab8496e..85afe3c 100644 --- a/tests/testcrypt.nim +++ b/tests/testcrypt.nim @@ -8,7 +8,7 @@ # import unittest -import eth_keys, ethp2p/auth, ethp2p/rlpxcrypt, nimcrypto/utils, ethp2p/hexdump +import eth_keys, ethp2p/auth, ethp2p/rlpxcrypt, nimcrypto/utils import nimcrypto/sysrand, nimcrypto/keccak const data = [