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.

server_side_sorting_response_control.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. var assert = require('assert-plus');
  2. var util = require('util');
  3. var asn1 = require('asn1');
  4. var Control = require('./control');
  5. var CODES = require('../errors/codes');
  6. ///--- Globals
  7. var BerReader = asn1.BerReader;
  8. var BerWriter = asn1.BerWriter;
  9. var VALID_CODES = [
  10. CODES.LDAP_SUCCESS,
  11. CODES.LDAP_OPERATIONS_ERROR,
  12. CODES.LDAP_TIME_LIMIT_EXCEEDED,
  13. CODES.LDAP_STRONG_AUTH_REQUIRED,
  14. CODES.LDAP_ADMIN_LIMIT_EXCEEDED,
  15. CODES.LDAP_NO_SUCH_ATTRIBUTE,
  16. CODES.LDAP_INAPPROPRIATE_MATCHING,
  17. CODES.LDAP_INSUFFICIENT_ACCESS_RIGHTS,
  18. CODES.LDAP_BUSY,
  19. CODES.LDAP_UNWILLING_TO_PERFORM,
  20. CODES.LDAP_OTHER
  21. ];
  22. function ServerSideSortingResponseControl(options) {
  23. assert.optionalObject(options);
  24. options = options || {};
  25. options.type = ServerSideSortingResponseControl.OID;
  26. options.criticality = false;
  27. if (options.value) {
  28. if (Buffer.isBuffer(options.value)) {
  29. this.parse(options.value);
  30. } else if (typeof (options.value) === 'object') {
  31. if (VALID_CODES.indexOf(options.value.result) === -1) {
  32. throw new Error('Invalid result code');
  33. }
  34. if (options.value.failedAttribute &&
  35. typeof (options.value.failedAttribute) !== 'string') {
  36. throw new Error('failedAttribute must be String');
  37. }
  38. this._value = options.value;
  39. } else {
  40. throw new TypeError('options.value must be a Buffer or Object');
  41. }
  42. options.value = null;
  43. }
  44. Control.call(this, options);
  45. }
  46. util.inherits(ServerSideSortingResponseControl, Control);
  47. Object.defineProperties(ServerSideSortingResponseControl.prototype, {
  48. value: {
  49. get: function () { return this._value || {}; },
  50. configurable: false
  51. }
  52. });
  53. ServerSideSortingResponseControl.prototype.parse = function parse(buffer) {
  54. assert.ok(buffer);
  55. var ber = new BerReader(buffer);
  56. if (ber.readSequence(0x30)) {
  57. this._value = {};
  58. this._value.result = ber.readEnumeration();
  59. if (ber.peek() == 0x80) {
  60. this._value.failedAttribute = ber.readString(0x80);
  61. }
  62. return true;
  63. }
  64. return false;
  65. };
  66. ServerSideSortingResponseControl.prototype._toBer = function (ber) {
  67. assert.ok(ber);
  68. if (!this._value || this.value.length === 0)
  69. return;
  70. var writer = new BerWriter();
  71. writer.startSequence(0x30);
  72. writer.writeEnumeration(this.value.result);
  73. if (this.value.result !== CODES.LDAP_SUCCESS && this.value.failedAttribute) {
  74. writer.writeString(this.value.failedAttribute, 0x80);
  75. }
  76. writer.endSequence();
  77. ber.writeBuffer(writer.buffer, 0x04);
  78. };
  79. ServerSideSortingResponseControl.prototype._json = function (obj) {
  80. obj.controlValue = this.value;
  81. return obj;
  82. };
  83. ServerSideSortingResponseControl.OID = '1.2.840.113556.1.4.474';
  84. ///--- Exports
  85. module.exports = ServerSideSortingResponseControl;