From 0c331d520037c7fb3bc03df4b45e6ad7fba89302 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Wed, 16 Dec 2020 13:10:06 +0100 Subject: [PATCH] simplify noise frame construction (#478) --- libp2p/protocols/secure/noise.nim | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libp2p/protocols/secure/noise.nim b/libp2p/protocols/secure/noise.nim index 8f4832a46..effdba19a 100644 --- a/libp2p/protocols/secure/noise.nim +++ b/libp2p/protocols/secure/noise.nim @@ -435,15 +435,12 @@ proc encryptFrame( doAssert cipherFrame.len == 2 + src.len + sizeof(ChaChaPolyTag) cipherFrame[0..<2] = toBytesBE(uint16(src.len + sizeof(ChaChaPolyTag))) - - copyMem(addr cipherFrame[2], unsafeAddr src[0], src.len()) + cipherFrame[2..<2 + src.len()] = src let tag = encrypt( sconn.writeCs, cipherFrame.toOpenArray(2, 2 + src.len() - 1), []) - copyMem( - addr cipherFrame[cipherFrame.len - sizeof(tag)], unsafeAddr tag[0], - sizeof(tag)) + cipherFrame[2 + src.len()..