Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

entry_change_notification_control.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. var assert = require('assert-plus');
  2. var util = require('util');
  3. var asn1 = require('asn1');
  4. var Control = require('./control');
  5. ///--- Globals
  6. var BerReader = asn1.BerReader;
  7. var BerWriter = asn1.BerWriter;
  8. ///--- API
  9. function EntryChangeNotificationControl(options) {
  10. assert.optionalObject(options);
  11. options = options || {};
  12. options.type = EntryChangeNotificationControl.OID;
  13. if (options.value) {
  14. if (Buffer.isBuffer(options.value)) {
  15. this.parse(options.value);
  16. } else if (typeof (options.value) === 'object') {
  17. this._value = options.value;
  18. } else {
  19. throw new TypeError('options.value must be a Buffer or Object');
  20. }
  21. options.value = null;
  22. }
  23. Control.call(this, options);
  24. }
  25. util.inherits(EntryChangeNotificationControl, Control);
  26. Object.defineProperties(EntryChangeNotificationControl.prototype, {
  27. value: {
  28. get: function () { return this._value || {}; },
  29. configurable: false
  30. }
  31. });
  32. EntryChangeNotificationControl.prototype.parse = function parse(buffer) {
  33. assert.ok(buffer);
  34. var ber = new BerReader(buffer);
  35. if (ber.readSequence()) {
  36. this._value = {
  37. changeType: ber.readInt()
  38. };
  39. // if the operation was moddn, then parse the optional previousDN attr
  40. if (this._value.changeType === 8)
  41. this._value.previousDN = ber.readString();
  42. this._value.changeNumber = ber.readInt();
  43. return true;
  44. }
  45. return false;
  46. };
  47. EntryChangeNotificationControl.prototype._toBer = function (ber) {
  48. assert.ok(ber);
  49. if (!this._value)
  50. return;
  51. var writer = new BerWriter();
  52. writer.startSequence();
  53. writer.writeInt(this.value.changeType);
  54. if (this.value.previousDN)
  55. writer.writeString(this.value.previousDN);
  56. writer.writeInt(parseInt(this.value.changeNumber, 10));
  57. writer.endSequence();
  58. ber.writeBuffer(writer.buffer, 0x04);
  59. };
  60. EntryChangeNotificationControl.prototype._json = function (obj) {
  61. obj.controlValue = this.value;
  62. return obj;
  63. };
  64. EntryChangeNotificationControl.OID = '2.16.840.1.113730.3.4.7';
  65. ///--- Exports
  66. module.exports = EntryChangeNotificationControl;