Skip to content

Instantly share code, notes, and snippets.

@public
Created January 9, 2014 10:14
Show Gist options
  • Select an option

  • Save public/8332087 to your computer and use it in GitHub Desktop.

Select an option

Save public/8332087 to your computer and use it in GitHub Desktop.
import os
from testmachine import TestMachine
from testmachine.common import basic_operations
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
machine = TestMachine()
basic_operations(machine, "backend")
basic_operations(machine, "hash")
basic_operations(machine, "hash_ctx")
basic_operations(machine, "bytes")
basic_operations(machine, "digest")
basic_operations(machine, "none")
hash_types = [
hashes.SHA1,
hashes.SHA256,
hashes.Whirlpool,
hashes.RIPEMD160,
hashes.MD5
]
machine.generate(lambda _: default_backend(), "backend")
machine.generate(lambda r: r.choice(hash_types)(), "hash")
machine.generate(lambda r: os.urandom(r.randint(0, 1024)), "bytes")
machine.operation(
argspec=("hash", "backend"),
target="hash_ctx",
function=lambda h, b: hashes.Hash(h, b),
pattern="hashes.Hash(%s, %s)"
)
machine.operation(
argspec=("hash_ctx", "bytes"),
target="none",
function=lambda h, b: h.update(b),
pattern="%s.update(%s)"
)
machine.check(
argspec=("hash_ctx",),
test=lambda h: h.copy().finalize(),
pattern="assert %s.copy().finalize()"
)
machine.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment