From d039ab69b31271135fa9c159c9952b7a8e613153 Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Fri, 4 Jul 2025 19:28:50 +0200 Subject: [PATCH] set default value of the encryption parameter in "store" proc to nil (default: no encryption) --- codex/node.nim | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/codex/node.nim b/codex/node.nim index 9331e4b4..05125c88 100644 --- a/codex/node.nim +++ b/codex/node.nim @@ -404,7 +404,7 @@ proc store*( filename: ?string = string.none, mimetype: ?string = string.none, blockSize = DefaultBlockSize, - encryption: CodexEncryption, + encryption: CodexEncryption = nil, ): Future[?!Cid] {.async.} = ## Save stream contents as dataset with given blockSize ## to nodes's BlockStore, and return Cid of its manifest @@ -422,15 +422,21 @@ proc store*( try: while (let chunk = await chunker.getBytes(); chunk.len > 0): - let encryptedChunk = encryption.encryptBlock(chunk, blockIndex) + echo "chunk[", blockIndex, "]: ", byteutils.toHex(chunk) + let blockData = + if isNil(encryption): + chunk + else: + encryption.encryptBlock(chunk, blockIndex).get() + echo "blockData[", blockIndex, "]: ", byteutils.toHex(blockData) blockIndex.inc() - without mhash =? MultiHash.digest($hcodec, encryptedChunk).mapFailure, err: + without mhash =? MultiHash.digest($hcodec, blockData).mapFailure, err: return failure(err) without cid =? Cid.init(CIDv1, dataCodec, mhash).mapFailure, err: return failure(err) - without blk =? bt.Block.new(cid, encryptedChunk, verify = false): + without blk =? bt.Block.new(cid, blockData, verify = false): return failure("Unable to init block from chunk!") cids.add(cid)