def test_length(self): self.failUnlessEqual(der.encode_length(0), "\x00") self.failUnlessEqual(der.encode_length(127), "\x7f") self.failUnlessEqual(der.encode_length(128), "\x81\x80") self.failUnlessEqual(der.encode_length(255), "\x81\xff") self.failUnlessEqual(der.encode_length(256), "\x82\x01\x00") self.failUnlessEqual(der.encode_length(3 * 256 + 7), "\x82\x03\x07") self.failUnlessEqual(der.read_length("\x81\x9b" + "more"), (155, 2)) self.failUnlessEqual(der.encode_length(155), "\x81\x9b") for n in (0, 1, 2, 127, 128, 255, 256, 3 * 256 + 7, 155): x = der.encode_length(n) + "more" n1, llen = der.read_length(x) self.failUnlessEqual(n1, n) self.failUnlessEqual(x[llen:], "more")
def test_length(self): self.assertEqual(der.encode_length(0), b("\x00")) self.assertEqual(der.encode_length(127), b("\x7f")) self.assertEqual(der.encode_length(128), b("\x81\x80")) self.assertEqual(der.encode_length(255), b("\x81\xff")) self.assertEqual(der.encode_length(256), b("\x82\x01\x00")) self.assertEqual(der.encode_length(3 * 256 + 7), b("\x82\x03\x07")) self.assertEqual(der.read_length(b("\x81\x9b") + b("more")), (155, 2)) self.assertEqual(der.encode_length(155), b("\x81\x9b")) for n in (0, 1, 2, 127, 128, 255, 256, 3 * 256 + 7, 155): x = der.encode_length(n) + b("more") n1, llen = der.read_length(x) self.assertEqual(n1, n) self.assertEqual(x[llen:], b("more"))
def test_length(self): self.failUnlessEqual(der.encode_length(0), "\x00") self.failUnlessEqual(der.encode_length(127), "\x7f") self.failUnlessEqual(der.encode_length(128), "\x81\x80") self.failUnlessEqual(der.encode_length(255), "\x81\xff") self.failUnlessEqual(der.encode_length(256), "\x82\x01\x00") self.failUnlessEqual(der.encode_length(3*256+7), "\x82\x03\x07") self.failUnlessEqual(der.read_length("\x81\x9b"+"more"), (155, 2)) self.failUnlessEqual(der.encode_length(155), "\x81\x9b") for n in (0, 1, 2, 127, 128, 255, 256, 3*256+7, 155): x = der.encode_length(n) + "more" n1, llen = der.read_length(x) self.failUnlessEqual(n1, n) self.failUnlessEqual(x[llen:], "more")