def test_long_object_identifier(self):
     dec = asn1.Decoder()
     buf = b'\x06\x03\x8c\x1a\x03'
     dec.start(buf)
     tag, val = dec.read()
     assert val == b'39.2.3'
     buf = b'\x06\x02\x4f\x03'
     dec.start(buf)
     tag, val = dec.read()
     assert val == b'1.39.3'
     buf = b'\x06\x04\x2a\x92\xa7\x60'
     dec.start(buf)
     tag, val = dec.read()
     assert val == b'1.2.300000'
 def test_twos_complement_boundaries(self):
     buf = '\x02\x01\x7f'
     dec = asn1.Decoder()
     dec.start(buf)
     tag, val = dec.read()
     assert val == 127
     buf = '\x02\x02\x00\x80'
     dec.start(buf)
     tag, val = dec.read()
     assert val == 128
     buf = '\x02\x01\x80'
     dec.start(buf)
     tag, val = dec.read()
     assert val == -128
     buf = '\x02\x02\xff\x7f'
     dec.start(buf)
     tag, val = dec.read()
     assert val == -129
 def test_boolean(self):
     buf = '\x01\x01\xff'
     dec = asn1.Decoder()
     dec.start(buf)
     tag = dec.peek()
     assert tag == (asn1.Boolean, asn1.TypePrimitive, asn1.ClassUniversal)
     tag, val = dec.read()
     assert isinstance(val, int)
     assert val == True
     buf = '\x01\x01\x01'
     dec.start(buf)
     tag, val = dec.read()
     assert isinstance(val, int)
     assert val == True
     buf = '\x01\x01\x00'
     dec.start(buf)
     tag, val = dec.read()
     assert isinstance(val, int)
     assert val == False
 def test_error_non_normalized_negative_integer(self):
     buf = '\x02\x02\xff\x80'
     dec = asn1.Decoder()
     dec.start(buf)
     assert_raises(asn1.Error, dec.read)
 def test_error_missing_value_bytes(self):
     buf = '\x02\x02\x01'
     dec = asn1.Decoder()
     dec.start(buf)
     assert_raises(asn1.Error, dec.read)
 def test_error_too_many_length_bytes(self):
     buf = '\x04\xff' + '\xff' * 0x7f
     dec = asn1.Decoder()
     dec.start(buf)
     assert_raises(asn1.Error, dec.read)
 def test_error_missing_length_bytes(self):
     buf = '\x04\x82\xff'
     dec = asn1.Decoder()
     dec.start(buf)
     assert_raises(asn1.Error, dec.read)
 def test_error_no_length_bytes(self):
     buf = '\x02'
     dec = asn1.Decoder()
     dec.start(buf)
     assert_raises(asn1.Error, dec.read)
 def test_no_input(self):
     dec = asn1.Decoder()
     dec.start('')
     tag = dec.peek()
     assert tag is None
 def test_error_non_normalized_positive_integer(self):
     buf = b'\x02\x02\x00\x01'
     dec = asn1.Decoder()
     dec.start(buf)
     assert_raises(asn1.Error, dec.read)
 def test_long_tag_length(self):
     buf = '\x04\x82\xff\xff' + 'x' * 0xffff
     dec = asn1.Decoder()
     dec.start(buf)
     tag, val = dec.read()
     assert val == 'x' * 0xffff
 def test_real_object_identifier(self):
     dec = asn1.Decoder()
     buf = '\x06\x0a\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01'
     dec.start(buf)
     tag, val = dec.read()
     assert val == '1.2.840.113554.1.2.1.1'
 def test_long_negative_integer(self):
     buf = '\x02\x0f\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1\xf1'
     dec = asn1.Decoder()
     dec.start(buf)
     tag, val = dec.read()
     assert val == -0x0102030405060708090a0b0c0d0e0f
 def test_negative_integer(self):
     buf = '\x02\x01\xff'
     dec = asn1.Decoder()
     dec.start(buf)
     tag, val = dec.read()
     assert val == -1
 def test_long_integer(self):
     buf = '\x02\x0f\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'
     dec = asn1.Decoder()
     dec.start(buf)
     tag, val = dec.read()
     assert val == 0x0102030405060708090a0b0c0d0e0f
 def test_error_non_normalised_object_identifier(self):
     buf = '\x06\x02\x80\x01'
     dec = asn1.Decoder()
     dec.start(buf)
     assert_raises(asn1.Error, dec.read)
 def test_error_object_identifier_with_too_large_first_component(self):
     buf = '\x06\x02\x8c\x40'
     dec = asn1.Decoder()
     dec.start(buf)
     assert_raises(asn1.Error, dec.read)
 def test_error_init(self):
     dec = asn1.Decoder()
     assert_raises(asn1.Error, dec.peek)
     assert_raises(asn1.Error, dec.read)
     assert_raises(asn1.Error, dec.enter)
     assert_raises(asn1.Error, dec.leave)