示例#1
0
 def readline(self, size=4096):
     # type: (int) -> bytes
     if not self.readable():
         raise IOError('cannot read')
     buf = m2.bio_gets(self.bio, size)
     buf = '' if buf is None else buf
     return util.py3bytes(buf)
示例#2
0
文件: BIO.py 项目: mcepl/M2Crypto
 def readline(self, size=4096):
     # type: (int) -> bytes
     if not self.readable():
         raise IOError('cannot read')
     buf = m2.bio_gets(self.bio, size)
     buf = '' if buf is None else buf
     return six.ensure_binary(buf)
示例#3
0
文件: BIO.py 项目: rodrigc/m2crypto
 def readlines(self, sizehint='ignored'):
     if not self.readable():
         raise IOError('cannot read')
     lines = []
     while 1:
         buf = m2.bio_gets(self.bio, 4096)
         if buf is None:
             break
         lines.append(buf)
     return lines
示例#4
0
 def readlines(self, sizehint='ignored'):
     if not self.readable():
         raise IOError('cannot read')
     lines = []
     while 1:
         buf = m2.bio_gets(self.bio, 4096)
         if buf is None:
             break
         lines.append(buf)
     return lines
示例#5
0
 def readlines(self, sizehint='ignored'):
     # type: (Union[AnyStr, int]) -> Iterable[bytes]
     if not self.readable():
         raise IOError('cannot read')
     lines = []
     while 1:
         buf = m2.bio_gets(self.bio, 4096)
         if buf is None:
             break
         lines.append(util.py3bytes(buf))
     return lines
示例#6
0
文件: BIO.py 项目: mcepl/M2Crypto
 def readlines(self, sizehint='ignored'):
     # type: (Union[AnyStr, int]) -> Iterable[bytes]
     if not self.readable():
         raise IOError('cannot read')
     lines = []
     while 1:
         buf = m2.bio_gets(self.bio, 4096)
         if buf is None:
             break
         lines.append(six.ensure_binary(buf))
     return lines
示例#7
0
文件: c.py 项目: xampserver1/M2Crypto
def c_style(HOST, PORT, req):

    # Set up SSL context.
    ctx = m2.ssl_ctx_new(m2.sslv3_method())
    m2.ssl_ctx_use_cert(ctx, 'client.pem')
    m2.ssl_ctx_use_privkey(ctx, 'client.pem')

    # Make the socket connection.
    s = socket(AF_INET, SOCK_STREAM)
    s.connect((HOST, PORT))

    # Set up the SSL connection.
    sbio = m2.bio_new_socket(s.fileno(), 0)
    ssl = m2.ssl_new(ctx)
    m2.ssl_set_bio(ssl, sbio, sbio)
    m2.ssl_connect(ssl)
    sslbio = m2.bio_new(m2.bio_f_ssl())
    m2.bio_set_ssl(sslbio, ssl, 0)

    # Push a buffering BIO over the SSL BIO.
    iobuf = m2.bio_new(m2.bio_f_buffer())
    topbio = m2.bio_push(iobuf, sslbio)

    # Send the request.
    m2.bio_write(sslbio, req)

    # Receive the response.
    while 1:
        data = m2.bio_gets(topbio, 4096)
        if not data: break
        sys.stdout.write(data)

    # Cleanup. May be missing some necessary steps. ;-|
    m2.bio_pop(topbio)
    m2.bio_free(iobuf)
    m2.ssl_shutdown(ssl)
    m2.ssl_free(ssl)
    m2.ssl_ctx_free(ctx)
    s.close()
示例#8
0
文件: c.py 项目: 0xkag/M2Crypto
def c_style(HOST, PORT, req):

    # Set up SSL context.
    ctx = m2.ssl_ctx_new(m2.sslv3_method())
    m2.ssl_ctx_use_cert(ctx, 'client.pem')
    m2.ssl_ctx_use_privkey(ctx, 'client.pem')

    # Make the socket connection.
    s = socket(AF_INET, SOCK_STREAM)
    s.connect((HOST, PORT))

    # Set up the SSL connection.
    sbio = m2.bio_new_socket(s.fileno(), 0)
    ssl = m2.ssl_new(ctx)
    m2.ssl_set_bio(ssl, sbio, sbio)
    m2.ssl_connect(ssl)
    sslbio = m2.bio_new(m2.bio_f_ssl())
    m2.bio_set_ssl(sslbio, ssl, 0)

    # Push a buffering BIO over the SSL BIO.
    iobuf = m2.bio_new(m2.bio_f_buffer())
    topbio = m2.bio_push(iobuf, sslbio)

    # Send the request.
    m2.bio_write(sslbio, req)

    # Receive the response.
    while 1:
        data = m2.bio_gets(topbio, 4096)
        if not data: break
        sys.stdout.write(data)

    # Cleanup. May be missing some necessary steps. ;-|
    m2.bio_pop(topbio)
    m2.bio_free(iobuf)
    m2.ssl_shutdown(ssl)
    m2.ssl_free(ssl)
    m2.ssl_ctx_free(ctx)
    s.close()
示例#9
0
 def readline(self, size=4096):
     # type: (int) -> bytes
     if not self.readable():
         raise IOError('cannot read')
     buf = m2.bio_gets(self.bio, size)
     return buf
示例#10
0
文件: BIO.py 项目: rodrigc/m2crypto
 def readline(self, size=4096):
     if not self.readable():
         raise IOError('cannot read')
     buf = m2.bio_gets(self.bio, size)
     return buf