Beispiel #1
0
def test_init(context):
    h = hashcontext.HashContext(algo='sha256')
    assert h.secure is True
    assert h.hmac is False
    h = hashcontext.HashContext(algo='sha256', secure=False, hmac=True)
    assert h.secure is False
    assert h.hmac is True
Beispiel #2
0
def test_reset(context):
    h = hashcontext.HashContext(algo='sha256')
    h.write('tototatatiti')
    one = h.read()
    h.reset()
    h.write('tototatatiti')
    assert one == h.read()
Beispiel #3
0
def test_read(context):
    h = hashcontext.HashContext(algo='sha256')
    h.write(
        b"Let's write things that will be hashed and with a long, ong text, bger than 32bytes. Stuff ike that. You know, long block of data."
    )
    hashed_data = h.read()
    assert hashed_data == b'\xb2m\x9a\x97\xe0\xa7\x1c\xe9\x0f<\x93\xee\rK3\x0b\x813|; q\x99\xf6\xef)\xe1\x9c\x93\xceG\xd8'
    assert len(hashed_data) == 32
Beispiel #4
0
#!/usr/bin/env python

import os, sys, binascii

from pygcrypt import hashcontext

h = hashcontext.HashContext(algo='sha256')

#print dir(h)

print(binascii.hexlify(h.read()))

h.reset()
h.write("Hello")
print(binascii.hexlify(h.read()))

h.reset()
h.write("Hello2")
print(binascii.hexlify(h.read()))
Beispiel #5
0
 def try_one():
     h = hashcontext.HashContext(algo='SHA512')
     h.write(b'testestsetsetstsststs')
     h.read()
Beispiel #6
0
def test_copy(context):
    h = hashcontext.HashContext(algo='sha256')
    h.write('yadayada')
    h2 = h.copy()
    assert h.read() == h2.read()
Beispiel #7
0
def test_write(context):
    h = hashcontext.HashContext(algo='sha256')
    h.write("Let's write things to be hashed")
Beispiel #8
0
def test_setkey(context):
    h = hashcontext.HashContext(algo='sha256', hmac=True)
    assert h.hmac is True
    h.setkey(b'What a beautiful key')
Beispiel #9
0
def test_enable(context):
    h = hashcontext.HashContext(algo='sha256')
    h.enable('sha512')

    with pytest.raises(Exception):
        h.enable('yadayada')
Beispiel #10
0
def test_getattr(context):
    h = hashcontext.HashContext(algo='sha256')
    assert h.algo == b'sha256'.upper()
    assert h.hashlen == 32
Beispiel #11
0
def test_valid(context):
    with pytest.raises(Exception):
        hashcontext.HashContext(algo='yadayada')