abandon-request.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. 'use strict'
  2. const LdapMessage = require('../ldap-message')
  3. const Protocol = require('@ldapjs/protocol')
  4. const warning = require('../deprecations')
  5. /**
  6. * Implements the abandon request message as described in
  7. * https://www.rfc-editor.org/rfc/rfc4511.html#section-4.11
  8. */
  9. class AbandonRequest extends LdapMessage {
  10. #abandonId
  11. /**
  12. * @typedef {LdapMessageOptions} AbandonRequestOptions
  13. * @property {number} [abandonId=0] The message id of the request to abandon.
  14. */
  15. /**
  16. * @param {AbandonRequestOptions} [options]
  17. */
  18. constructor (options = {}) {
  19. options.protocolOp = Protocol.operations.LDAP_REQ_ABANDON
  20. super(options)
  21. const abandonId = options.abandonId || options.abandonID || 0
  22. if (options.abandonID) {
  23. warning.emit('LDAP_MESSAGE_DEP_003')
  24. }
  25. this.#abandonId = abandonId
  26. }
  27. /**
  28. * The identifier for the request that the instance will request be abandoned.
  29. *
  30. * @type {number}
  31. */
  32. get abandonId () {
  33. return this.#abandonId
  34. }
  35. /**
  36. * Use {@link abandonId} instead.
  37. *
  38. * @deprecated
  39. */
  40. get abandonID () {
  41. warning.emit('LDAP_MESSAGE_DEP_003')
  42. return this.#abandonId
  43. }
  44. /**
  45. * The name of the request type.
  46. *
  47. * @type {string}
  48. */
  49. get type () {
  50. return 'AbandonRequest'
  51. }
  52. /**
  53. * Internal use only.
  54. *
  55. * @param {import('@ldapjs/asn1').BerWriter} ber
  56. *
  57. * @returns {import('@ldapjs/asn1').BerWriter}
  58. */
  59. _toBer (ber) {
  60. ber.writeInt(this.#abandonId, Protocol.operations.LDAP_REQ_ABANDON)
  61. return ber
  62. }
  63. /**
  64. * Internal use only.
  65. *
  66. * @param {object}
  67. *
  68. * @returns {object}
  69. */
  70. _pojo (obj = {}) {
  71. obj.abandonId = this.#abandonId
  72. return obj
  73. }
  74. /**
  75. * Implements the standardized `parseToPojo` method.
  76. *
  77. * @see LdapMessage.parseToPojo
  78. *
  79. * @param {import('@ldapjs/asn1').BerReader} ber
  80. */
  81. static parseToPojo (ber) {
  82. const protocolOp = ber.peek()
  83. if (protocolOp !== Protocol.operations.LDAP_REQ_ABANDON) {
  84. const op = protocolOp.toString(16).padStart(2, '0')
  85. throw Error(`found wrong protocol operation: 0x${op}`)
  86. }
  87. const abandonId = ber.readInt(Protocol.operations.LDAP_REQ_ABANDON)
  88. return { protocolOp, abandonId }
  89. }
  90. }
  91. module.exports = AbandonRequest