Development of an internal social media platform with personalised dashboards for students
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.

dds.py 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # -*- coding: utf-8 -*-
  2. """
  3. ldap.extop.dds - Classes for Dynamic Entries extended operations
  4. (see RFC 2589)
  5. See https://www.python-ldap.org/ for details.
  6. """
  7. from ldap.extop import ExtendedRequest,ExtendedResponse
  8. # Imports from pyasn1
  9. from pyasn1.type import namedtype,univ,tag
  10. from pyasn1.codec.der import encoder,decoder
  11. from pyasn1_modules.rfc2251 import LDAPDN
  12. class RefreshRequest(ExtendedRequest):
  13. requestName = '1.3.6.1.4.1.1466.101.119.1'
  14. defaultRequestTtl = 86400
  15. class RefreshRequestValue(univ.Sequence):
  16. componentType = namedtype.NamedTypes(
  17. namedtype.NamedType(
  18. 'entryName',
  19. LDAPDN().subtype(
  20. implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,0)
  21. )
  22. ),
  23. namedtype.NamedType(
  24. 'requestTtl',
  25. univ.Integer().subtype(
  26. implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,1)
  27. )
  28. ),
  29. )
  30. def __init__(self,requestName=None,entryName=None,requestTtl=None):
  31. self.entryName = entryName
  32. self.requestTtl = requestTtl or self.defaultRequestTtl
  33. def encodedRequestValue(self):
  34. p = self.RefreshRequestValue()
  35. p.setComponentByName(
  36. 'entryName',
  37. LDAPDN(self.entryName).subtype(
  38. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple,0)
  39. )
  40. )
  41. p.setComponentByName(
  42. 'requestTtl',
  43. univ.Integer(self.requestTtl).subtype(
  44. implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,1)
  45. )
  46. )
  47. return encoder.encode(p)
  48. class RefreshResponse(ExtendedResponse):
  49. responseName = '1.3.6.1.4.1.1466.101.119.1'
  50. class RefreshResponseValue(univ.Sequence):
  51. componentType = namedtype.NamedTypes(
  52. namedtype.NamedType(
  53. 'responseTtl',
  54. univ.Integer().subtype(
  55. implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,1)
  56. )
  57. )
  58. )
  59. def decodeResponseValue(self,value):
  60. respValue,_ = decoder.decode(value,asn1Spec=self.RefreshResponseValue())
  61. self.responseTtl = int(respValue.getComponentByName('responseTtl'))
  62. return self.responseTtl