Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
expected.slice(240, 300) + '\x03' +
expected.slice(300, 360);
b = new Buffer(expectedIllegal, 'base64');
assert.equal(quote.length, b.length);
assert.equal(quote, b.toString('ascii', 0, quote.length));
assert.equal(new Buffer('', 'base64').toString(), '');
assert.equal(new Buffer('K', 'base64').toString(), '');
// multiple-of-4 with padding
assert.equal(new Buffer('Kg==', 'base64').toString(), '*');
assert.equal(new Buffer('Kio=', 'base64').toString(), '**');
assert.equal(new Buffer('Kioq', 'base64').toString(), '***');
assert.equal(new Buffer('KioqKg==', 'base64').toString(), '****');
assert.equal(new Buffer('KioqKio=', 'base64').toString(), '*****');
assert.equal(new Buffer('KioqKioq', 'base64').toString(), '******');
assert.equal(new Buffer('KioqKioqKg==', 'base64').toString(), '*******');
assert.equal(new Buffer('KioqKioqKio=', 'base64').toString(), '********');
assert.equal(new Buffer('KioqKioqKioq', 'base64').toString(), '*********');
assert.equal(new Buffer('KioqKioqKioqKg==', 'base64').toString(),
'**********');
assert.equal(new Buffer('KioqKioqKioqKio=', 'base64').toString(),
'***********');
assert.equal(new Buffer('KioqKioqKioqKioq', 'base64').toString(),
'************');
assert.equal(new Buffer('KioqKioqKioqKioqKg==', 'base64').toString(),
'*************');
assert.equal(new Buffer('KioqKioqKioqKioqKio=', 'base64').toString(),
'**************');
assert.equal(new Buffer('KioqKioqKioqKioqKioq', 'base64').toString(),
'***************');
if (n < list[0].length) {
// just take a part of the first list item.
// slice is the same for buffers and strings.
var buf = list[0];
ret = buf.slice(0, n);
list[0] = buf.slice(n);
} else if (n === list[0].length) {
// first list is a perfect match
ret = list.shift();
} else {
// complex case.
// we have enough to cover it, but it spans past the first buffer.
if (stringMode)
ret = '';
else
ret = new Buffer(n);
var c = 0;
for (var i = 0, l = list.length; i < l && c < n; i++) {
var buf = list[0];
var cpy = Math.min(n - c, buf.length);
if (stringMode)
ret += buf.slice(0, cpy);
else
buf.copy(ret, c, 0, cpy);
if (cpy < buf.length)
list[0] = buf.slice(cpy);
else
list.shift();
self.onReply.call(self.thisArg, reply);
}
self.clearState();
self.skip = 1; // Skip LF
};
switch (inbound[i]) {
case CR:
switch (this.type) {
case INLINE:
case ERROR:
// CR denotes end of the inline/error value.
// +OK\r\n
// ^
var inlineBuf = new Buffer(this.valueBufferLen);
this.valueBuffer.copy(inlineBuf, 0, 0, this.valueBufferLen);
maybeCallbackWithReply({ type:this.type, value:inlineBuf });
break;
case INTEGER:
// CR denotes the end of the integer value.
// :42\r\n
// ^
var n = parseInt(this.valueBuffer.asciiSlice(0, this.valueBufferLen), 10);
maybeCallbackWithReply({ type:INTEGER, value:n });
break;
case BULK:
if (this.bulkLengthExpected == null) {
// CR denotes end of first line of a bulk reply,
// Bignum, assume big endian
if (typeof num !== 'number' && !Buffer.isBuffer(num)) {
var numArray = num.toArray();
if (!num.sign && numArray[0] & 0x80) {
numArray.unshift(0);
}
num = new Buffer(numArray);
}
if (Buffer.isBuffer(num)) {
var size = num.length;
if (num.length === 0)
size++;
var out = new Buffer(size);
num.copy(out);
if (num.length === 0)
out[0] = 0
return this._createEncoderBuffer(out);
}
if (num < 0x80)
return this._createEncoderBuffer(num);
if (num < 0x100)
return this._createEncoderBuffer([0, num]);
var size = 1;
for (var i = num; i >= 0x100; i >>= 8)
size++;
if (options.distributionKey !== null) {
console.log('Distribution key expired, requesting new distribution key as well...');
} else {
console.log('No distribution key yet, requesting new distribution key as well...');
}
reqMsgType = msgType.SESSION_KEY_REQ_IN_PUB_ENC;
sessionKeyReqBuf = serializeSessionKeyReq(sessionKeyReq);
reqPayload = new buffer.Buffer(
crypto.publicEncryptAndSign(sessionKeyReqBuf.getArray(),
options.authPublicKey, options.entityPrivateKey,
options.publicKeyCryptoSpec.cipher, options.publicKeyCryptoSpec.sign));
} else {
console.log('distribution key available! ');
reqMsgType = msgType.SESSION_KEY_REQ;
sessionKeyReqBuf = serializeSessionKeyReq(sessionKeyReq);
var encryptedSessionKeyReqBuf = new buffer.Buffer(
symmetricEncryptAuthenticate(sessionKeyReqBuf, options.distributionKey, options.distributionCryptoSpec));
reqPayload = serializeSessionKeyReqWithDistributionKey(options.entityName,
encryptedSessionKeyReqBuf);
}
var toSend = exports.serializeIoTSP({
msgType: reqMsgType,
payload: reqPayload
}).getArray();
authClientSocket.send(toSend);
} else {
console.log('Session key response arrived.');
handleSessionKeyResponse(options, obj, myNonce, sessionKeyResponseCallback, callbackParameters);
authClientSocket.close();
}
});
authClientSocket.on('close', function () {
function (err, json) {
if (err) return callback(err, null);
callback(null, [
new Buffer(JSON.stringify(json), 'utf8'),
{ 'Content-Type': 'text/javascript; charset=utf-8' },
{ keys: json.keys }
]);
});
} else {
return new Promise(function (resolve, reject) {
if (self._destroyed) {
reject()
} else if(self.push(new Buffer(chunk))) {
resolve()
} else {
self._resumeFetch = resolve
}
})
},
var transport_encode = function(documents, headers) {
var rb = new Buffer(1024);
if(headers) {
rb = transport_header(rb, headers);
}
documents.map(function(el) {
rb = write_buf(rb, el.type);
rb = write_buf(rb,'\u0000');
rb.writeUInt32LE(el.contents.length, rb._pos);
rb._pos += 4;
rb = write_buf(rb, el.contents);
});
return rb.slice(0, rb._pos);
};
pad: function (dataBytes, nBytesPerBlock) {
var nPaddingBytes = nBytesPerBlock - dataBytes.length % nBytesPerBlock;
var zeroBytes = new Buffer(nPaddingBytes).fill(0x00);
return Buffer.concat([ dataBytes, zeroBytes ]);
},
_packReserved() {
let buf = new buffer.Buffer(1)
buf.writeUInt8(0, 0)
return buf
}