better way to handle non supported hash algorithms
This commit is contained in:
parent
c02b43f88f
commit
b2897e36bb
|
@ -118,11 +118,15 @@ class JingleFileTransfer(JingleContent):
|
||||||
if self.session.hash_algo == None:
|
if self.session.hash_algo == None:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
file = open(self.file_props['file-name'], 'r')
|
file_ = open(self.file_props['file-name'], 'r')
|
||||||
except:
|
except:
|
||||||
|
# can't open file
|
||||||
return
|
return
|
||||||
h = xmpp.Hashes()
|
h = xmpp.Hashes()
|
||||||
hash_ = h.calculateHash(self.session.hash_algo, file)
|
hash_ = h.calculateHash(self.session.hash_algo, file_)
|
||||||
|
if not hash_:
|
||||||
|
# Hash alogrithm not supported
|
||||||
|
return
|
||||||
self.file_props['hash'] = hash_
|
self.file_props['hash'] = hash_
|
||||||
h.addHash(hash_, self.session.hash_algo)
|
h.addHash(hash_, self.session.hash_algo)
|
||||||
checksum = xmpp.Node(tag='checksum',
|
checksum = xmpp.Node(tag='checksum',
|
||||||
|
|
|
@ -1078,10 +1078,7 @@ class Hashes(Node):
|
||||||
elif algo == 'sha-512':
|
elif algo == 'sha-512':
|
||||||
hl = hashlib.sha512()
|
hl = hashlib.sha512()
|
||||||
|
|
||||||
if hl == None:
|
if hl:
|
||||||
# Raise exception
|
|
||||||
raise Exception('Hash algorithm not supported')
|
|
||||||
else:
|
|
||||||
hl.update(file_string)
|
hl.update(file_string)
|
||||||
hash_ = hl.hexdigest()
|
hash_ = hl.hexdigest()
|
||||||
else: # if it is a file
|
else: # if it is a file
|
||||||
|
@ -1095,10 +1092,7 @@ class Hashes(Node):
|
||||||
elif algo == 'sha-512':
|
elif algo == 'sha-512':
|
||||||
hl = hashlib.sha512()
|
hl = hashlib.sha512()
|
||||||
|
|
||||||
if hl == None:
|
if hl:
|
||||||
# Raise exception
|
|
||||||
raise Exception('Hash algorithm not supported')
|
|
||||||
else:
|
|
||||||
for line in file_string:
|
for line in file_string:
|
||||||
hl.update(line)
|
hl.update(line)
|
||||||
hash_ = hl.hexdigest()
|
hash_ = hl.hexdigest()
|
||||||
|
|
Loading…
Reference in New Issue