Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
};
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);
}
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')
}
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)
function checkIsPrivateKey(key) {
if (Buffer.isBuffer(key)) {
return;
}
if (typeof key === 'string') {
return;
}
if (typeof key === 'object') {
return;
}
throw typeError(MSG_INVALID_SIGNER_KEY);
};
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;
}
},
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;
}
function byteLength (bufOrString) {
if (!bufOrString) return 0
else if (Buffer.isBuffer(bufOrString)) return bufOrString.length
else return Buffer.byteLength(bufOrString)
}
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) {
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)
}