unbind-request.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict'
  2. const LdapMessage = require('../ldap-message')
  3. const { operations } = require('@ldapjs/protocol')
  4. /**
  5. * Implements the unbind request message as described in
  6. * https://www.rfc-editor.org/rfc/rfc4511.html#section-4.3.
  7. */
  8. class UnbindRequest extends LdapMessage {
  9. /**
  10. * @param {LdapMessageOptions} options
  11. */
  12. constructor (options = {}) {
  13. options.protocolOp = operations.LDAP_REQ_UNBIND
  14. super(options)
  15. }
  16. /**
  17. * The name of the request type.
  18. *
  19. * @type {string}
  20. */
  21. get type () {
  22. return 'UnbindRequest'
  23. }
  24. /**
  25. * Internal use only.
  26. *
  27. * @param {import('@ldapjs/asn1').BerWriter} ber
  28. *
  29. * @returns {import('@ldapjs/asn1').BerWriter}
  30. */
  31. _toBer (ber) {
  32. ber.writeString('', operations.LDAP_REQ_UNBIND)
  33. return ber
  34. }
  35. /**
  36. * Internal use only.
  37. *
  38. * @param {object}
  39. *
  40. * @returns {object}
  41. */
  42. _pojo (obj = {}) {
  43. return obj
  44. }
  45. /**
  46. * Implements the standardized `parseToPojo` method.
  47. *
  48. * @see LdapMessage.parseToPojo
  49. *
  50. * @param {import('@ldapjs/asn1').BerReader} ber
  51. */
  52. static parseToPojo (ber) {
  53. const protocolOp = ber.readSequence()
  54. if (protocolOp !== operations.LDAP_REQ_UNBIND) {
  55. const op = protocolOp.toString(16).padStart(2, '0')
  56. throw Error(`found wrong protocol operation: 0x${op}`)
  57. }
  58. return { protocolOp }
  59. }
  60. }
  61. module.exports = UnbindRequest