From c715990992f32119745f2decd0861d4b63efce36 Mon Sep 17 00:00:00 2001 From: snow Date: Thu, 14 Jan 2016 06:51:16 -0500 Subject: [PATCH] Solved the CryptoStream errors causing the node version incompatibilities, now works with up to node 12.5 --- js/lib/CryptoStream.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/js/lib/CryptoStream.js b/js/lib/CryptoStream.js index 9add37db..9abe1fba 100644 --- a/js/lib/CryptoStream.js +++ b/js/lib/CryptoStream.js @@ -69,11 +69,28 @@ CryptoStream.prototype.getCipher = function (callback) { cipher.on('readable', function () { var chunk = cipher.read(); - if (!ciphertext) { - ciphertext = chunk; - } - else { - ciphertext = Buffer.concat([ciphertext, chunk], ciphertext.length + chunk.length); + /* + The crypto stream error was coming from the additional null packet before the end of the stream + + IE + + + null + CryptoStream transform error TypeError: Cannot read property 'length' of null + Coap Error: Error: Invalid CoAP version. Expected 1, got: 3 + + The if statement solves (I believe) all of the node version dependency ussues + + ( Previously required node 10.X, with this tested and working on node 12.5 ) + + */ + if(chunk){ + if (!ciphertext) { + ciphertext = chunk; + } + else { + ciphertext = Buffer.concat([ciphertext, chunk], ciphertext.length + chunk.length); + } } }); cipher.on('end', function () {