How to use the slixmpp.util.bytes function in slixmpp

To help you get started, we’ve selected a few slixmpp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github poezio / slixmpp / slixmpp / util / sasl / mechanisms.py View on Github external
def parse(self, challenge=b''):
        data = {}
        var_name = b''
        var_value = b''

        # States: var, new_var, end, quote, escaped_quote
        state = 'var'


        for char in challenge:
            char = bytes([char])

            if state == 'var':
                if char.isspace():
                    continue
                if char == b'=':
                    state = 'value'
                else:
                    var_name += char
            elif state == 'value':
                if char == b'"':
                    state = 'quote'
                elif char == b',':
                    if var_name:
                        data[var_name.decode('utf-8')] = var_value
                    var_name = b''
                    var_value = b''
github poezio / slixmpp / slixmpp / features / feature_mechanisms / stanza / success.py View on Github external
def set_value(self, values):
        if values:
            self.xml.text = bytes(base64.b64encode(values)).decode('utf-8')
        else:
            self.xml.text = '='
github poezio / slixmpp / slixmpp / plugins / xep_0047 / stanza.py View on Github external
def to_b64(data):
    return bytes(base64.b64encode(bytes(data))).decode('utf-8')
github poezio / slixmpp / slixmpp / util / sasl / mechanisms.py View on Github external
def A2(self, prefix=b''):
        a2 = prefix + b':' + self.digest_uri()
        if self.qop in (b'auth-int', b'auth-conf'):
            a2 += b':00000000000000000000000000000000'
        return bytes(a2)
github poezio / slixmpp / slixmpp / features / feature_mechanisms / stanza / auth.py View on Github external
def set_value(self, values):
        if not self['mechanism'] in self.plain_mechs:
            if values:
                self.xml.text = bytes(base64.b64encode(values)).decode('utf-8')
            elif values == b'':
                self.xml.text = '='
        else:
            self.xml.text = bytes(values).decode('utf-8')
github poezio / slixmpp / slixmpp / util / sasl / mechanisms.py View on Github external
'username': quote(self.credentials['username']),
            'authzid': quote(self.credentials['authzid']),
            'realm': quote(self.credentials['realm']),
            'nonce': quote(self.nonce),
            'cnonce': quote(self.cnonce),
            'nc': bytes('%08x' % self.nonce_count),
            'qop': self.qop,
            'digest-uri': quote(self.digest_uri()),
            'response': self.response(b'AUTHENTICATE'),
            'maxbuf': self.maxbuf,
            'charset': 'utf-8'
        }
        resp = b''
        for key, value in data.items():
            if value and value != b'""':
                resp += b',' + bytes(key) + b'=' + bytes(value)
        return resp[1:]
github poezio / slixmpp / slixmpp / util / sasl / mechanisms.py View on Github external
def process(self, challenge=b''):
        if not challenge:
            return None

        username = self.credentials['username']
        password = self.credentials['password']

        mac = hmac.HMAC(key=password, digestmod=self.hash)
        mac.update(challenge)

        return username + b' ' + bytes(mac.hexdigest())
github poezio / slixmpp / slixmpp / util / sasl / mechanisms.py View on Github external
def A1(self):
        username = self.credentials['username']
        password = self.credentials['password']
        authzid = self.credentials['authzid']
        realm = self.credentials['realm']

        a1 = self.hash()
        a1.update(username + b':' + realm + b':' + password)
        a1 = a1.digest()
        a1 += b':' + self.nonce + b':' + self.cnonce
        if authzid:
            a1 += b':' + authzid

        return bytes(a1)
github poezio / slixmpp / slixmpp / plugins / xep_0258 / stanza.py View on Github external
def set_value(self, value):
        self.xml.text = ''
        if value:
            self.xml.text = b64encode(bytes(value))
github poezio / slixmpp / slixmpp / features / feature_mechanisms / stanza / auth.py View on Github external
def get_value(self):
        if not self['mechanism'] in self.plain_mechs:
            return base64.b64decode(bytes(self.xml.text))
        else:
            return self.xml.text