wec@sddlZddlZddlZddlZddlZddlZddlmZddlmZyddl Z e Z Wne k re Z nXdZdZiiidZdS(iN(t unhexlify(tFileNotFoundErrorcCs d}g}dtfdY}d }d}t} xtr|d7}|j} | sy|d k ru|j|nPn| j} | jds| rt} q7n| jdr|d k r|j|nd }|j| q7n| r9|d7}t} |d k r|j|n|d||f|}ntj d| } | sf|j | g7_ q7| j dj } | j d j } |j | d }|d krt| d dkrd | } nt|| tj| q7t|| || q7W|S( sLoad and parse a test vector file Return a list of objects, one per group of adjacent KV lines or for a single line in the form "[.*]". For a group of lines, the object has one attribute per line. it TestVectorcBseZdZRS(cSs||_||_g|_dS(N(tdesctcounttothers(tselft descriptionR((s</usr/lib64/python2.7/site-packages/Crypto/SelfTest/loader.pyt__init__=s  (t__name__t __module__R(((s</usr/lib64/python2.7/site-packages/Crypto/SelfTest/loader.pyR<sit#t[s%s (#%d)s([A-Za-z0-9]+) = ?(.*)it0N(tobjecttNonetTruetreadlinetappendtstript startswithtFalsetretmatchRtgrouptlowertgettlentsetattrtbinasciiR(t dir_compstfile_inRt conversionst line_numbertresultsRt test_vectorRt new_grouptlinetresttokentdatat conversion((s</usr/lib64/python2.7/site-packages/Crypto/SelfTest/loader.pyt _load_tests0sR            c Csd}yts3ttjtjtj|nd||f}tjjt j }tjj tjj |||}t |}t ||||}WdQXWn+tk rtjd|tddnX|S(sLoad and parse a test vector file, formatted using the NIST style. Args: dir_comps (list of strings): The path components under the ``pycryptodome_test_vectors`` package. For instance ``("Cipher", "AES")``. file_name (string): The name of the file with the test vectors. description (string): A description applicable to the test vectors in the file. conversions (dictionary): The dictionary contains functions. Values in the file that have an entry in this dictionary will be converted usign the matching function. Otherwise, values will be considered as hexadecimal and converted to binary. Returns: A list of test vector objects. The file is formatted in the following way: - Lines starting with "#" are comments and will be ignored. - Each test vector is a sequence of 1 or more adjacent lines, where each lines is an assignement. - Test vectors are separated by an empty line, a comment, or a line starting with "[". A test vector object has the following attributes: - desc (string): description - counter (int): the order of the test vector in the file (from 1) - others (list): zero or more lines of the test vector that were not assignments - left-hand side of each assignment (lowercase): the value of the assignement, either converted or bytes. s %s test (%s)Ns%Warning: skipping extended tests for t stackleveli(Rttest_vectors_availableRterrnotENOENTtoststrerrortpathtdirnametpycryptodome_test_vectorst__file__tjointopenR*twarningstwarnt UserWarning(Rt file_nameRR R"tinit_dirtfull_file_nameR((s</usr/lib64/python2.7/site-packages/Crypto/SelfTest/loader.pytload_test_vectorsus &  $   cCsg}yts3ttjtjtj|ntjjtj }tjj tjj |||}t |} t j | } WdQXWn,tk rtjd|tdd|SXdtfdY} i} x*|jD]\} }|| | | s           E >