Rev399, Urandom and Msgpack benchmark, Better random string generation, Never render page on OPTIONS request, Fix for Chrome browser socket hang on zeronet version update

This commit is contained in:
HelloZeroNet 2015-09-13 23:17:13 +02:00
parent 5c72030373
commit 8f63e4c421
9 changed files with 79 additions and 25 deletions

View file

@ -1,4 +1,6 @@
import hashlib
import os
import base64
def sha1sum(file, blocksize=65536):
@ -19,6 +21,15 @@ def sha512sum(file, blocksize=65536):
return hash.hexdigest()[0:64] # Truncate to 256bits is good enough
def random(length=64, encoding="hex"):
if encoding == "base64": # Characters: A-Za-z0-9
hash = hashlib.sha512(os.urandom(256)).digest()
return base64.standard_b64encode(hash).replace("+", "").replace("/", "").replace("=", "")[0:length]
else: # Characters: a-f0-9 (faster)
return hashlib.sha512(os.urandom(256)).hexdigest()[0:length]
if __name__ == "__main__":
import cStringIO as StringIO
a = StringIO.StringIO()