How to use the asn1.Ber.Context 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 joyent / node-snmpjs / lib / protocol / pdu.js View on Github external
SnmpTrapV1PDU.prototype.encode = function (writer) {
	var i;

	writer.startSequence(ASN1.Context | ASN1.Constructor | this._op);
	this._enterprise.encode(writer);
	this._agent_addr.encode(writer);
	this._generic_trap.encode(writer);
	this._specific_trap.encode(writer);
	this._time_stamp.encode(writer);

	writer.startSequence();
	for (i = 0; i < this._varbinds.length; i++)
		this._varbinds[i].encode(writer);
	writer.endSequence();
	writer.endSequence();
};
github joyent / node-snmpjs / lib / protocol / data.js View on Github external
registerType({
			type: t.prototype._typename,
			tag: t.prototype._tag,
			f: t
		});
	});

	/*
	 * These aliases exist so that we can encode inline varbind error status
	 * markers.  The specifications describe these as being of the NULL type
	 * even though they have their own tags (which are in fact values more
	 * than anything, since the value portion of these objects is empty).
	 */
	registerType({
		type: 'Null',
		tag: ASN1.Context | ERRORS.noSuchObject
	});
	registerType({
		type: 'Null',
		tag: ASN1.Context | ERRORS.noSuchInstance
	});
	registerType({
		type: 'Null',
		tag: ASN1.Context | ERRORS.endOfMibView
	});

	Object.keys(ERRORS).forEach(function (e) {
		data.__defineGetter__(e, function () { return (ERRORS[e]); });
	});

	data.isSnmpData = function (d) {
		return ((typeof (d.__snmpjs_magic) == 'string' &&
github joyent / node-snmpjs / lib / protocol / data.js View on Github external
return;
		} else if (typeof (v) === 'number') {
			if (v % 1 !== 0) {
				throw new TypeError('null value ' + v +
				    ' is not an integer');
			}
			if (v < 0 || v > 0x7f) {
				throw new RangeError('null value ' + v +
				    ' is out of range [0, 0x7f]');
			}
			self._tag = ASN1.Context | v;
		} else {
			throw new TypeError('value must be null or a number');
		}
		switch (self._tag) {
		case ASN1.Context | ERRORS.noSuchObject:
			self._value = ERRORS.noSuchObject;
			break;
		case ASN1.Context | ERRORS.noSuchInstance:
			self._value = ERRORS.noSuchInstance;
			break;
		case ASN1.Context | ERRORS.endOfMibView:
			self._value = ERRORS.endOfMibView;
			break;
		case ASN1.Null:
		default:
			self._value = null;
			break;
		}
	});