Example #1
0
  def test_packing(self):
    cert, content = Certificate.pop(b'\x02\x00\x04\x00\x00\x01\x01\x04\x04aq\x0f\x02\x00\x00\x00\x00')
    self.assertEqual(b'\x04\x04aq\x0f\x02\x00\x00\x00\x00', content)

    self.assertEqual(CertType.IDENTITY, cert.type)
    self.assertEqual(2, cert.type_int)
    self.assertEqual(b'\x00\x00\x01\x01', cert.value)
    self.assertEqual(b'\x02\x00\x04\x00\x00\x01\x01', cert.pack())
Example #2
0
  def _unpack(cls, content, circ_id, link_protocol):
    cert_count, content = Size.CHAR.pop(content)
    certs = []

    for i in range(cert_count):
      if not content:
        raise ValueError('CERTS cell indicates it should have %i certificates, but only contained %i' % (cert_count, len(certs)))

      cert, content = Certificate.pop(content)
      certs.append(cert)

    return CertsCell(certs, unused = content)
Example #3
0
File: cell.py Project: zmchu/stem
    def _unpack(
        cls, content: bytes, circ_id: int,
        link_protocol: 'stem.client.datatype.LinkProtocol'
    ) -> 'stem.client.cell.CertsCell':
        cert_count, content = Size.CHAR.pop(content)
        certs = []  # type: List[stem.client.datatype.Certificate]

        for i in range(cert_count):
            if not content:
                raise ValueError(
                    'CERTS cell indicates it should have %i certificates, but only contained %i'
                    % (cert_count, len(certs)))

            cert, content = Certificate.pop(content)
            certs.append(cert)

        return CertsCell(certs, unused=content)