replace md5 with sha256
This commit is contained in:
parent
a893e8bf2b
commit
50bcb6f3bc
10 changed files with 60 additions and 60 deletions
|
|
@ -27,6 +27,7 @@ from __future__ import absolute_import, division
|
|||
import base64
|
||||
import datetime
|
||||
import errno
|
||||
import hashlib
|
||||
import imp
|
||||
import logging
|
||||
import logging.handlers
|
||||
|
|
@ -3109,24 +3110,24 @@ class ClientSession(object):
|
|||
fo = open(localfile, "rb") # specify bufsize?
|
||||
totalsize = os.path.getsize(localfile)
|
||||
ofs = 0
|
||||
md5sum = util.md5_constructor()
|
||||
sha256sum = hashlib.sha256sum()
|
||||
debug = self.opts.get('debug', False)
|
||||
if callback:
|
||||
callback(0, totalsize, 0, 0, 0)
|
||||
while True:
|
||||
lap = time.time()
|
||||
contents = fo.read(blocksize)
|
||||
md5sum.update(contents)
|
||||
sha256sum.update(contents)
|
||||
size = len(contents)
|
||||
data = util.base64encode(contents)
|
||||
if size == 0:
|
||||
# end of file, use offset = -1 to finalize upload
|
||||
offset = -1
|
||||
digest = md5sum.hexdigest()
|
||||
digest = sha256sum.hexdigest()
|
||||
sz = ofs
|
||||
else:
|
||||
offset = ofs
|
||||
digest = util.md5_constructor(contents).hexdigest()
|
||||
digest = hashlib.sha256(contents).hexdigest()
|
||||
sz = size
|
||||
del contents
|
||||
tries = 0
|
||||
|
|
@ -3134,7 +3135,8 @@ class ClientSession(object):
|
|||
if debug:
|
||||
self.logger.debug("uploadFile(%r,%r,%r,%r,%r,...)" %
|
||||
(path, name, sz, digest, offset))
|
||||
if self.callMethod('uploadFile', path, name, sz, digest, offset, data, **volopts):
|
||||
if self.callMethod('uploadFile', path, name, sz, ("sha256", digest),
|
||||
offset, data, **volopts):
|
||||
break
|
||||
if tries <= retries:
|
||||
tries += 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue