Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _bytes_desc(self):
base = self.dotted_form
if rfc5801 is not None and self._saslname and self._saslname.mech_name:
base = self._saslname.mech_name
if isinstance(base, str):
base = base.encode(_utils._get_encoding())
return base
# where GSS_C_NT_COMPOSITE_EXPORT doesn't trigger
# immediate import logic. However, we can just use
# the normal GSS_C_NT_EXPORT_NAME in this case.
base_name = rname.import_name(token, NameType.export)
else:
# NB(directxman12): some older versions of MIT krb5 don't
# have support for the GSS_C_NT_COMPOSITE_EXPORT, but do
# support composite tokens via GSS_C_NT_EXPORT_NAME.
base_name = rname.import_name(token, NameType.export)
else:
base_name = rname.import_name(token, NameType.export)
elif isinstance(base, rname.Name):
base_name = base
else:
if isinstance(base, str):
base = base.encode(_utils._get_encoding())
base_name = rname.import_name(base, name_type)
return super(Name, cls).__new__(cls, base_name)
def __str__(self):
return bytes(self).decode(_utils._get_encoding())
name_type (OID): the :class:`NameType` to use to display the given
name
Returns:
str: the displayed name
Raises:
OperationUnavailableError
"""
if rname_rfc6680 is None:
raise NotImplementedError("Your GSSAPI implementation does not "
"support RFC 6680 (the GSSAPI naming "
"extensions)")
return rname_rfc6680.display_name_ext(self, name_type).decode(
_utils._get_encoding())
def __unicode__(self):
return self._bytes_desc().decode(_utils._get_encoding())
def __getitem__(self, key):
if isinstance(key, str):
key = key.encode(_utils._get_encoding())
res = rname_rfc6680.get_name_attribute(self._name, key)
return tuples.GetNameAttributeResult(frozenset(res.values),
frozenset(res.display_values),
res.authenticated,
res.complete)
Args:
name (str): SASL name of the desired mechanism
Returns:
Mechanism: the desired mechanism
Raises:
GSSError
:requires-ext:`rfc5801`
"""
if rfc5801 is None:
raise NotImplementedError("Your GSSAPI implementation does not "
"have support for RFC 5801")
if isinstance(name, str):
name = name.encode(_utils._get_encoding())
m = rfc5801.inquire_mech_for_saslname(name)
return cls(m)
def __str__(self):
return self._bytes_desc().decode(_utils._get_encoding())