Commit 14db4017 authored by zimio's avatar zimio
Browse files

update xep-300 to the lastest version

parent 6d228206
......@@ -162,12 +162,12 @@ NS_PUBKEY_PUBKEY = 'urn:xmpp:pubkey:2'
NS_PUBKEY_REVOKE = 'urn:xmpp:revoke:2'
NS_PUBKEY_ATTEST = 'urn:xmpp:attest:2'
NS_STREAM_MGMT = 'urn:xmpp:sm:2' # XEP-198
NS_HASHES = 'urn:xmpp:hashes:0' # XEP-300
NS_HASHES = 'urn:xmpp:hashes:1' # XEP-300
NS_HASHES_MD5 = 'urn:xmpp:hash-function-textual-names:md5'
NS_HASHES_SHA1 = 'urn:xmpp:hash-function-textual-names:sha-1'
NS_HASHES_SHA256 = 'urn:xmpp:hash-function-textual-names:sha-256'
NS_HASHES_SHA512 = 'urn:xmpp:hash-function-textual-names:sha-512'
xmpp_stream_error_conditions = '''
bad-format -- -- -- The entity has sent XML that cannot be processed.
bad-namespace-prefix -- -- -- The entity has sent a namespace prefix that is unsupported, or has sent no namespace prefix on an element that requires such a prefix.
......@@ -1037,12 +1037,12 @@ class Iq(Protocol):
attrs={'id': self.getID()})
iq.setQuery(self.getQuery().getName()).setNamespace(self.getQueryNS())
return iq
class Hashes(Node):
class Hashes(Node):
"""
Hash elements for various XEPs as defined in XEP-300
"""
"""
RECOMENDED HASH USE:
Algorithm Support
......@@ -1053,14 +1053,14 @@ class Hashes(Node):
SHA-256 MUST
SHA-512 SHOULD
"""
supported = ('md5', 'sha-1', 'sha-256', 'sha-512')
def __init__(self, nsp=NS_HASHES):
Node.__init__(self, None, {}, [], None, None,False, None)
Node.__init__(self, None, {}, [], None, None, False, None)
self.setNamespace(nsp)
self.setName('hashes')
self.setName('hash')
def calculateHash(self, algo, file_string):
"""
Calculate the hash and add it. It is preferable doing it here
......@@ -1078,12 +1078,12 @@ class Hashes(Node):
hl = hashlib.sha256()
elif algo == 'sha-512':
hl = hashlib.sha512()
if hl:
hl.update(file_string)
hash_ = hl.hexdigest()
else: # if it is a file
if algo == 'md5':
hl = hashlib.md5()
elif algo == 'sha-1':
......@@ -1092,23 +1092,18 @@ class Hashes(Node):
hl = hashlib.sha256()
elif algo == 'sha-512':
hl = hashlib.sha512()
if hl:
for line in file_string:
hl.update(line)
hash_ = hl.hexdigest()
return hash_
return hash_
def addHash(self, hash_, algo):
"""
More than one hash can be added. Although it is permitted, it should
not be done for big files because it could slow down Gajim.
"""
attrs = {}
attrs['algo'] = algo
self.addChild('hash', attrs, [hash_])
self.setAttr('algo', algo)
self.setData(hash_)
class Acks(Node):
"""
Acknowledgement elements for Stream Management
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment