simplify noise frame construction (#478)
This commit is contained in:
parent
051681678b
commit
0c331d5200
|
@ -435,15 +435,12 @@ proc encryptFrame(
|
||||||
doAssert cipherFrame.len == 2 + src.len + sizeof(ChaChaPolyTag)
|
doAssert cipherFrame.len == 2 + src.len + sizeof(ChaChaPolyTag)
|
||||||
|
|
||||||
cipherFrame[0..<2] = toBytesBE(uint16(src.len + sizeof(ChaChaPolyTag)))
|
cipherFrame[0..<2] = toBytesBE(uint16(src.len + sizeof(ChaChaPolyTag)))
|
||||||
|
cipherFrame[2..<2 + src.len()] = src
|
||||||
copyMem(addr cipherFrame[2], unsafeAddr src[0], src.len())
|
|
||||||
|
|
||||||
let tag = encrypt(
|
let tag = encrypt(
|
||||||
sconn.writeCs, cipherFrame.toOpenArray(2, 2 + src.len() - 1), [])
|
sconn.writeCs, cipherFrame.toOpenArray(2, 2 + src.len() - 1), [])
|
||||||
|
|
||||||
copyMem(
|
cipherFrame[2 + src.len()..<cipherFrame.len] = tag
|
||||||
addr cipherFrame[cipherFrame.len - sizeof(tag)], unsafeAddr tag[0],
|
|
||||||
sizeof(tag))
|
|
||||||
|
|
||||||
method write*(sconn: NoiseConnection, message: seq[byte]): Future[void] {.async.} =
|
method write*(sconn: NoiseConnection, message: seq[byte]): Future[void] {.async.} =
|
||||||
if message.len == 0:
|
if message.len == 0:
|
||||||
|
|
Loading…
Reference in New Issue