mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2026-01-09 03:08:21 -05:00
Fixes for style check (#676)
This commit is contained in:
@@ -146,7 +146,7 @@ proc encrypt(
|
||||
|
||||
proc encryptWithAd(state: var CipherState, ad, data: openArray[byte]): seq[byte]
|
||||
{.raises: [Defect, NoiseNonceMaxError].} =
|
||||
result = newSeqOfCap[byte](data.len + sizeof(ChachaPolyTag))
|
||||
result = newSeqOfCap[byte](data.len + sizeof(ChaChaPolyTag))
|
||||
result.add(data)
|
||||
|
||||
let tag = encrypt(state, result, ad)
|
||||
@@ -217,7 +217,7 @@ proc encryptAndHash(ss: var SymmetricState, data: openArray[byte]): seq[byte]
|
||||
proc decryptAndHash(ss: var SymmetricState, data: openArray[byte]): seq[byte]
|
||||
{.raises: [Defect, NoiseDecryptTagError, NoiseNonceMaxError].} =
|
||||
# according to spec if key is empty leave plaintext
|
||||
if ss.cs.hasKey:
|
||||
if ss.cs.hasKey and data.len > ChaChaPolyTag.len:
|
||||
result = ss.cs.decryptWithAd(ss.h.data, data)
|
||||
else:
|
||||
result = @data
|
||||
@@ -368,7 +368,7 @@ proc handshakeXXOutbound(
|
||||
dh_se()
|
||||
|
||||
# last payload must follow the encrypted way of sending
|
||||
msg.add hs.ss.encryptAndHash(p2psecret)
|
||||
msg.add hs.ss.encryptAndHash(p2pSecret)
|
||||
|
||||
await conn.sendHSMessage(msg.data)
|
||||
|
||||
@@ -408,7 +408,7 @@ proc handshakeXXInbound(
|
||||
write_s()
|
||||
dh_es()
|
||||
|
||||
msg.add hs.ss.encryptAndHash(p2psecret)
|
||||
msg.add hs.ss.encryptAndHash(p2pSecret)
|
||||
|
||||
await conn.sendHSMessage(msg.data)
|
||||
msg.clear()
|
||||
@@ -431,7 +431,7 @@ method readMessage*(sconn: NoiseConnection): Future[seq[byte]] {.async.} =
|
||||
while true: # Discard 0-length payloads
|
||||
let frame = await sconn.stream.readFrame()
|
||||
sconn.activity = true
|
||||
if frame.len > 0:
|
||||
if frame.len > ChaChaPolyTag.len:
|
||||
let res = sconn.readCs.decryptWithAd([], frame)
|
||||
if res.len > 0:
|
||||
when defined(libp2p_dump):
|
||||
@@ -554,7 +554,7 @@ method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureCon
|
||||
trace "Remote signature verified", conn
|
||||
|
||||
if initiator:
|
||||
let pid = PeerID.init(remotePubKey)
|
||||
let pid = PeerId.init(remotePubKey)
|
||||
if not conn.peerId.validate():
|
||||
raise newException(NoiseHandshakeError, "Failed to validate peerId.")
|
||||
if pid.isErr or pid.get() != conn.peerId:
|
||||
@@ -567,7 +567,7 @@ method handshake*(p: Noise, conn: Connection, initiator: bool): Future[SecureCon
|
||||
received_key = $remotePubKey
|
||||
raise newException(NoiseHandshakeError, "Noise handshake, peer infos don't match! " & $pid & " != " & $conn.peerId)
|
||||
else:
|
||||
let pid = PeerID.init(remotePubKey)
|
||||
let pid = PeerId.init(remotePubKey)
|
||||
if pid.isErr:
|
||||
raise newException(NoiseHandshakeError, "Invalid remote peer id")
|
||||
conn.peerId = pid.get()
|
||||
|
||||
Reference in New Issue
Block a user