<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , division , print_function <EOL> from itertools import islice <EOL> try : <EOL> import unittest2 as unittest <EOL> except ImportError : <EOL> import unittest <EOL> from tls . c import api <EOL> class DigestTests ( object ) : <EOL> data_short = b'<STR_LIT:abc>' <EOL> data_long = b'<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . ctx = api . EVP_MD_CTX_create ( ) <EOL> api . EVP_DigestInit_ex ( self . ctx , self . digest , api . NULL ) <EOL> self . ctx_two = api . EVP_MD_CTX_create ( ) <EOL> api . EVP_DigestInit_ex ( self . ctx_two , self . digest , api . NULL ) <EOL> def tearDown ( self ) : <EOL> api . EVP_MD_CTX_destroy ( self . ctx ) <EOL> api . EVP_MD_CTX_destroy ( self . ctx_two ) <EOL> def test_short ( self ) : <EOL> data = api . new ( '<STR_LIT>' , self . data_short ) <EOL> buf = api . new ( '<STR_LIT>' , api . EVP_MAX_MD_SIZE ) <EOL> size = api . new ( '<STR_LIT>' ) <EOL> api . EVP_DigestUpdate ( self . ctx , api . cast ( '<STR_LIT>' , data ) , len ( self . data_short ) ) <EOL> api . EVP_DigestFinal_ex ( self . ctx , buf , size ) <EOL> hash_value = b'<STR_LIT>' . join ( '<STR_LIT>' . format ( v ) . encode ( ) for v in islice ( buf , size [ <NUM_LIT:0> ] ) ) <EOL> self . assertEqual ( hash_value , self . hash_short ) <EOL> def test_long ( self ) : <EOL> data = api . new ( '<STR_LIT>' , self . data_long ) <EOL> buf = api . new ( '<STR_LIT>' , api . EVP_MAX_MD_SIZE ) <EOL> size = api . new ( '<STR_LIT>' ) <EOL> api . EVP_DigestUpdate ( self . ctx , api . cast ( '<STR_LIT>' , data ) , len ( self . data_long ) ) <EOL> api . EVP_DigestFinal_ex ( self . ctx , buf , size ) <EOL> hash_value = b'<STR_LIT>' . join ( '<STR_LIT>' . format ( v ) . encode ( ) for v in islice ( buf , size [ <NUM_LIT:0> ] ) ) <EOL> self . assertEqual ( hash_value , self . hash_long ) <EOL> def test_copy ( self ) : <EOL> data = api . new ( '<STR_LIT>' , self . data_short ) <EOL> buf = api . new ( '<STR_LIT>' , api . EVP_MAX_MD_SIZE ) <EOL> size = api . new ( '<STR_LIT>' ) <EOL> api . EVP_DigestUpdate ( self . ctx , api . cast ( '<STR_LIT>' , data ) , len ( self . data_short ) ) <EOL> api . EVP_MD_CTX_copy_ex ( self . ctx_two , self . ctx ) <EOL> api . EVP_DigestFinal_ex ( self . ctx_two , buf , size ) <EOL> hash_value = b'<STR_LIT>' . join ( '<STR_LIT>' . format ( v ) . encode ( ) for v in islice ( buf , size [ <NUM_LIT:0> ] ) ) <EOL> self . assertEqual ( hash_value , self . hash_short ) <EOL> data = api . new ( '<STR_LIT>' , self . data_long [ len ( self . data_short ) : ] ) <EOL> api . EVP_DigestUpdate ( self . ctx , api . cast ( '<STR_LIT>' , data ) , len ( data ) - <NUM_LIT:1> ) <EOL> api . EVP_DigestFinal_ex ( self . ctx , buf , size ) <EOL> hash_value = b'<STR_LIT>' . join ( '<STR_LIT>' . format ( v ) . encode ( ) for v in islice ( buf , size [ <NUM_LIT:0> ] ) ) <EOL> self . assertEqual ( hash_value , self . hash_long ) <EOL> class TestSHA1 ( DigestTests , unittest . TestCase ) : <EOL> "<STR_LIT>" <EOL> hash_short = b"<STR_LIT>" <EOL> hash_long = b"<STR_LIT>" <EOL> @ property <EOL> def digest ( cls ) : <EOL> return api . EVP_sha1 ( ) <EOL> class TestMD5 ( DigestTests , unittest . TestCase ) : <EOL> "<STR_LIT>" <EOL> hash_short = b"<STR_LIT>" <EOL> hash_long = b"<STR_LIT>" <EOL> @ property <EOL> def digest ( self ) : <EOL> return api . EVP_md5 ( ) <EOL> class TestSHA256 ( DigestTests , unittest . TestCase ) : <EOL> "<STR_LIT>" <EOL> hash_short = b"<STR_LIT>" <EOL> hash_long = b"<STR_LIT>" <EOL> @ property <EOL> def digest ( self ) : <EOL> return api . EVP_sha256 ( ) <EOL> class TestEVP ( unittest . TestCase ) : <EOL> def test_init ( self ) : <EOL> ctx = api . new ( '<STR_LIT>' ) <EOL> self . assertTrue ( ctx ) <EOL> api . EVP_MD_CTX_init ( ctx ) <EOL> api . EVP_MD_CTX_cleanup ( ctx ) <EOL> def test_create ( self ) : <EOL> ctx = api . EVP_MD_CTX_create ( ) <EOL> self . assertTrue ( ctx ) <EOL> api . EVP_MD_CTX_destroy ( ctx ) <EOL> def _test_md_func ( self , name , nid_name = None ) : <EOL> nid_name = '<STR_LIT>' + name . lower ( ) if nid_name is None else nid_name <EOL> getter = getattr ( api , '<STR_LIT>' . format ( name . lower ( ) ) ) <EOL> num = getattr ( api , nid_name ) <EOL> md = getter ( ) <EOL> self . assertTrue ( md ) <EOL> self . assertEqual ( api . EVP_MD_type ( md ) , num ) <EOL> def test_md_null_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def test_dsa_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def test_dsa1_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_dss_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def test_dss1_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_ecdsa_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def test_md2_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' ) <EOL> def test_md4_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' ) <EOL> def test_md5_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' ) <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def test_mdc2_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' ) <EOL> def test_ripemd160_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' ) <EOL> def test_sha_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' ) <EOL> def test_sha1_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' ) <EOL> def test_sha224_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' ) <EOL> def test_sha256_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' ) <EOL> def test_sha384_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' ) <EOL> def test_sha512_func ( self ) : <EOL> self . _test_md_func ( '<STR_LIT>' ) <EOL> def _test_md_name ( self , name , nid_name = None ) : <EOL> if nid_name is None : <EOL> nid_name = b'<STR_LIT>' + name . lower ( ) <EOL> md_name = name <EOL> num = getattr ( api , nid_name . decode ( ) ) <EOL> md = api . EVP_get_digestbyname ( md_name ) <EOL> self . assertTrue ( md ) <EOL> self . assertEqual ( api . EVP_MD_type ( md ) , num ) <EOL> def test_dsa_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' , b'<STR_LIT>' ) <EOL> def test_dsa_sha_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' , b'<STR_LIT>' ) <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def test_dsa_sha1_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' , b'<STR_LIT>' ) <EOL> def test_ecdsa_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' , b'<STR_LIT>' ) <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def test_md2_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' ) <EOL> def test_md4_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' ) <EOL> def test_md5_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' ) <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def test_mdc2_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' ) <EOL> def test_ripemd160_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' ) <EOL> def test_sha_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' ) <EOL> def test_sha1_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' ) <EOL> def test_sha224_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' ) <EOL> def test_sha256_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' ) <EOL> def test_sha384_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' ) <EOL> def test_sha512_name ( self ) : <EOL> self . _test_md_name ( b'<STR_LIT>' ) <EOL> def _test_md_nid ( self , nid , name ) : <EOL> self . assertEqual ( name , api . string ( api . OBJ_nid2sn ( nid ) ) ) <EOL> md = api . EVP_get_digestbynid ( nid ) <EOL> self . assertTrue ( md ) <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def test_md2_nid ( self ) : <EOL> self . _test_md_nid ( api . NID_md2 , b'<STR_LIT>' ) <EOL> def test_md4_nid ( self ) : <EOL> self . _test_md_nid ( api . NID_md4 , b'<STR_LIT>' ) <EOL> def test_md5_nid ( self ) : <EOL> self . _test_md_nid ( api . NID_md5 , b'<STR_LIT>' ) <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def test_mdc2_nid ( self ) : <EOL> self . _test_md_nid ( api . NID_mdc2 , b'<STR_LIT>' ) <EOL> def test_ripemd160_nid ( self ) : <EOL> self . _test_md_nid ( api . NID_ripemd160 , b'<STR_LIT>' ) <EOL> def test_sha_nid ( self ) : <EOL> self . _test_md_nid ( api . NID_sha , b'<STR_LIT>' ) <EOL> def test_sha1_nid ( self ) : <EOL> self . _test_md_nid ( api . NID_sha1 , b'<STR_LIT>' ) <EOL> def test_sha224_nid ( self ) : <EOL> self . _test_md_nid ( api . NID_sha224 , b'<STR_LIT>' ) <EOL> def test_sha256_nid ( self ) : <EOL> self . _test_md_nid ( api . NID_sha256 , b'<STR_LIT>' ) <EOL> def test_sha384_nid ( self ) : <EOL> self . _test_md_nid ( api . NID_sha384 , b'<STR_LIT>' ) <EOL> def test_sha512_nid ( self ) : <EOL> self . _test_md_nid ( api . NID_sha512 , b'<STR_LIT>' ) </s>
