File: //usr/lib/python3/dist-packages/twisted/words/protocols/jabber/__pycache__/xmlstream.cpython-38.pyc
U
s�@g� � @ s� d Z ddlmZmZ ddlmZ ddlmZ ddlm Z m
Z
ddlmZm
Z
ddlmZ ddlmZmZmZ dd lmZmZmZmZ dd
lmZmZmZ ddlmZmZ ddl m!Z! dd
l m"Z" ddl m#Z# ddl m$Z$ zddlm%Z% W n e&k
�r dZ%Y nX e%�re%j'�sdZ%ed�Z(ed�Z)dZ*dZ+e,� Z-dd� Z.G dd� d�Z/G dd� de/�Z0G dd� de/�Z1G dd� de2�Z3e
ej4�G d d!� d!e,��Z5G d"d#� d#e2�Z6G d$d%� d%e6�Z7G d&d'� d'e6�Z8G d(d)� d)e6�Z9G d*d+� d+e5�Z:G d,d-� d-ej;�Z;G d.d/� d/ej<�Z<G d0d1� d1ej=e
j>�Z?G d2d3� d3e2�Z@d4d5� ZAG d6d7� d7ejB�ZCdId8d9�ZDe
ejE�G d:d;� d;e,��ZFe
ejG�G d<d=� d=e,��ZHG d>d?� d?eH�ZIdd!ddd@d7ddAdBdCdDdEdFdGdHd?d#d%d+d)d'd3d;d=d-d/d1dd9d5gZJdS )Ja2
XMPP XML Streams
Building blocks for setting up XML Streams, including helping classes for
doing authentication on either client or server side, and working with XML
Stanzas.
@var STREAM_AUTHD_EVENT: Token dispatched by L{Authenticator} when the
stream has been completely initialized
@type STREAM_AUTHD_EVENT: L{str}.
@var INIT_FAILED_EVENT: Token dispatched by L{Authenticator} when the
stream has failed to be initialized
@type INIT_FAILED_EVENT: L{str}.
@var Reset: Token to signal that the XML stream has been reset.
@type Reset: Basic object.
� )�absolute_import�division)�hexlify)�sha1)�directlyProvides�implementer)�defer�protocol)�ConnectionLost)�failure�log� randbytes)�intern� iteritems�
itervalues�unicode)�error�ijabber�jid)�domish� xmlstream)�STREAM_CONNECTED_EVENT)�STREAM_START_EVENT)�STREAM_END_EVENT)�STREAM_ERROR_EVENT)�sslNz//event/stream/authdz//event/xmpp/initfailedz http://etherx.jabber.org/streamszurn:ietf:params:xml:ns:xmpp-tlsc C sB t | t�std��t |t�s$td��d| |f }t|�d���� S )z�
Create a SHA1-digest string of a session identifier and password.
@param sid: The stream session identifier.
@type sid: C{unicode}.
@param password: The password to be hashed.
@type password: C{unicode}.
z/The session identifier must be a unicode objectz%The password must be a unicode objectz%s%szutf-8)�
isinstancer � TypeErrorr �encodeZ hexdigest)�sidZpassword�input� r! �J/usr/lib/python3/dist-packages/twisted/words/protocols/jabber/xmlstream.py�hashPassword9 s
r# c @ s0 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
S )�
AuthenticatoraD
Base class for business logic of initializing an XmlStream
Subclass this object to enable an XmlStream to initialize and authenticate
to different types of stream hosts (such as clients, components, etc.).
Rules:
1. The Authenticator MUST dispatch a L{STREAM_AUTHD_EVENT} when the
stream has been completely initialized.
2. The Authenticator SHOULD reset all state information when
L{associateWithStream} is called.
3. The Authenticator SHOULD override L{streamStarted}, and start
initialization there.
@type xmlstream: L{XmlStream}
@ivar xmlstream: The XmlStream that needs authentication
@note: the term authenticator is historical. Authenticators perform
all steps required to prepare the stream for the exchange
of XML stanzas.
c C s
d | _ d S �N�r ��selfr! r! r"