コード例 #1
0
ファイル: test_hash.py プロジェクト: pglen/pyvserv
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
コード例 #2
0
ファイル: test_hash.py プロジェクト: pglen/pyvserv
def test_reset(context):
    h = hashcontext.HashContext(algo='sha256')
    h.write('tototatatiti')
    one = h.read()
    h.reset()
    h.write('tototatatiti')
    assert one == h.read()
コード例 #3
0
ファイル: test_hash.py プロジェクト: pglen/pyvserv
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
コード例 #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()))
コード例 #5
0
ファイル: test_hash.py プロジェクト: pglen/pyvserv
 def try_one():
     h = hashcontext.HashContext(algo='SHA512')
     h.write(b'testestsetsetstsststs')
     h.read()
コード例 #6
0
ファイル: test_hash.py プロジェクト: pglen/pyvserv
def test_copy(context):
    h = hashcontext.HashContext(algo='sha256')
    h.write('yadayada')
    h2 = h.copy()
    assert h.read() == h2.read()
コード例 #7
0
ファイル: test_hash.py プロジェクト: pglen/pyvserv
def test_write(context):
    h = hashcontext.HashContext(algo='sha256')
    h.write("Let's write things to be hashed")
コード例 #8
0
ファイル: test_hash.py プロジェクト: pglen/pyvserv
def test_setkey(context):
    h = hashcontext.HashContext(algo='sha256', hmac=True)
    assert h.hmac is True
    h.setkey(b'What a beautiful key')
コード例 #9
0
ファイル: test_hash.py プロジェクト: pglen/pyvserv
def test_enable(context):
    h = hashcontext.HashContext(algo='sha256')
    h.enable('sha512')

    with pytest.raises(Exception):
        h.enable('yadayada')
コード例 #10
0
ファイル: test_hash.py プロジェクト: pglen/pyvserv
def test_getattr(context):
    h = hashcontext.HashContext(algo='sha256')
    assert h.algo == b'sha256'.upper()
    assert h.hashlen == 32
コード例 #11
0
ファイル: test_hash.py プロジェクト: pglen/pyvserv
def test_valid(context):
    with pytest.raises(Exception):
        hashcontext.HashContext(algo='yadayada')