예제 #1
0
 def test_bio_read_write(self):
     try:
         method = api.BIO_s_mem()
         mem = api.BIO_new(method)
         data = api.new('char[]', b"HELLO WORLD")
         api.BIO_write(mem, data, 11)
         buf = api.new('char[]', 5)
         api.BIO_read(mem, buf, len(buf))
         self.assertEqual(api.string(buf), b"HELLO")
         api.BIO_gets(mem, buf, len(buf))
         self.assertEqual(api.string(buf), b" WOR")
     finally:
         api.BIO_free(mem)
예제 #2
0
파일: _chain.py 프로젝트: exarkun/opentls
 def read(self, n=-1):
     if n < 0:
         return self.readall()
     data = api.new('char[]', n)
     read = api.BIO_read(self._bio, data, len(data))
     if read < 0:
         raise IOError('unsupported operation')
     return api.string(data)
예제 #3
0
 def read(self, n=-1):
     if n < 0:
         return self.readall()
     data = api.new('char[]', n)
     read = api.BIO_read(self._bio, data, len(data))
     if read < 0:
         raise IOError('unsupported operation')
     return api.string(data)
예제 #4
0
파일: util.py 프로젝트: exarkun/opentls
 def add_to_names(obj, _):
     if obj.alias:
         return
     name = obj.name
     nid = api.OBJ_sn2nid(name)
     if nid == api.NID_undef:
         nid = api.OBJ_ln2nid(name)
     if nid != api.NID_undef:
         hashes.setdefault(nid, set()).add(api.string(name))
예제 #5
0
 def test_ctrl_pending(self):
     pending = api.BIO_ctrl_pending(self.bio)
     self.assertEqual(pending, len(api.string(self.data)))
예제 #6
0
 def test_gets(self):
     buf = api.new('char[]', len(self.data))
     got = api.BIO_gets(self.bio, buf, len(buf))
     self.assertEqual(got + 1, len(buf))
     self.assertEqual(api.string(buf), api.string(self.data))
예제 #7
0
 def test_read_long(self):
     buf = api.new('char[]', 2 * len(self.data))
     size = api.BIO_read(self.bio, buf, len(buf))
     self.assertEqual(size, len(api.string(self.data)))
예제 #8
0
 def name(self):
     if self._cipher == api.NULL:
         raise ValueError("Cipher object failed to be initialised")
     return api.string(api.OBJ_nid2sn(api.EVP_CIPHER_nid(self._cipher)))
예제 #9
0
 def test_puts(self):
     put = api.BIO_puts(self.bio, self.data)
     self.assertEqual(api.BIO_wpending(self.bio), 0)
     self.assertEqual(put, len(api.string(self.data)))
예제 #10
0
 def test_error_string(self):
     value = api.ERR_error_string(self.code, api.NULL)
     self.assertEqual(api.string(value), self.text)
예제 #11
0
 def _test_md_nid(self, nid, name):
     self.assertEqual(name, api.string(api.OBJ_nid2sn(nid)))
     md = api.EVP_get_digestbynid(nid)
     self.assertTrue(md)
예제 #12
0
 def _test_md_nid(self, nid, name):
     self.assertEqual(name, api.string(api.OBJ_nid2sn(nid)))
     md = api.EVP_get_digestbynid(nid)
     self.assertTrue(md)
예제 #13
0
파일: hashlib.py 프로젝트: exarkun/opentls
 def name(self):
     nid = api.EVP_MD_CTX_type(self._context)
     name = api.OBJ_nid2sn(nid)
     if name == api.NULL:
         raise DigestError('Failed to get digest name')
     return api.string(name)
예제 #14
0
 def test_filter(self):
     buf = api.new('char[]', len(self.output))
     api.BIO_write(self.bio, self.input, len(api.string(self.input)))
     api.BIO_flush(self.bio)
     api.BIO_read(self.sink, buf, len(buf))
     self.assertEqual(api.string(buf), api.string(self.output))
예제 #15
0
 def test_seek(self):
     api.BIO_seek(self.bio, 1)
     buf = api.new('char[]', len(self.data))
     read = api.BIO_read(self.bio, buf, len(buf))
     self.assertEqual(read, len(api.string(self.data)) - 1)
     self.assertEqual(api.string(buf), api.string(self.data)[1:])
예제 #16
0
 def test_error_string_n(self):
     stop = len(self.text) - 1
     buf = api.new('char[]', 2 * len(self.text))
     api.ERR_error_string_n(self.code, buf, stop)
     self.assertEqual(api.string(buf), self.text[:stop - 1])
예제 #17
0
 def test_eof(self):
     buf = api.new('char[]', len(self.data) + 1)
     read = api.BIO_read(self.bio, buf, len(buf))
     self.assertEqual(read, len(api.string(self.data)))
     self.assertTrue(api.BIO_eof(self.bio))
예제 #18
0
 def test_func_error_string(self):
     value = api.ERR_func_error_string(self.code)
     self.assertEqual(api.string(value), self.text.split(b':')[3])
예제 #19
0
 def setUpClass(cls):
     fd, cls.name = tempfile.mkstemp()
     os.close(fd)
     with open(cls.name, 'wb') as dest:
         dest.write(api.string(cls.data))
예제 #20
0
 def test_reason_error_string(self):
     value = api.ERR_reason_error_string(self.code)
     self.assertEqual(api.string(value), self.text.split(b':')[4])
예제 #21
0
 def test_read_all(self):
     buf = api.new('char[]', len(self.data))
     read = api.BIO_read(self.bio, buf, len(buf))
     self.assertEqual(read, len(api.string(buf)))
     self.assertEqual(api.string(buf), api.string(self.data))
예제 #22
0
 def setUp(self):
     fileobj = BytesIO(api.string(self.data))
     self.bio = io.wrap_io(fileobj)
예제 #23
0
파일: test_obj.py 프로젝트: exarkun/opentls
 def test_nid2sn(self):
     name = api.OBJ_nid2sn(api.NID_md5)
     self.assertEqual(b'MD5', api.string(name))
예제 #24
0
 def setUp(self):
     fileobj = BytesIO(api.string(self.data))
     self.bio = io.wrap_io(fileobj)