ffzdZddlZddlTddlmZmZmZmZmZm Z m Z m Z m Z Gddej ZGddej ZGd d ej ZGd d ej ZGd dej ZGddej ZGddej ZGddej ZGddej ZifdZedkrdZejddSdS)zSelf-tests for Crypto.Util.asn1N)*) DerObjectDerSetOf DerInteger DerBitString DerObjectIdDerNullDerOctetString DerSequence DerBooleancbeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdS)DerObjectTestsc|tttd|ttddS)Nu™) assertRaises ValueErrorrb)selfs /builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/SelfTest/Util/test_asn1.py testObjInit1zDerObjectTests.testObjInit1.s> *i:??? *i66666cttd}||tdtd|_||td||tdtd}td|_||tdttdd }||td dS) NEzEzET) constructed0)rr assertEqualencodepayloadrders rtestObjEncode1zDerObjectTests.testObjEncode16s& "" q}}555ii  q'8'8999 q'8'8999ooii  q'8'8999& t444 q}}55555rctdtd}||tddS)Nzz)rrr r!r#s rtestObjEncode2zDerObjectTests.testObjEncode2GsDa mm,, q);'<'<=====rcttd}tddz|_||tddS)Nr0u€00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000rrr"r r!r#s rtestObjEncode3zDerObjectTests.testObjEncode3LsS& ""ffSj  q)A'B'BCCCCCrcrtddd}td|_||tdtddd }td|_||td dS) NT)implicitrppllu¡ppllFužppllr,r#s rtestObjEncode4zDerObjectTests.testObjEncode4Rsqd;;;ii  q'8'8999t???ii  q'8'899999rctdd}td|_||tddS)Nr/explicitxxll ¥xxllr,r#s rtestObjEncode5zDerObjectTests.testObjEncode5\sNq)))ii  q)?'@'@AAAAArctd}|td||jtd||jddS)Nr3rdecoderr r" _tag_octetr#s rtestObjDecode1zDerObjectTests.testObjDecode1dsdoo 1'(())) a mm444 .....rctd}|td||jtddz||jddS)Nr3u€111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111r+r@r#s rtestObjDecode2zDerObjectTests.testObjDecode2kshoo 1-../// affSj111 .....rctd}|t|jt dtd}|t|jt ddS)Nr3uÿzrrrrArr#s rtestObjDecode3zDerObjectTests.testObjDecode3rscoo *cj!4J2K2KLLLoo *cj!N2C2CDDDDDrc.tddd}|t|jt d|t d||jt dtddd}|t|jt d|t d ||jt ddS) Nr3F)rr1r>uTu¯)rrrrArr r"r#s rtestObjDecode4zDerObjectTests.testObjDecode4zs%#>>> *cj!4F2G2GHHH 1^$$%%% aii000$=== *cj!4F2G2GHHH 1^$$%%% aii00000rctd}|t|jt ddS)Nr3zrHr#s rtestObjDecode5zDerObjectTests.testObjDecode5s6oo *cj!4F2G2GHHHHHrct}|td||jd||jtddS)Nueˆeˆ)rrArr rBr"r#s rtestObjDecode6zDerObjectTests.testObjDecode6sakk 1^$$%%% ... aii00000rctdd}|td||jd||jtdtdd}|td||jd||jtddS)Nr/r7r8r;r:ru  xxll)rrArr _inner_tag_octetr"r#s rtestObjDecode7zDerObjectTests.testObjDecode7sq))) 1+,,--- -t444 aii000q))) 1+,,--- -t444 aii00000rctd}|||tddS)Nr3r>)rr rArr#s rtestObjDecode8zDerObjectTests.testObjDecode8s>oo cjj+=)>)>??@@@@@rN)__name__ __module__ __qualname__rr%r(r-r5r<rCrFrIrMrOrSrVrXrrrr,s777666">>> DDD :::BBB//////EEE 1 1 1III 111 1 1 1AAAAArrc\eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdS)DerIntegerTestsctd}||tddS)Nr0rr r!rr#s r testInit1zDerIntegerTests.testInit1s9mm q'8'899999rctd}||tdtd}||tdtd}||tddS)Nrr0r`rar#s r testEncode1zDerIntegerTests.testEncode1smm q'8'8999mm q'8'8999oo q'8'899999rctd}||tdtd}||tdtddz}||tdtdztdztdztdztdztdztdztdztdztdztdztdztdztdztdztdztdztd zdS) Nr+u€€r3‚ rar#s r testEncode2zDerIntegerTests.testEncode2soo q);'<'<=== q);'<'<===D!!  DEE DEE F DEE F DEE F DEE  F DEE  F DEE  F DEE F DEE F DEE F DEE F DEE F DEE F DEE F DEE F DEE F DEE! F" DEE# F$ 011% 2 3 3 3 3 3rctd}||tdtd}||tdtd}||tddS)Nÿiu€iuþ¨¿rar#s r testEncode3zDerIntegerTests.testEncode3snn q'8'8999 q'8'8999   q)?'@'@AAAAArctdd}||tddS)N4r'r8£4rarnumbers r testEncode4zDerIntegerTests.testEncode4sAD1--- !,B*C*CDDDDDrct}|td||jd|td||jd|td||jddS)Nrdrr`r0rfrerrArr valuer#s r testDecode1zDerIntegerTests.testDecode1sll 1^$$%%% A&&& 1^$$%%% A&&& 1^$$%%% C(((((rc\t}|td||jd|tdtdztdztdztdztdztdztdztdztdztdztdztdztdztdztdztdztdztdz||jddzdS)Nrjrirlrmrnr3rkr{r#s r testDecode2zDerIntegerTests.testDecode2sll 1'(())) 5)))  DEE DEE F DEE F DEE F DEE  F DEE  F DEE  F DEE F DEE F DEE F DEE F DEE F DEE F DEE F DEE F DEE F DEE! F" DEE# F$ 011% 2 3 3 3( 1d7+++++rct}|td||jd|td||jddS)Nrrrqu€ir{r#s r testDecode3zDerIntegerTests.testDecode3svll 1^$$%%% B''' 1'(())) F+++++rct}|td||jd|td||jd|td||jddS)Nzr0uÿÿrqrrr{r#s r testDecode5zDerIntegerTests.testDecode5sll 1'(())) A&&& 1'(())) B''' 1Z==!!! A&&&&&rctd}|td||jddS)Nr'r8rvrur{rws r testDecode6zDerIntegerTests.testDecode6)sKQ''' a.//000 t,,,,,rct}|||tddS)Nrf)rr rArr#s r testDecode7zDerIntegerTests.testDecode7/s;ll cjj>):):;;<<<< B B BEEE ) ) ),,,:,,, ' ' '--- ===WWWIIIIIrr^ceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdS)DerSequenceTestsctdtdtdg}||tddS)Nr0r3rz 00)r rrr r!r#s rrbzDerSequenceTests.testInit1HsO1jmmQwZZ899 q)M'N'NOOOOOrct}||td|||d||td||d||dd||||d||tddS)Nrr0r0F) r r r!r assertFalse hasOnlyIntsappendhasInts assertTruer#s rrgzDerSequenceTests.testEncode1Ls*mm qzz222 **+++ 1  q)<'='=>>> q))) U++A... ))*** ../// q)<'='=>>>>>rcnt}|dd|d<|t|d||dd||dd||t ddg|dd<|t|d||dd||t ddS)Nrr0rqz0)r rr lenr!rr#s rrozDerSequenceTests.testEncode2[s mm 1 A S!$$$ Q""" R### q)<'='=>>>AAA S!$$$ Q""" q)<'='=>>>>>rct}|d||t ddS)Nriu0€r rr r!rr#s rrszDerSequenceTests.testEncode3jsJmm 5 q)@'A'ABBBBBrct}|ddz||t dt dzt dzt dzt dzt dzt dzt dzt dzt dzt dzt dzt dzt dzt dzt dzt dzt dzt dzt dzdS)Nr3rk0‚rlrmrnrr#s rryzDerSequenceTests.testEncode4psmm 1d7 q'9'9 DEE(F DEE(F DEE(F DEE (F DEE (F DEE (F DEE(F DEE(F DEE (F DEE (F DEE (F DEE (F DEE (F DEE(F DEE(F DEE!(F" DEE#(F$ DEE%(F& 011'(2 3 3 3 3 3rct}|dz }|tdz }||tddS)Nr0rz00)r rr r!r#s r testEncode5zDerSequenceTests.testEncode5sQmm q q}} q)G'H'HIIIIIrct}|d|d||t d||||dt}|d|d||t d||d||dd||||d|dd d g|dd<|t|d ||ddd d g||dd d g||t d dS)Nri 0€ÿFr3u 0þr0 r'rqz 0  ) r rr r!rrrrrrr#s r testEncode6zDerSequenceTests.testEncode6smm 5 4 q)P'Q'QRRR ))*** ..///mm 1  2 q)H'I'IJJJ *** U++Q/// **+++ ../// 4Q%ABB S!$$$ QRR!A''' QrTA3''' q)T'U'UVVVVVrcHt}|d|td||td||dS)Nriz0 0 €0)r rrr r!rrr#s r testEncode7zDerSequenceTests.testEncode7smm 5 1())*** q)Q'R'RSSS **+++++rcJt}|d|tdg||t d||dS)Nrir7r)r rr r!rrrr#s r testEncode8zDerSequenceTests.testEncode8smm 5 ;s##$$$ q)Q'R'RSSS **+++++rc0t}|td|t |d|td|t |d||dd|td|t |d||dddS)Nrrrr0r rArr rr#s rr}zDerSequenceTests.testDecode1smm 1W:: S!$$$ 1())*** S!$$$ Q""" 1())*** S!$$$ Q"""""rct}|td|t |d||dddS)Nz0r0rrerr#s rrzDerSequenceTests.testDecode2sbmm 1())*** S!$$$ Q$$$$$rcJt}|tdtdztdztdztdztdztdztdztdztdztdztdztdztdztdztdztdztdztdztdz|t |d||dddzdS) Nrrlrmrnr0rr3rkrr#s r testDecode4zDerSequenceTests.testDecode4smm 1_%% DEEF DEEF DEEF DEE F DEE F DEE F DEEF DEEF DEE F DEE F DEE F DEE F DEE F DEEF DEEF DEE!F" DEE#F$ DEE%F& 011'2 3 3 3( S!$$$ Q4(((((rct}|td|t |d||dd||dddS)Nrr3rrir0rrr#s rrzDerSequenceTests.testDecode6s|mm 1<==>>> S!$$$ Q&&& Q%%%%%rct}|td|t |d||dd||dtd||dtddS) N0 €$¶cr'rrir0$¶cr3rr#s rrzDerSequenceTests.testDecode7smm 1DEEFFF S!$$$ Q&&& Q"4 5 5666 Q* .....rct}|td|t |d||dtd||dtd||d||dd||||ddS)N 0$¶cr3rrr0rF)r rArr rrrrr#s r testDecode8zDerSequenceTests.testDecode8s mm 1455666 S!$$$ Q"4 5 5666 Q* ... *** U++Q/// **+++ //00000rct}|||tddS)Nr)r r rArr#s r testDecode9zDerSequenceTests.testDecode9s<mm cjj+J)K)KLLMMMMMrc6t}|t|jt d|t|jt d|t|jt ddS)NrLr*r rrrArr#s rrzDerSequenceTests.testErrDecode1 sqmm *cj!B%%888 *cj!F))<<< *cj!F))<<<<>>555999 IIIIIrrceZdZdZdZdS) DerNullTestsct}||tddSNz)r r r!rr#s rrgzDerNullTests.testEncode1Zs5ii q}}55555rct}|||tddSr)r r rArr#s rr}zDerNullTests.testDecode1`s9ii cjj:7788888rN)rYrZr[rgr}r\rrrrXs2666 99999rrc8eZdZdZdZdZdZdZdZdZ dS) DerObjectIdTestscttd}||ddS)Nz1.1s))rr r!r#s rrbzDerObjectIdTests.testInit1gs3%   |44444rc\td}||dt}d|_||dtd}||ddS)N1.2.840.113549.1.1.1  *H  2.999.12347R)rr r!r|r#s rrgzDerObjectIdTests.testEncode1ks011 'VWWWmm*  'VWWW,'' 'BCCCCCrctd}|t|jtd}|t|jdS)Nz3.4z1.40)rrrr!r#s rrozDerObjectIdTests.testEncode2vsR%   *cj111&!! *cj11111rct}|d||jddS)NrrrrAr r|r#s rr}zDerObjectIdTests.testDecode1s=mm BCCC $:;;;;;rctt}|||ddS)Nr)rr rAr#s rrzDerObjectIdTests.testDecode2sDmm  JKK M M M M Mrct}|d||jddS)Ns  *H z1.2.840.113549.1.0.1rr#s rrzDerObjectIdTests.testDecode3s=mm BCCC $:;;;;;rct}|d||jddS)Nrrrr#s rrzDerObjectIdTests.testDecode4s<mm ./// L11111rN) rYrZr[rbrgror}rrrr\rrrres555 D D D222<<< MMM <<< 22222rrc,eZdZdZdZdZdZdZdS)DerBitStringTestscttd}||tddS)Nruÿ)rrr r!r#s rrbzDerBitStringTests.testInit1sB1V99%% q);'<'<=====rcttd}||t ddS)Nr0z)rrr r!rr#s r testInit2zDerBitStringTests.testInit2sB:a==)) q)C'D'DEEEEErct}||tdttd}||tdt}td|_||tddS)Nzr?)rr r!rr|r#s rrgzDerBitStringTests.testEncode1snn q'8'89991Z==)) q)?'@'@AAAnnjMM  q)?'@'@AAAAArcJt}|td||jtd|td||jtddS)Nrrr?)rrArr r|r#s rr}zDerBitStringTests.testDecode1snn 1Z==!!! AbEE*** 1+,,--- AjMM22222rct}|||tddS)Nr)rr rArr#s rrzDerBitStringTests.testDecode2s9nn cjj:7788888rN)rYrZr[rbrrgr}rr\rrrrse>>>FFF B B B33399999rrcJeZdZdZdZdZdZdZdZdZ dZ d Z d Z d S) DerSetOfTestscttdtdg}||t ddS)Nr0r3z1)rrr r!rr#s rrbzDerSetOfTests.testInit1sM 1 z!}}566 q)H'I'IJJJJJrct}||td|d||td||tddS)N1r1)rr r!raddr#s rrgzDerSetOfTests.testEncode1sjj qzz222   q)<'='=>>> q)<'='=>>>>>rclt}|d|d||t dtddg}||t ddS)Nriru 1ÿ€)rrr r!rr#s rrozDerSetOfTests.testEncode2sjj    q)P'Q'QRRRt}%% q)P'Q'QRRRRRrct}|d|t|jt ddS)Nriz)rrrrrr#s rrszDerSetOfTests.testEncode3sCjj  *cgq1C/D/DEEEEErct}|td|td||tddS)Nzzz1)rrrr r!r#s rryzDerSetOfTests.testEncode4sjjj *  .!!""" q)D'E'EFFFFFrc~t}|td|t |d|td|t |d|t |dgdS)Nrrrr0)rrArr rlistr#s rr}zDerSetOfTests.testDecode1sjj 1W:: S!$$$ 1())*** S!$$$ cA3'''''rc&t}|td|t |dt |}|d|v|d|vdS)N 1€ÿr3rir)rrArr rrr)rr$ls rrzDerSetOfTests.testDecode2sjj 1<==>>> S!$$$ II  ###  """""rc~t}|t|jt ddS)NrrrrrArr#s rrzDerSetOfTests.testDecode3sDjj *cj = > > @ @ @ @ @rct}|||tddS)Nr)rr rArr#s rrzDerSetOfTests.testDecode4sLjj  1DEEFF H H H H Hrc~t}|t|jt ddS)Nu1€ÿªrr#s rrzDerSetOfTests.testErrDecode1s?jj *cj 9 : : < < < < ?????rct}|d||jddS)Nr Fr rAr r|r#s rr}zDerBooleanTests.testDecode1"s;ll ?### E*****rct}|d||jddS)Nr Trr#s rrzDerBooleanTests.testDecode2's;ll ?### D)))))rctd}|d||jddS)NrrrFrr#s rrzDerBooleanTests.testDecode3,sB$''' ?### E*****rctd}|d||jddS)Nr7r8rFrr#s rrzDerBooleanTests.testDecode41sC$''' *+++ E*****rcdt}|t|jddS)Nsr rrrAr#s rtestErrorDecode1z DerBooleanTests.testErrorDecode16s+ll *cj/BBBBBrcdt}|t|jddS)Nsrr#s rtestErrorDecode2z DerBooleanTests.testErrorDecode2;s,ll *cj2EFFFFFrN) rYrZr[rgrorsryr}rrrrrr\rrrrs888888888@@@ +++ *** +++ +++ CCC GGGGGrrclddlm}g}||tz }||tz }||tz }||t z }||t z }||tz }||tz }||tz }||tz }|S)Nr)list_test_cases) Crypto.SelfTest.st_commonrrr^rrrrrrr)configr listTestss r get_testsr"As999999I 000I 111I !1222I !4555I ...I !1222I !2333I ///I 111I r__main__cBtjtS)N)unittest TestSuiter"r\rrr'PsH&y{{33rsuite) defaultTest)__doc__r%Crypto.Util.py3compatCrypto.Util.asn1rrrrrr r r r TestCaserr^rrrrrrrr"rYr(mainr\rrr/sD&%####6666666666666666666666 vAvAvAvAvAX&vAvAvAp_I_I_I_I_Ih'_I_I_IDl_l_l_l_l_x(l_l_l_^!I!I!I!I!I(+!I!I!IF 9 9 9 9 98$ 9 9 9.2.2.2.2.2x(.2.2.2b$9$9$9$9$9)$9$9$9NO<O<O<O<O