#50466 Issue: 50443 - Create a module in lib389 to Convert a byte sequence to a properly escaped for LDAP
Opened 3 months ago by aborah. Modified 2 months ago
aborah/389-ds-base utils  into  master

@@ -1269,3 +1269,16 @@ 

  def display_log_data(data, hide_sensitive=True):

      # Take a dict and mask all the sensitive data

      return {a: display_log_value(a, v, hide_sensitive) for a, v in data.items()}

+ 

+ 

+ def escape_bytes(bytes_value):

+     """ Convert a byte sequence to a properly escaped for LDAP (format BACKSLASH HEX HEX) string"""

+     # copied from https://github.com/cannatag/ldap3/blob/master/ldap3/utils/conv.py

+     if str is not bytes:

+         if isinstance(bytes_value, str):

+             bytes_value = bytearray(bytes_value, encoding='utf-8')

+         escaped = '\\'.join([('%02x' % int(b)) for b in bytes_value])

+     else:

+         escaped = ''

+ 

+     return ('\\' + escaped) if escaped else '' 

\ No newline at end of file

Create a module in lib389 to Convert a byte sequence to a properly escaped for LDAP

Fixes: https://pagure.io/389-ds-base/issue/50443

Author: aborah

Reviewed by: ???

rebased onto 6c75fbe

2 months ago
Metadata