How to use the asn1.Ber.Integer function in asn1

To help you get started, we’ve selected a few asn1 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 mscdex / ssh2-streams / lib / ssh.js View on Github external
if (p === false)
      return false;
    var q = readString(info.hostkey, info.hostkey._pos, self, callback);
    if (q === false)
      return false;
    var g = readString(info.hostkey, info.hostkey._pos, self, callback);
    if (g === false)
      return false;
    var y = readString(info.hostkey, info.hostkey._pos, self, callback);
    if (y === false)
      return false;

    asnWriter.startSequence();
    asnWriter.writeOID('1.2.840.10040.4.1');
    asnWriter.startSequence();
    asnWriter.writeBuffer(p, Ber.Integer);
    asnWriter.writeBuffer(q, Ber.Integer);
    asnWriter.writeBuffer(g, Ber.Integer);
    asnWriter.endSequence();
    asnWriter.endSequence();

    asnWriter.startSequence(Ber.BitString);
    asnWriter.writeByte(0x00);
    asnWriter.writeBuffer(y, Ber.Integer);
    asnWriter.endSequence();

    if (rawsig.length <= 40) {
      // change bare signature r and s values to ASN.1 DER values for OpenSSL
      var asnSigWriter = new Ber.Writer();
      asnSigWriter.startSequence();
      asnSigWriter.writeBuffer(rawsig.slice(0, 20), Ber.Integer);
      asnSigWriter.writeBuffer(rawsig.slice(20), Ber.Integer);
github mscdex / ssh2-streams / lib / keyParser.js View on Github external
function genOpenSSLDSAPub(p, q, g, y) {
  var asnWriter = new Ber.Writer();
  asnWriter.startSequence();
    // algorithm
    asnWriter.startSequence();
      asnWriter.writeOID('1.2.840.10040.4.1'); // id-dsa
      // algorithm parameters
      asnWriter.startSequence();
        asnWriter.writeBuffer(p, Ber.Integer);
        asnWriter.writeBuffer(q, Ber.Integer);
        asnWriter.writeBuffer(g, Ber.Integer);
      asnWriter.endSequence();
    asnWriter.endSequence();

    // subjectPublicKey
    asnWriter.startSequence(Ber.BitString);
      asnWriter.writeByte(0x00);
      asnWriter.writeBuffer(y, Ber.Integer);
    asnWriter.endSequence();
  asnWriter.endSequence();
  return makePEM('PUBLIC', asnWriter.buffer);
}
github mscdex / ssh2 / lib / Connection.js View on Github external
asnWriter.writeByte(0x00);
    asnWriter.startSequence();
    asnWriter.writeBuffer(n, Ber.Integer);
    asnWriter.writeBuffer(e, Ber.Integer);
    asnWriter.endSequence();
    asnWriter.endSequence();
  } else {
    var p = Parser.readString(info.hostkey, info.hostkey._pos),
        q = Parser.readString(info.hostkey, info.hostkey._pos),
        g = Parser.readString(info.hostkey, info.hostkey._pos),
        y = Parser.readString(info.hostkey, info.hostkey._pos);

    asnWriter.startSequence();
    asnWriter.writeOID('1.2.840.10040.4.1');
    asnWriter.startSequence();
    asnWriter.writeBuffer(p, Ber.Integer);
    asnWriter.writeBuffer(q, Ber.Integer);
    asnWriter.writeBuffer(g, Ber.Integer);
    asnWriter.endSequence();
    asnWriter.endSequence();

    asnWriter.startSequence(Ber.BitString);
    asnWriter.writeByte(0x00);
    asnWriter.writeBuffer(y, Ber.Integer);
    asnWriter.endSequence();

    if (rawsig.length <= 40) {
      // change bare signature r and s values to ASN.1 DER values for OpenSSL
      var asnSigWriter = new Ber.Writer();
      asnSigWriter.startSequence();
      asnSigWriter.writeBuffer(rawsig.slice(0, 20), Ber.Integer);
      asnSigWriter.writeBuffer(rawsig.slice(20), Ber.Integer);
github Equals182 / eqFTP / node / node_modules / ssh2 / node_modules / ssh2-streams / lib / utils.js View on Github external
return false;

  var asnWriter = new Ber.Writer();
  asnWriter.startSequence();
    // algorithm
    asnWriter.startSequence();
      asnWriter.writeOID('1.2.840.113549.1.1.1'); // rsaEncryption
      // algorithm parameters (RSA has none)
      asnWriter.writeNull();
    asnWriter.endSequence();

    // subjectPublicKey
    asnWriter.startSequence(Ber.BitString);
      asnWriter.writeByte(0x00);
      asnWriter.startSequence();
        asnWriter.writeBuffer(n, Ber.Integer);
        asnWriter.writeBuffer(e, Ber.Integer);
      asnWriter.endSequence();
    asnWriter.endSequence();
  asnWriter.endSequence();
  return asnWriter.buffer;
}
github mscdex / ssh2-streams / lib / ssh.js View on Github external
var q = readString(info.hostkey, info.hostkey._pos, self, callback);
    if (q === false)
      return false;
    var g = readString(info.hostkey, info.hostkey._pos, self, callback);
    if (g === false)
      return false;
    var y = readString(info.hostkey, info.hostkey._pos, self, callback);
    if (y === false)
      return false;

    asnWriter.startSequence();
    asnWriter.writeOID('1.2.840.10040.4.1');
    asnWriter.startSequence();
    asnWriter.writeBuffer(p, Ber.Integer);
    asnWriter.writeBuffer(q, Ber.Integer);
    asnWriter.writeBuffer(g, Ber.Integer);
    asnWriter.endSequence();
    asnWriter.endSequence();

    asnWriter.startSequence(Ber.BitString);
    asnWriter.writeByte(0x00);
    asnWriter.writeBuffer(y, Ber.Integer);
    asnWriter.endSequence();

    if (rawsig.length <= 40) {
      // change bare signature r and s values to ASN.1 DER values for OpenSSL
      var asnSigWriter = new Ber.Writer();
      asnSigWriter.startSequence();
      asnSigWriter.writeBuffer(rawsig.slice(0, 20), Ber.Integer);
      asnSigWriter.writeBuffer(rawsig.slice(20), Ber.Integer);
      asnSigWriter.endSequence();
      rawsig = asnSigWriter.buffer;
github Equals182 / eqFTP / node / node_modules / ssh2 / node_modules / ssh2-streams / lib / utils.js View on Github external
var g = readString(key, key._pos, self, callback);
  if (g === false)
    return false;
  var y = readString(key, key._pos, self, callback);
  if (y === false)
    return false;

  var asnWriter = new Ber.Writer();
  asnWriter.startSequence();
    // algorithm
    asnWriter.startSequence();
      asnWriter.writeOID('1.2.840.10040.4.1'); // id-dsa
      // algorithm parameters
      asnWriter.startSequence();
        asnWriter.writeBuffer(p, Ber.Integer);
        asnWriter.writeBuffer(q, Ber.Integer);
        asnWriter.writeBuffer(g, Ber.Integer);
      asnWriter.endSequence();
    asnWriter.endSequence();

    // subjectPublicKey
    asnWriter.startSequence(Ber.BitString);
      asnWriter.writeByte(0x00);
      asnWriter.writeBuffer(y, Ber.Integer);
    asnWriter.endSequence();
  asnWriter.endSequence();
  return asnWriter.buffer;
}
github mscdex / ssh2-streams / lib / keyParser.js View on Github external
function genOpenSSLDSAPriv(p, q, g, y, x) {
  var asnWriter = new Ber.Writer();
  asnWriter.startSequence();
    asnWriter.writeInt(0x00, Ber.Integer);
    asnWriter.writeBuffer(p, Ber.Integer);
    asnWriter.writeBuffer(q, Ber.Integer);
    asnWriter.writeBuffer(g, Ber.Integer);
    asnWriter.writeBuffer(y, Ber.Integer);
    asnWriter.writeBuffer(x, Ber.Integer);
  asnWriter.endSequence();
  return makePEM('DSA PRIVATE', asnWriter.buffer);
}
github joyent / node-snmpjs / lib / protocol / data.js View on Github external
}
		if (typeof (v) !== 'number' || v % 1 !== 0)
			throw new TypeError('value is of incompatible type');
		if (v < MIN_INT32 || v > MAX_INT32) {
			throw new RangeError('value ' + v +
			    ' out of range for ' + self._typename);
		}
		self._value = v >> 0;
	});

	if (value !== undefined)
		this.value = value;
}
util.inherits(SnmpInteger, SnmpData);

SnmpInteger.prototype._tag = ASN1.Integer;
SnmpInteger.prototype._typename = 'Integer';

SnmpInteger.prototype.encode = function _integer_encode(writer) {
	writer.writeInt(this._value, this._tag);
};

function
SnmpOctetString(value)
{
	var self = this;

	SnmpData.call(this);

	this.__defineSetter__('value', function (v) {
		if (typeof (v) === 'object' && (v instanceof ASN1.Reader)) {
			var b;
github mscdex / ssh2-streams / lib / utils.js View on Github external
asnWriter.endSequence();
      return asnWriter.buffer;
    case 'ecdsa-sha2-nistp256':
    case 'ecdsa-sha2-nistp384':
    case 'ecdsa-sha2-nistp521':
      var r = readString(sig, 0, self, callback);
      if (r === false)
        return false;
      var s = readString(sig, sig._pos, self, callback);
      if (s === false)
        return false;

      asnWriter = new Ber.Writer();
      asnWriter.startSequence();
      asnWriter.writeBuffer(r, Ber.Integer);
      asnWriter.writeBuffer(s, Ber.Integer);
      asnWriter.endSequence();
      return asnWriter.buffer;
    default:
      return sig;
  }
}
github mscdex / ssh2-streams / lib / utils.js View on Github external
asnWriter.writeBuffer(s, Ber.Integer);
      asnWriter.endSequence();
      return asnWriter.buffer;
    case 'ecdsa-sha2-nistp256':
    case 'ecdsa-sha2-nistp384':
    case 'ecdsa-sha2-nistp521':
      var r = readString(sig, 0, self, callback);
      if (r === false)
        return false;
      var s = readString(sig, sig._pos, self, callback);
      if (s === false)
        return false;

      asnWriter = new Ber.Writer();
      asnWriter.startSequence();
      asnWriter.writeBuffer(r, Ber.Integer);
      asnWriter.writeBuffer(s, Ber.Integer);
      asnWriter.endSequence();
      return asnWriter.buffer;
    default:
      return sig;
  }
}