jaraco.crypto / tests /

import binascii

import py.test
from ctypescrypto import evp, digest

def test_load_valid_digest_type_by_name():
	t = evp.DigestType.from_name('SHA256')

def test_load_invalid_digest_type_by_name():
	# dne is Does Not Exist
	py.test.raises(evp.DigestError, evp.DigestType.from_name, 'sha-dne')

def test_digest():
	digest_type = digest.DigestType.from_name('SHA512')
	sha512 = digest.Digest(digest_type)
	assert not sha512.finalized
	digest_ = sha512.digest()
	digest_str = binascii.hexlify(digest_)
	assert len(digest_) == 64
	assert digest_str == (

def pytest_generate_tests(metafunc):
	if "data_parts" in metafunc.funcargnames:
		for i in range(0, 1000, 50):
				data_parts=('a'*i, 'b'*i, 'c'*i)

def test_cipher(data_parts):
	Encrypt and decrypt the data_parts supplied and ensure the source
	matches the result.
	py.test.skip('not ready yet')
	key1 = '11111111111111111111111111111111'
	key2 = '1111111111111111'
	params = 'AES-256', 'CBC', key1, key2
	ce = cipher.Cipher(*params)
	map(ce.update, data_parts)
	data_enc = ce.finish()
	cd = cipher.Cipher(*params)
	assert cd.finish(data_enc) == ''.join(data_parts)

def test_rand():
	py.test.skip('not ready yet')
	ran = rand.bytes(libcrypto, 100)
	assert len(ran) == 100
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.