1Mc@sdZddlZddlmZddlmZdefdYZejedddYZ d e fd YZ d e fd YZ d dZ de fdYZ de fdYZde fdYZdS(scM2Crypto wrapper for OpenSSL BIO API. Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved.iN(tbio_do_handshake(tStringIOtBIOErrorcBseZRS((t__name__t __module__(((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR stBIOcBseZdZejZddddZdZdZ e Z dZ dZ ddZ dd Zd d Zd Zd ZdZdZdZdZdZdZdZRS(s)Abstract object interface to the BIO API.icCs1||_||_||_d|_d|_dS(Ni(tbiot_pyfreet _close_cbtclosedt write_closed(tselfRRR((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyt__init__s     cCs |jr|j|jndS(N(Rt m2_bio_freeR(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyt__del__s cCs|jS(N(R(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyt_ptr!scCstj|jS(N(tm2t bio_get_fdR(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pytfileno'scCs|j S(N(R (R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pytreadable*scCs|jstdn|dkrit}x/tj|jd}|sOPn|j|q0|jS|dkrydS|dkrt dntj|j|SdS(Ns cannot readiitsread count is negative( RtIOErrortNoneRRtbio_readRtwritetgetvaluet ValueError(R tsizetbuftdata((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pytread-s        icCs1|jstdntj|j|}|S(Ns cannot read(RRRtbio_getsR(R RR((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pytreadline>s  tignoredcCsZ|jstdng}x5tj|jd}|dkrFPn|j|q!|S(Ns cannot readi(RRRRRRtappend(R tsizehinttlinesR((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyt readlinesDs   cCs|j o|j S(N(R R (R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyt writeableOscCs+|jstdntj|j|S(Ns cannot write(R&RRt bio_writeR(R R((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyRRs  cCs d|_dS(Ni(R (R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyt write_closeWscCstj|jdS(N(Rt bio_flushR(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pytflushZscCstj|jS(s3 Sets the bio to its initial state (Rt bio_resetR(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pytreset]scCs#d|_|jr|jndS(Ni(R R(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pytclosecs  cCstj|jS(si Can the call be attempted again, or was there an error ie do_handshake (Rtbio_should_retryR(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyt should_retryhscCstj|jS(se Returns whether the cause of the condition is the bio should read more data (Rtbio_should_readR(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyt should_readpscCstj|jS(sf Returns whether the cause of the condition is the bio should write more data (Rtbio_should_writeR(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyt should_writewsN(RRt__doc__Rtbio_freeR RR RRtbio_ptrRRRR R%R&RR(R*R,R-R/R1R3(((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyRs(               t MemoryBuffercBsHeZdZddZdZddZeZZdZ e Z RS(sw Object interface to BIO_s_mem. Empirical testing suggests that this class performs less well than cStringIO, because cStringIO is implemented in C, whereas this class is implemented in Python. Thus, the recommended practice is to use cStringIO for regular work and convert said cStringIO object to a MemoryBuffer object only when necessary. cCsTtj|tjtj|_d|_|dk rPtj|j|ndS(Ni( RR Rtbio_newt bio_s_memRRRR'(R R((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR s    cCstj|jS(N(Rtbio_ctrl_pendingR(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyt__len__sicCsT|jstdn|r1tj|j|Stj|jtj|jSdS(Ns cannot read(RRRRRR:(R R((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyRs   cCs d|_tj|jddS(Nii(R Rtbio_set_mem_eof_returnR(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR(s N( RRR4RR R;RRtread_allR(R-(((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR7~s     tFilecBs#eZdZddZdZRS(s Object interface to BIO_s_fp. This class interfaces Python to OpenSSL functions that expect BIO *. For general file manipulation in Python, use Python's builtin file object. icCs>tj|dd||_||_tj|d|_dS(NRii(RR tpyfilet close_pyfileRt bio_new_fpR(R R?R@((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR s  cCs&d|_|jr"|jjndS(Ni(R R@R?R-(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR-s  (RRR4R R-(((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR>s trbcCstt||S(N(R>topen(tfilenametmode((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pytopenfilestIOBuffercBsAeZdZejZejZdddZdZ dZ RS(s Object interface to BIO_f_buffer. Its principal function is to be BIO_push()'ed on top of a BIO_f_ssl, so that makefile() of said underlying SSL socket works. trwbicCswtj|d|tjtj|_tj|j|j|_||_ d|krjd|_ n d|_ dS(NRtwii( RR RR8t bio_f_buffertiotbio_pushRRt _under_bioR (R t under_bioRER((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR s   cCs9t|ddr%|j|jn|j|jdS(NRi(tgetattrt m2_bio_popRR RK(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyRscCstj|dS(N(RR-(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR-s( RRR4Rtbio_popRPR5R R RR-(((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyRGs    t CipherStreamcBsVeZdZejZejZejZ dZ dZ dZ dZ dZRS(s+ Object interface to BIO_f_cipher. cCsAtj|dd||_tjtj|_d|_dS(NRii(RR tobioRR8t bio_f_cipherRR (R RS((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR s cCs#t|dds|jndS(NR i(ROR-(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyRscCs-|j|j|j|jd|_dS(Ni(RPRR R (R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR-scCs|jjdS(N(RSR((R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR(scCsott|d}|dkr0td|fntj|j||||tj|j|jjdS(Nsunknown cipher( RORRRtbio_set_cipherRRLRSR(R talgotkeytivtoptcipher((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyt set_ciphers  (RRR4RtPKCS5_SALT_LENtSALT_LENRQRPR5R R RR-R(R[(((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyRRs       tSSLBiocBs2eZdZddZejdZdZRS(s( Object interface to BIO_f_ssl icCs5tj||tjtj|_d|_dS(Ni(RR RR8t bio_f_sslRR (R R((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR scCsHd|_tj|j|j||tjkrD|jtjndS(sh Sets the bio to the SSL pointer which is contained in the connection object. iN(RRt bio_set_sslRtsslt bio_noclosetset_ssl_close_flagt bio_close(R tconnt close_flag((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pytset_ssl s cCstj|jS(s Do the handshake. Return 1 if the handshake completes Return 0 or a negative number if there is a problem (RRR(R ((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyt do_handshakes(RRR4R RRbRgRh(((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyR^s  ((R4RRtbio_do_ssl_handshaket cStringIORt ExceptionRtbio_initRR7R>RFRGRRR^(((s2/usr/lib64/python2.7/site-packages/M2Crypto/BIO.pyts  n'  %