From d4ff1c88e93b166d7a22a099c8af58a56d447452 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Tue, 24 May 2022 15:10:57 +0200 Subject: [PATCH] Less warnings (#710) --- config.nims | 3 ++ libp2p/crypto/crypto.nim | 2 - libp2p/crypto/curve25519.nim | 2 +- libp2p/crypto/ecnist.nim | 22 ++++----- libp2p/crypto/rsa.nim | 64 +++++++++++++-------------- libp2p/multistream.nim | 1 - libp2p/nameresolving/nameresolver.nim | 1 - libp2p/peerid.nim | 7 ++- libp2p/peerinfo.nim | 2 +- libp2p/peerstore.nim | 2 +- libp2p/protocols/secure/secure.nim | 2 +- libp2p/routing_record.nim | 4 +- tests/testbufferstream.nim | 4 +- tests/testmplex.nim | 2 +- tests/testmultistream.nim | 3 -- tests/testnoise.nim | 1 - 16 files changed, 62 insertions(+), 60 deletions(-) diff --git a/config.nims b/config.nims index 80f134395..d26e195ff 100644 --- a/config.nims +++ b/config.nims @@ -1,3 +1,6 @@ # to allow locking if dirExists("nimbledeps/pkgs"): switch("NimblePath", "nimbledeps/pkgs") + +when (NimMajor, NimMinor) > (1, 2): + switch("hint", "XCannotRaiseY:off") \ No newline at end of file diff --git a/libp2p/crypto/crypto.nim b/libp2p/crypto/crypto.nim index 6dd1b280a..a9cde403e 100644 --- a/libp2p/crypto/crypto.nim +++ b/libp2p/crypto/crypto.nim @@ -81,8 +81,6 @@ export results # This is workaround for Nim's `import` bug export rijndael, twofish, sha2, hash, hmac, ncrutils -from strutils import split - type DigestSheme* = enum Sha256, diff --git a/libp2p/crypto/curve25519.nim b/libp2p/crypto/curve25519.nim index d1b0b0029..4f66b1616 100644 --- a/libp2p/crypto/curve25519.nim +++ b/libp2p/crypto/curve25519.nim @@ -28,7 +28,7 @@ const type Curve25519* = object Curve25519Key* = array[Curve25519KeySize, byte] - pcuchar = ptr cuchar + pcuchar = ptr char Curve25519Error* = enum Curver25519GenError diff --git a/libp2p/crypto/ecnist.nim b/libp2p/crypto/ecnist.nim index 6d1277956..b212eb360 100644 --- a/libp2p/crypto/ecnist.nim +++ b/libp2p/crypto/ecnist.nim @@ -123,8 +123,8 @@ proc checkPublic(key: openArray[byte], curve: cint): uint32 = var impl = brEcGetDefault() var orderlen = 0 discard impl.order(curve, addr orderlen) - result = impl.mul(cast[ptr cuchar](unsafeAddr ckey[0]), len(ckey), - cast[ptr cuchar](addr x[0]), len(x), curve) + result = impl.mul(cast[ptr char](unsafeAddr ckey[0]), len(ckey), + cast[ptr char](addr x[0]), len(x), curve) proc getOffset(pubkey: EcPublicKey): int {.inline.} = let o = cast[uint](pubkey.key.q) - cast[uint](unsafeAddr pubkey.buffer[0]) @@ -174,7 +174,7 @@ proc copy*[T: EcPKI](dst: var T, src: T): bool = dst.buffer = src.buffer dst.key.curve = src.key.curve dst.key.xlen = length - dst.key.x = cast[ptr cuchar](addr dst.buffer[offset]) + dst.key.x = cast[ptr char](addr dst.buffer[offset]) result = true elif T is EcPublicKey: let length = src.key.qlen @@ -184,7 +184,7 @@ proc copy*[T: EcPKI](dst: var T, src: T): bool = dst.buffer = src.buffer dst.key.curve = src.key.curve dst.key.qlen = length - dst.key.q = cast[ptr cuchar](addr dst.buffer[offset]) + dst.key.q = cast[ptr char](addr dst.buffer[offset]) result = true else: let length = len(src.buffer) @@ -252,8 +252,8 @@ proc getPublicKey*(seckey: EcPrivateKey): EcResult[EcPublicKey] = var ecimp = brEcGetDefault() if seckey.key.curve in EcSupportedCurvesCint: - var length = getPublicKeyLength(cast[EcCurveKind](seckey.key.curve)) var res = new EcPublicKey + assert res.buffer.len > getPublicKeyLength(cast[EcCurveKind](seckey.key.curve)) if brEcComputePublicKey(ecimp, addr res.key, addr res.buffer[0], unsafeAddr seckey.key) == 0: err(EcKeyIncorrectError) @@ -638,7 +638,7 @@ proc init*(key: var EcPrivateKey, data: openArray[byte]): Result[void, Asn1Error if checkScalar(raw.toOpenArray(), curve) == 1'u32: key = new EcPrivateKey copyMem(addr key.buffer[0], addr raw.buffer[raw.offset], raw.length) - key.key.x = cast[ptr cuchar](addr key.buffer[0]) + key.key.x = cast[ptr char](addr key.buffer[0]) key.key.xlen = raw.length key.key.curve = curve ok() @@ -697,7 +697,7 @@ proc init*(pubkey: var EcPublicKey, data: openArray[byte]): Result[void, Asn1Err if checkPublic(raw.toOpenArray(), curve) != 0: pubkey = new EcPublicKey copyMem(addr pubkey.buffer[0], addr raw.buffer[raw.offset], raw.length) - pubkey.key.q = cast[ptr cuchar](addr pubkey.buffer[0]) + pubkey.key.q = cast[ptr char](addr pubkey.buffer[0]) pubkey.key.qlen = raw.length pubkey.key.curve = curve ok() @@ -785,7 +785,7 @@ proc initRaw*(key: var EcPrivateKey, data: openArray[byte]): bool = let length = len(data) key = new EcPrivateKey copyMem(addr key.buffer[0], unsafeAddr data[0], length) - key.key.x = cast[ptr cuchar](addr key.buffer[0]) + key.key.x = cast[ptr char](addr key.buffer[0]) key.key.xlen = length key.key.curve = curve result = true @@ -816,7 +816,7 @@ proc initRaw*(pubkey: var EcPublicKey, data: openArray[byte]): bool = let length = len(data) pubkey = new EcPublicKey copyMem(addr pubkey.buffer[0], unsafeAddr data[0], length) - pubkey.key.q = cast[ptr cuchar](addr pubkey.buffer[0]) + pubkey.key.q = cast[ptr char](addr pubkey.buffer[0]) pubkey.key.qlen = length pubkey.key.curve = curve result = true @@ -891,9 +891,9 @@ proc scalarMul*(pub: EcPublicKey, sec: EcPrivateKey): EcPublicKey = let poffset = key.getOffset() let soffset = sec.getOffset() if poffset >= 0 and soffset >= 0: - let res = impl.mul(cast[ptr cuchar](addr key.buffer[poffset]), + let res = impl.mul(cast[ptr char](addr key.buffer[poffset]), key.key.qlen, - cast[ptr cuchar](unsafeAddr sec.buffer[soffset]), + cast[ptr char](unsafeAddr sec.buffer[soffset]), sec.key.xlen, key.key.curve) if res != 0: diff --git a/libp2p/crypto/rsa.nim b/libp2p/crypto/rsa.nim index dc8662680..133936cd6 100644 --- a/libp2p/crypto/rsa.nim +++ b/libp2p/crypto/rsa.nim @@ -62,7 +62,7 @@ type buffer*: seq[byte] seck*: BrRsaPrivateKey pubk*: BrRsaPublicKey - pexp*: ptr cuchar + pexp*: ptr char pexplen*: int RsaPublicKey* = ref object @@ -109,9 +109,9 @@ template getArray*(bs, os, ls: untyped): untyped = template trimZeroes(b: seq[byte], pt, ptlen: untyped) = var length = ptlen for i in 0.. 0 and len(rawdq) > 0 and len(rawiq) > 0: key = new RsaPrivateKey key.buffer = @data - key.pubk.n = cast[ptr cuchar](addr key.buffer[rawn.offset]) - key.pubk.e = cast[ptr cuchar](addr key.buffer[rawpube.offset]) - key.seck.p = cast[ptr cuchar](addr key.buffer[rawp.offset]) - key.seck.q = cast[ptr cuchar](addr key.buffer[rawq.offset]) - key.seck.dp = cast[ptr cuchar](addr key.buffer[rawdp.offset]) - key.seck.dq = cast[ptr cuchar](addr key.buffer[rawdq.offset]) - key.seck.iq = cast[ptr cuchar](addr key.buffer[rawiq.offset]) - key.pexp = cast[ptr cuchar](addr key.buffer[rawprie.offset]) + key.pubk.n = cast[ptr char](addr key.buffer[rawn.offset]) + key.pubk.e = cast[ptr char](addr key.buffer[rawpube.offset]) + key.seck.p = cast[ptr char](addr key.buffer[rawp.offset]) + key.seck.q = cast[ptr char](addr key.buffer[rawq.offset]) + key.seck.dp = cast[ptr char](addr key.buffer[rawdp.offset]) + key.seck.dq = cast[ptr char](addr key.buffer[rawdq.offset]) + key.seck.iq = cast[ptr char](addr key.buffer[rawiq.offset]) + key.pexp = cast[ptr char](addr key.buffer[rawprie.offset]) key.pubk.nlen = len(rawn) key.pubk.elen = len(rawpube) key.seck.plen = len(rawp) @@ -554,8 +554,8 @@ proc init*(key: var RsaPublicKey, data: openArray[byte]): Result[void, Asn1Error if len(rawn) >= (MinKeySize shr 3) and len(rawe) > 0: key = new RsaPublicKey key.buffer = @data - key.key.n = cast[ptr cuchar](addr key.buffer[rawn.offset]) - key.key.e = cast[ptr cuchar](addr key.buffer[rawe.offset]) + key.key.n = cast[ptr char](addr key.buffer[rawn.offset]) + key.key.e = cast[ptr char](addr key.buffer[rawe.offset]) key.key.nlen = len(rawn) key.key.elen = len(rawe) ok() @@ -762,9 +762,9 @@ proc sign*[T: byte|char](key: RsaPrivateKey, kv.update(addr hc.vtable, nil, 0) kv.output(addr hc.vtable, addr hash[0]) var oid = RsaOidSha256 - let implRes = impl(cast[ptr cuchar](addr oid[0]), - cast[ptr cuchar](addr hash[0]), len(hash), - addr key.seck, cast[ptr cuchar](addr res.buffer[0])) + let implRes = impl(cast[ptr char](addr oid[0]), + cast[ptr char](addr hash[0]), len(hash), + addr key.seck, cast[ptr char](addr res.buffer[0])) if implRes == 0: err(RsaSignatureError) else: @@ -791,8 +791,8 @@ proc verify*[T: byte|char](sig: RsaSignature, message: openArray[T], kv.update(addr hc.vtable, nil, 0) kv.output(addr hc.vtable, addr hash[0]) var oid = RsaOidSha256 - let res = impl(cast[ptr cuchar](addr sig.buffer[0]), len(sig.buffer), - cast[ptr cuchar](addr oid[0]), - len(check), addr pubkey.key, cast[ptr cuchar](addr check[0])) + let res = impl(cast[ptr char](addr sig.buffer[0]), len(sig.buffer), + cast[ptr char](addr oid[0]), + len(check), addr pubkey.key, cast[ptr char](addr check[0])) if res == 1: result = equalMem(addr check[0], addr hash[0], len(hash)) diff --git a/libp2p/multistream.nim b/libp2p/multistream.nim index 95e40c023..3070123d7 100644 --- a/libp2p/multistream.nim +++ b/libp2p/multistream.nim @@ -12,7 +12,6 @@ import std/[strutils] import chronos, chronicles, stew/byteutils import stream/connection, - vbuffer, protocols/protocol logScope: diff --git a/libp2p/nameresolving/nameresolver.nim b/libp2p/nameresolving/nameresolver.nim index 6f1e97588..b8da3352a 100644 --- a/libp2p/nameresolving/nameresolver.nim +++ b/libp2p/nameresolving/nameresolver.nim @@ -62,7 +62,6 @@ proc resolveDnsAddress( port = Port(fromBytesBE(uint16, pbuf)) resolvedAddresses = await self.resolveIp(prefix & dnsval, port, domain) - var addressSuffix = ma return collect(newSeqOfCap(4)): for address in resolvedAddresses: var createdAddress = MultiAddress.init(address).tryGet()[0].tryGet() diff --git a/libp2p/peerid.nim b/libp2p/peerid.nim index b7b2c0dcc..a50cac220 100644 --- a/libp2p/peerid.nim +++ b/libp2p/peerid.nim @@ -38,7 +38,12 @@ func shortLog*(pid: PeerId): string = var spid = $pid if len(spid) > 10: spid[3] = '*' - spid.delete(4, spid.high - 6) + + # reminder to remove this once we stop supporting 1.2 + when (NimMajor, NimMinor) > (1, 2): + spid.delete(4 .. spid.high - 6) + else: + spid.delete(4, spid.high - 6) spid diff --git a/libp2p/peerinfo.nim b/libp2p/peerinfo.nim index af1ad98c8..ce953cc3b 100644 --- a/libp2p/peerinfo.nim +++ b/libp2p/peerinfo.nim @@ -9,7 +9,7 @@ {.push raises: [Defect].} -import std/[options, sequtils, hashes] +import std/[options, sequtils] import pkg/[chronos, chronicles, stew/results] import peerid, multiaddress, crypto/crypto, routing_record, errors diff --git a/libp2p/peerstore.nim b/libp2p/peerstore.nim index 33c34b775..992b337f6 100644 --- a/libp2p/peerstore.nim +++ b/libp2p/peerstore.nim @@ -10,7 +10,7 @@ {.push raises: [Defect].} import - std/[tables, sets, sequtils, options], + std/[tables, sets, options], ./crypto/crypto, ./protocols/identify, ./peerid, ./peerinfo, diff --git a/libp2p/protocols/secure/secure.nim b/libp2p/protocols/secure/secure.nim index 3e098767f..5e9a30d1d 100644 --- a/libp2p/protocols/secure/secure.nim +++ b/libp2p/protocols/secure/secure.nim @@ -9,7 +9,7 @@ {.push raises: [Defect].} -import std/[options, strformat] +import std/[strformat] import chronos, chronicles, bearssl import ../protocol, ../../stream/streamseq, diff --git a/libp2p/routing_record.nim b/libp2p/routing_record.nim index 26e52e783..b3410581c 100644 --- a/libp2p/routing_record.nim +++ b/libp2p/routing_record.nim @@ -11,8 +11,8 @@ {.push raises: [Defect].} -import std/[sequtils, times, sugar] -import pkg/stew/[results, byteutils] +import std/[sequtils, times] +import pkg/stew/results import multiaddress, multicodec, diff --git a/tests/testbufferstream.nim b/tests/testbufferstream.nim index 35874dbc0..a31997e01 100644 --- a/tests/testbufferstream.nim +++ b/tests/testbufferstream.nim @@ -228,7 +228,9 @@ suite "BufferStream": await stream.pushData("123".toBytes()) let push = stream.pushData("123".toBytes()) - expect AssertionError: + when (NimMajor, NimMinor) < (1, 4): + type AssertionDefect = AssertionError + expect AssertionDefect: await stream.pushData("123".toBytes()) await stream.closeWithEOF() diff --git a/tests/testmplex.nim b/tests/testmplex.nim index be45f07be..bce9e9af4 100644 --- a/tests/testmplex.nim +++ b/tests/testmplex.nim @@ -1,4 +1,4 @@ -import strformat, strformat, random, oids, sequtils +import strformat, random, oids, sequtils import chronos, nimcrypto/utils, chronicles, stew/byteutils import ../libp2p/[errors, stream/connection, diff --git a/tests/testmultistream.nim b/tests/testmultistream.nim index 5690ec0fc..6b07fcc72 100644 --- a/tests/testmultistream.nim +++ b/tests/testmultistream.nim @@ -278,9 +278,6 @@ suite "Multistream select": asyncTest "e2e - ls": let ma = @[MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet()] - let - handlerWait = newFuture[void]() - let msListen = MultistreamSelect.new() var protocol: LPProtocol = new LPProtocol protocol.handler = proc(conn: Connection, proto: string) {.async, gcsafe.} = diff --git a/tests/testnoise.nim b/tests/testnoise.nim index 8415d6f17..8c9e82e82 100644 --- a/tests/testnoise.nim +++ b/tests/testnoise.nim @@ -12,7 +12,6 @@ import tables, bearssl import chronos, stew/byteutils import chronicles -import ../libp2p/crypto/crypto import ../libp2p/[switch, errors, multistream,