a „oeüã@sžddlZddlZddlmZmZddlZddlmZmZm Z ddl TGdd„dej ƒZ dZ dZejeeeed œd d „ƒZGd d „d ej ƒZedkrše ƒdS)éN)ÚAnyÚIterator)Ú TestSkippedÚfind_test_fixtureÚtestmain)Ú*c@seZdZdd„Zdd„ZdS)ÚCryptc CsZd}d}d}d}d}t |||d||¡}t ||d||¡\}}| ||¡| ||¡dS)Nó My test dataúMy descriptionr©Ú win32cryptZCryptProtectDataZCryptUnprotectDataÚ assertEqual© ÚselfÚdataZentropyZdescÚflagsZpsZblobZgot_descZgot_data©rú;C:\Program Files\Certbot\pkgs\win32\test\test_win32crypt.pyÚ testSimple s ÿ zCrypt.testSimplec CsZd}d}d}d}d}t |||d||¡}t ||d||¡\}}| ||¡| ||¡dS)Nr sMy test entropyr rr rrrrÚ testEntropys ÿ zCrypt.testEntropyN)Ú__name__Ú __module__Ú __qualname__rrrrrrr s rZ LocalMachineZ CurrentUser)Ú store_nameÚstore_locationÚreturnccsTd}z8t tdd|tkrtnt|¡}|VW|durP| ¡n|durN| ¡0dS)z”Open a windows certificate store :param store_name: store name :param store_location: store location :return: handle to cert store Nr)r Z CertOpenStoreZCERT_STORE_PROV_SYSTEMÚ_LOCAL_MACHINEZCERT_SYSTEM_STORE_LOCAL_MACHINEZCERT_SYSTEM_STORE_CURRENT_USERZCertCloseStore)rrÚhandlerrrÚopen_windows_certstore-s ÿù  ÿrc@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) Ú TestCertscCsPtt|ƒdƒ�.}t| ¡ƒ}t t|ttd¡WdƒS1sB0YdS)NÚrbr) ÚopenrÚ bytearrayÚreadr ÚCryptQueryObjectZCERT_QUERY_OBJECT_BLOBÚCERT_QUERY_CONTENT_FLAG_CERTÚCERT_QUERY_FORMAT_FLAG_ALL)rÚ file_nameÚfÚbufrrrÚ readCertFileGs ûzTestCerts.readCertFilecCs>d}t tt|ƒttd¡}| |dt¡| |dt¡dS)Núwin32crypt_testcert_base64.cerrÚ FormatTypeÚ ContentType) r r$ZCERT_QUERY_OBJECT_FILErr%r&r Ú CERT_QUERY_FORMAT_BASE64_ENCODEDÚCERT_QUERY_CONTENT_CERT)rÚfilenameÚcertrrrÚtestReadCertFilesRsûzTestCerts.testReadCertFilesc Cs¼| |¡}| |d|¡| |dt¡ttdƒ�t}| |dt¡}| t|  ¡ƒ¡|  t|  ¡ƒ¡|  ¡z |  ¡Wnt y�Yn 0tdƒ‚Wdƒn1s®0YdS)Nr,r-ZTempZContextz-should not be able to close the context twice)r*r r/rÚ _CURRENT_USERZ CertAddCertificateContextToStoreZCERT_STORE_ADD_REPLACE_EXISTINGZ assertTrueÚlenZCertEnumCertificatesInStoreZ assertFalseZCertEnumCTLsInStoreZCertFreeCertificateContextÚ ValueErrorÚ RuntimeError)rr0Zexpected_formatr1ÚstoreÚcontextrrrÚ checkCertFilecs  ÿ  zTestCerts.checkCertFilecCs| dt¡dS)Nr+)r9r.©rrrrÚtestCertBase64wsÿzTestCerts.testCertBase64cCs| dt¡dS)Nzwin32crypt_testcert_bin.cer)r9ZCERT_QUERY_FORMAT_BINARYr:rrrÚtestCertBinary|szTestCerts.testCertBinaryN)rrrr*r2r9r;r<rrrrrFs  rÚ__main__)Ú contextlibZunittestÚtypingrrr Zpywin32_testutilrrrZ win32cryptconZTestCaserrr3ÚcontextmanagerÚstrrrrrrrrÚs: