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.

persistent_search_control.js 1.9KB

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