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

To help you get started, we’ve selected a few safe-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 mongodb / node-mongodb-native / lib / gridfs / grid_store.js View on Github external
var _writeNormal = function(self, data, close, options, callback) {
  // If we have a buffer write it using the writeBuffer method
  if (Buffer.isBuffer(data)) {
    return writeBuffer(self, data, close, callback);
  } else {
    return writeBuffer(self, Buffer.from(data, 'binary'), close, callback);
  }
};
github avwo / whistle / lib / util / index.js View on Github external
function toBuffer(buf, charset) {
  if (buf == null || Buffer.isBuffer(buf)) {
    return buf;
  }
  buf += '';
  if (charset && typeof charset === 'string' && !UTF8_RE.test(charset)) {
    try {
      charset = charset.toLowerCase();
      if (charset === 'base64') {
        return Buffer.from(buf, 'base64');
      }
      return iconv.encode(buf, charset);
    } catch (e) {}
  }
  return Buffer.from(buf);
}
github bunsenbrowser / bunsen / www / nodejs-project / node_modules / bittorrent-dht / client.js View on Github external
function toBuffer (str) {
  if (Buffer.isBuffer(str)) return str
  if (typeof str === 'string') return Buffer.from(str, 'hex')
  throw new Error('Pass a buffer or a string')
}
github airgap-it / airgap-coin-lib / src / dependencies / src / pbkdf2-3.0.17 / lib / sync-browser.js View on Github external
function pbkdf2 (password, salt, iterations, keylen, digest) {
  checkParameters(password, salt, iterations, keylen)

  if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding)
  if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding)

  digest = digest || 'sha1'

  var hmac = new Hmac(digest, password, salt.length)

  var DK = Buffer.allocUnsafe(keylen)
  var block1 = Buffer.allocUnsafe(salt.length + 4)
  salt.copy(block1, 0, 0, salt.length)

  var destPos = 0
  var hLen = sizes[digest]
  var l = Math.ceil(keylen / hLen)

  for (var i = 1; i <= l; i++) {
    block1.writeUInt32BE(i, salt.length)
github Azure / dev-spaces / actions / add-review-url / node_modules / jwa / index.js View on Github external
function checkIsPrivateKey(key) {
  if (Buffer.isBuffer(key)) {
    return;
  }

  if (typeof key === 'string') {
    return;
  }

  if (typeof key === 'object') {
    return;
  }

  throw typeError(MSG_INVALID_SIGNER_KEY);
};
github nebulasio / go-nebulas / cmd / console / neb.js / lib / account.js View on Github external
setPrivateKey: function (priv) {
        if (utils.isString(priv) || Buffer.isBuffer(priv)) {
            this.privKey = priv.length === 32 ? priv : Buffer(priv, 'hex');
            this.pubKey = null;
            this.address = null;
        }
    },
github guggero / bip-schnorr / src / bip-schnorr.js View on Github external
function deterministicGetK0(privateKey, message) {
  if (!BigInteger.isBigInteger(privateKey)) {
    throw new Error('privateKey must be a BigInteger');
  }
  if (!Buffer.isBuffer(message)) {
    throw new Error('message must be a Buffer');
  }
  if (message.length !== 32) {
    throw new Error('message must be 32 bytes long');
  }
  check.checkRange(privateKey);

  const h = convert.hash(concat([convert.intToBuffer(privateKey), message]));
  const i = convert.bufferToInt(h);
  const k0 = i.mod(n);
  if (k0.signum() === 0) {
    throw new Error('k0 is zero');
  }
  return k0;
}
github noahziheng / freeiot / firmware / nodejs / node_modules / mqtt-packet / writeToStream.js View on Github external
function byteLength (bufOrString) {
  if (!bufOrString) return 0
  else if (Buffer.isBuffer(bufOrString)) return bufOrString.length
  else return Buffer.byteLength(bufOrString)
}
github enigmampc / secret-contracts / node_modules / browserify-des / index.js View on Github external
function DES (opts) {
  CipherBase.call(this)
  var modeName = opts.mode.toLowerCase()
  var mode = modes[modeName]
  var type
  if (opts.decrypt) {
    type = 'decrypt'
  } else {
    type = 'encrypt'
  }
  var key = opts.key
  if (!Buffer.isBuffer(key)) {
    key = Buffer.from(key)
  }
  if (modeName === 'des-ede' || modeName === 'des-ede-cbc') {
    key = Buffer.concat([key, key.slice(0, 8)])
  }
  var iv = opts.iv
  if (!Buffer.isBuffer(iv)) {
    iv = Buffer.from(iv)
  }
  this._des = mode.create({
    key: key,
    iv: iv,
    type: type
  })
}
DES.prototype._update = function (data) {
github depjs / dep / node_modules / dat-node / node_modules / bittorrent-dht / client.js View on Github external
if (opts.v === undefined) {
    throw new Error('opts.v not given')
  }
  if (opts.v.length >= 1000) {
    throw new Error('v must be less than 1000 bytes in put()')
  }
  if (isMutable && opts.cas !== undefined && typeof opts.cas !== 'number') {
    throw new Error('opts.cas must be an integer if provided')
  }
  if (isMutable && !opts.k) {
    throw new Error('opts.k ed25519 public key required for mutable put')
  }
  if (isMutable && opts.k.length !== 32) {
    throw new Error('opts.k ed25519 public key must be 32 bytes')
  }
  if (isMutable && typeof opts.sign !== 'function' && !Buffer.isBuffer(opts.sig)) {
    throw new Error('opts.sign function or options.sig signature is required for mutable put')
  }
  if (isMutable && opts.salt && opts.salt.length > 64) {
    throw new Error('opts.salt is > 64 bytes long')
  }
  if (isMutable && opts.seq === undefined) {
    throw new Error('opts.seq not provided for a mutable update')
  }
  if (isMutable && typeof opts.seq !== 'number') {
    throw new Error('opts.seq not an integer')
  }

  return this._put(opts, cb)
}