Forking what is left of ZeroNet and hopefully adding an AT Proto Frontend/Proxy
at main 31 lines 1.3 kB view raw
1import base64 2 3from Crypt import CryptHash 4 5sha512t_sum_hex = "2e9466d8aa1f340c91203b4ddbe9b6669879616a1b8e9571058a74195937598d" 6sha512t_sum_bin = b".\x94f\xd8\xaa\x1f4\x0c\x91 ;M\xdb\xe9\xb6f\x98yaj\x1b\x8e\x95q\x05\x8at\x19Y7Y\x8d" 7sha256_sum_hex = "340cd04be7f530e3a7c1bc7b24f225ba5762ec7063a56e1ae01a30d56722e5c3" 8 9 10class TestCryptBitcoin: 11 12 def testSha(self, site): 13 file_path = site.storage.getPath("dbschema.json") 14 assert CryptHash.sha512sum(file_path) == sha512t_sum_hex 15 assert CryptHash.sha512sum(open(file_path, "rb")) == sha512t_sum_hex 16 assert CryptHash.sha512sum(open(file_path, "rb"), format="digest") == sha512t_sum_bin 17 18 assert CryptHash.sha256sum(file_path) == sha256_sum_hex 19 assert CryptHash.sha256sum(open(file_path, "rb")) == sha256_sum_hex 20 21 with open(file_path, "rb") as f: 22 hash = CryptHash.Sha512t(f.read(100)) 23 hash.hexdigest() != sha512t_sum_hex 24 hash.update(f.read(1024 * 1024)) 25 assert hash.hexdigest() == sha512t_sum_hex 26 27 def testRandom(self): 28 assert len(CryptHash.random(64)) == 64 29 assert CryptHash.random() != CryptHash.random() 30 assert bytes.fromhex(CryptHash.random(encoding="hex")) 31 assert base64.b64decode(CryptHash.random(encoding="base64"))