Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved the CryptoStream errors causing the node version incompatibili… #14

Merged
merged 1 commit into from
Feb 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions js/lib/CryptoStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
<Buffer a0 4a 2e 8e 2d ce de 12 15 03 7a 42 44 ca 84 88 72 64 77 61 72 65 2f 6f 74 61 5f 63 68 75 6e 6b>
<Buffer 5f 73 69 7a 65 ff 35 31 32>
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 () {
Expand Down