aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2020-06-07 12:14:51 +0200
committerpukkamustard <pukkamustard@posteo.net>2020-06-07 12:14:51 +0200
commit1bca8692addcc7618ed18a2984d8a95fd64da0a2 (patch)
treee32bb16ea60172305b4d45fa5bc0301b06b11cce
parentffe7fe6f45e3a0b6d06da49d8498193d10f3e820 (diff)
naive decoding (non stream)
-rw-r--r--src/eris.js28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/eris.js b/src/eris.js
index 787f0d2..7f37498 100644
--- a/src/eris.js
+++ b/src/eris.js
@@ -261,7 +261,22 @@ async function * decodeTree (cas, verificationKey, ref, nodeLevel, nodeCount) {
}
}
-async function * get (capability, cas) {
+async function concatBlocks (iterable) {
+ const blocks = []
+ for await (const block of iterable) {
+ blocks.push(block)
+ }
+
+ const out = new Uint8Array(blocks.length * 4096)
+
+ for (const i in blocks) {
+ out.set(blocks[i], i * 4096)
+ }
+
+ return out
+}
+
+async function get (capability, cas) {
capability = decodeCapability(capability)
if (capability.type !== 0) {
@@ -270,7 +285,16 @@ async function * get (capability, cas) {
const verificationKey = await crypto.derive_verification_key(capability.key)
- yield * decodeTree(cas, verificationKey, capability.rootReference, capability.level, 0)
+ const blockGenerator = decodeTree(cas, verificationKey, capability.rootReference, capability.level, 0)
+
+ const encrypted = await concatBlocks(blockGenerator)
+
+ const nonce = new Uint8Array(crypto.stream_xor_noncebytes)
+ const padded = await crypto.stream_xor(encrypted, nonce, capability.key)
+
+ const unpadded = await crypto.unpad(padded)
+
+ return unpadded
}
module.exports = {