How to use the safer-buffer.Buffer.isBuffer function in safer-buffer

To help you get started, we’ve selected a few safer-buffer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ashiq-r31 / PWA-Sushi-Hunt / node_modules / sshpk / lib / formats / pem.js View on Github external
m = lines[0].match(/*JSSTYLED*/
		    /^([A-Za-z0-9-]+): (.+)$/);
		if (!m)
			break;
		headers[m[1].toLowerCase()] = m[2];
	}

	var cipher, key, iv;
	if (headers['proc-type']) {
		var parts = headers['proc-type'].split(',');
		if (parts[0] === '4' && parts[1] === 'ENCRYPTED') {
			if (typeof (options.passphrase) === 'string') {
				options.passphrase = Buffer.from(
				    options.passphrase, 'utf-8');
			}
			if (!Buffer.isBuffer(options.passphrase)) {
				throw (new errors.KeyEncryptedError(
				    options.filename, 'PEM'));
			} else {
				parts = headers['dek-info'].split(',');
				assert.ok(parts.length === 2);
				cipher = parts[0].toLowerCase();
				iv = Buffer.from(parts[1], 'hex');
				key = utils.opensslKeyDeriv(cipher, iv,
				    options.passphrase, 1).key;
			}
		}
	}

	/* Chop off the first and last lines */
	lines = lines.slice(0, -1).join('');
	buf = Buffer.from(lines, 'base64');
github joyent / node-bunyan-syslog / lib / sys.js View on Github external
SyslogStream.prototype.write = function write(r) {
        if (!this.writable) {
                throw new Error('SyslogStream has been ended already');
        }

        var h;
        var l;
        var m;
        var t;

        if (Buffer.isBuffer(r)) {
                // expensive, but not expected
                m = r.toString('utf8');
        } else if (typeof (r) === 'object') {
                h = r.hostname;
                l = level(r.level);
                m = JSON.stringify(r, bunyan.safeCycles());
                t = time(r.time);
        } else if (typeof (r) === 'string') {
                m = r;
        } else {
                throw new TypeError('record (Object) required');
        }

        l = (this.facility * 8) + (l !== undefined ? l : level(bunyan.INFO));
        var hdr = sprintf('<%d>%s %s %s[%d]:',
                          l,
github joyent / node-asn1 / lib / ber / reader.js View on Github external
function Reader(data) {
  if (!data || !Buffer.isBuffer(data))
    throw new TypeError('data must be a node Buffer');

  this._buf = data;
  this._size = data.length;

  // These hold the "current" state
  this._len = 0;
  this._offset = 0;
}
github sx1989827 / DOClever / node_modules / sshpk / lib / formats / ssh-private.js View on Github external
'but specifies a cipher other than "none"'));
		}
		break;
	case 'bcrypt':
		var salt = kdfOptsBuf.readBuffer();
		var rounds = kdfOptsBuf.readInt();
		var cinf = utils.opensshCipherInfo(cipher);
		if (bcrypt === undefined) {
			bcrypt = require('bcrypt-pbkdf');
		}

		if (typeof (options.passphrase) === 'string') {
			options.passphrase = Buffer.from(options.passphrase,
			    'utf-8');
		}
		if (!Buffer.isBuffer(options.passphrase)) {
			throw (new errors.KeyEncryptedError(
			    options.filename, 'OpenSSH'));
		}

		var pass = new Uint8Array(options.passphrase);
		var salti = new Uint8Array(salt);
		/* Use the pbkdf to derive both the key and the IV. */
		var out = new Uint8Array(cinf.keySize + cinf.blockSize);
		var res = bcrypt.pbkdf(pass, pass.length, salti, salti.length,
		    out, out.length, rounds);
		if (res !== 0) {
			throw (new Error('bcrypt_pbkdf function returned ' +
			    'failure, parameters invalid'));
		}
		out = Buffer.from(out);
		var ckey = out.slice(0, cinf.keySize);
github joyent / node-sshpk / lib / formats / ssh-private.js View on Github external
'but specifies a cipher other than "none"'));
		}
		break;
	case 'bcrypt':
		var salt = kdfOptsBuf.readBuffer();
		var rounds = kdfOptsBuf.readInt();
		var cinf = utils.opensshCipherInfo(cipher);
		if (bcrypt === undefined) {
			bcrypt = require('bcrypt-pbkdf');
		}

		if (typeof (options.passphrase) === 'string') {
			options.passphrase = Buffer.from(options.passphrase,
			    'utf-8');
		}
		if (!Buffer.isBuffer(options.passphrase)) {
			throw (new errors.KeyEncryptedError(
			    options.filename, 'OpenSSH'));
		}

		var pass = new Uint8Array(options.passphrase);
		var salti = new Uint8Array(salt);
		/* Use the pbkdf to derive both the key and the IV. */
		var out = new Uint8Array(cinf.keySize + cinf.blockSize);
		var res = bcrypt.pbkdf(pass, pass.length, salti, salti.length,
		    out, out.length, rounds);
		if (res !== 0) {
			throw (new Error('bcrypt_pbkdf function returned ' +
			    'failure, parameters invalid'));
		}
		out = Buffer.from(out);
		var ckey = out.slice(0, cinf.keySize);
github joyent / node-sshpk / test / dhe_compat.js View on Github external
test('ecdhe shared secret', function (t) {
	var dh1 = new sshpk_dhe.DiffieHellman(EC_KEY);
	var secret1 = dh1.computeSecret(EC2_KEY.toPublic());
	t.ok(Buffer.isBuffer(secret1));
	t.deepEqual(secret1, Buffer.from(
	    'UoKiio/gnWj4BdV41YvoHu9yhjynGBmphZ1JFbpk30o=', 'base64'));

	var dh2 = new sshpk_dhe.DiffieHellman(EC2_KEY);
	var secret2 = dh2.computeSecret(EC_KEY.toPublic());
	t.deepEqual(secret1, secret2);
	t.end();
});
github joyent / node-sshpk / lib / formats / openssh-cert.js View on Github external
function read(buf, options) {
	if (Buffer.isBuffer(buf))
		buf = buf.toString('ascii');
	var parts = buf.trim().split(/[ \t\n]+/g);
	if (parts.length < 2 || parts.length > 3)
		throw (new Error('Not a valid SSH certificate line'));

	var algo = parts[0];
	var data = parts[1];

	data = Buffer.from(data, 'base64');
	return (fromBuffer(data, algo));
}
github farhadi / node-smpp / lib / pdu.js View on Github external
function PDU(command, options) {
	if (Buffer.isBuffer(command)) {
		return this.fromBuffer(command);
	}
	options = options || {};
	this.command = command;
	this.command_length = 0;
	this.command_id = commands[command].id;
	this.command_status = options.command_status || 0;
	this.sequence_number = options.sequence_number || 0;
	if (this.command_status) {
		return;
	}
	var params = commands[command].params || {};
	for (var key in params) {
		if (key in options) {
			this[key] = options[key];
		} else if ('default' in params[key]) {
github joyent / node-sshpk / lib / formats / pkcs8.js View on Github external
var ks = Object.keys(curve);
		for (j = 0; j < curveNames.length; ++j) {
			c = curveNames[j];
			cd = algs.curves[c];
			var equal = true;
			for (var i = 0; i < ks.length; ++i) {
				var k = ks[i];
				if (cd[k] === undefined)
					continue;
				if (typeof (cd[k]) === 'object' &&
				    cd[k].equals !== undefined) {
					if (!cd[k].equals(curve[k])) {
						equal = false;
						break;
					}
				} else if (Buffer.isBuffer(cd[k])) {
					if (cd[k].toString('binary')
					    !== curve[k].toString('binary')) {
						equal = false;
						break;
					}
				} else {
					if (cd[k] !== curve[k]) {
						equal = false;
						break;
					}
				}
			}
			if (equal) {
				curveName = c;
				break;
			}

safer-buffer

Modern Buffer API polyfill without footguns

MIT
Latest version published 6 years ago

Package Health Score

65 / 100
Full package analysis

Similar packages