def test_application(self): enc = asn1.Encoder() enc.start() enc.enter(1, asn1.ClassApplication) enc.write(1) enc.leave() res = enc.output() assert res == '\x61\x03\x02\x01\x01'
def test_context(self): enc = asn1.Encoder() enc.start() enc.enter(1, asn1.ClassContext) enc.write(1) enc.leave() res = enc.output() assert res == '\xa1\x03\x02\x01\x01'
def test_error_stack(self): enc = asn1.Encoder() enc.start() assert_raises(asn1.Error, enc.leave) enc.enter(asn1.Sequence) assert_raises(asn1.Error, enc.output) enc.leave() assert_raises(asn1.Error, enc.leave)
def test_private(self): enc = asn1.Encoder() enc.start() enc.enter(1, asn1.ClassPrivate) enc.write(1) enc.leave() res = enc.output() assert res == '\xe1\x03\x02\x01\x01'
def test_long_tag_id(self): enc = asn1.Encoder() enc.start() enc.enter(0xffff) enc.write(1) enc.leave() res = enc.output() assert res == '\x3f\x83\xff\x7f\x03\x02\x01\x01'
def test_set_of(self): enc = asn1.Encoder() enc.start() enc.enter(asn1.Set) enc.write(1) enc.write(2) enc.leave() res = enc.output() assert res == '\x31\x06\x02\x01\x01\x02\x01\x02'
def test_set(self): enc = asn1.Encoder() enc.start() enc.enter(asn1.Set) enc.write(1) enc.write('foo') enc.leave() res = enc.output() assert res == '\x31\x08\x02\x01\x01\x04\x03foo'
def test_error_object_identifier(self): enc = asn1.Encoder() enc.start() assert_raises(asn1.Error, enc.write, '1', asn1.ObjectIdentifier) assert_raises(asn1.Error, enc.write, '40.2.3', asn1.ObjectIdentifier) assert_raises(asn1.Error, enc.write, '1.40.3', asn1.ObjectIdentifier) assert_raises(asn1.Error, enc.write, '1.2.3.', asn1.ObjectIdentifier) assert_raises(asn1.Error, enc.write, '.1.2.3', asn1.ObjectIdentifier) assert_raises(asn1.Error, enc.write, 'foo', asn1.ObjectIdentifier) assert_raises(asn1.Error, enc.write, 'foo.bar', asn1.ObjectIdentifier)
def test_long_object_identifier(self): enc = asn1.Encoder() enc.start() enc.write('39.2.3', asn1.ObjectIdentifier) res = enc.output() assert res == '\x06\x03\x8c\x1a\x03' enc.start() enc.write('1.39.3', asn1.ObjectIdentifier) res = enc.output() assert res == '\x06\x02\x4f\x03' enc.start() enc.write('1.2.300000', asn1.ObjectIdentifier) res = enc.output() assert res == '\x06\x04\x2a\x92\xa7\x60'
def test_twos_complement_boundaries(self): enc = asn1.Encoder() enc.start() enc.write(127) res = enc.output() assert res == '\x02\x01\x7f' enc.start() enc.write(128) res = enc.output() assert res == '\x02\x02\x00\x80' enc.start() enc.write(-128) res = enc.output() assert res == '\x02\x01\x80' enc.start() enc.write(-129) res = enc.output() assert res == '\x02\x02\xff\x7f'
def test_long_negative_integer(self): enc = asn1.Encoder() enc.start() enc.write(-0x0102030405060708090a0b0c0d0e0f) res = enc.output() assert res == '\x02\x0f\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1\xf1'
def test_long_integer(self): enc = asn1.Encoder() enc.start() enc.write(0x0102030405060708090a0b0c0d0e0f) res = enc.output() assert res == '\x02\x0f\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'
def test_negative_integer(self): enc = asn1.Encoder() enc.start() enc.write(-1) res = enc.output() assert res == '\x02\x01\xff'
def test_enumerated(self): enc = asn1.Encoder() enc.start() enc.write(1, asn1.Enumerated) res = enc.output() assert res == '\x0a\x01\x01'
def test_boolean(self): enc = asn1.Encoder() enc.start() enc.write(True, asn1.Boolean) res = enc.output() assert res == '\x01\x01\xff'
def test_real_object_identifier(self): enc = asn1.Encoder() enc.start() enc.write('1.2.840.113554.1.2.1.1', asn1.ObjectIdentifier) res = enc.output() assert res == '\x06\x0a\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01'
def test_object_identifier(self): enc = asn1.Encoder() enc.start() enc.write('1.2.3', asn1.ObjectIdentifier) res = enc.output() assert res == '\x06\x02\x2a\x03'
def test_octet_string(self): enc = asn1.Encoder() enc.start() enc.write('foo') res = enc.output() assert res == '\x04\x03foo'
def test_null(self): enc = asn1.Encoder() enc.start() enc.write(None) res = enc.output() assert res == '\x05\x00'
def test_long_tag_length(self): enc = asn1.Encoder() enc.start() enc.write('x' * 0xffff) res = enc.output() assert res == '\x04\x82\xff\xff' + 'x' * 0xffff
def test_error_init(self): enc = asn1.Encoder() assert_raises(asn1.Error, enc.enter, asn1.Sequence) assert_raises(asn1.Error, enc.leave) assert_raises(asn1.Error, enc.write, 1) assert_raises(asn1.Error, enc.output)
def test_integer(self): enc = asn1.Encoder() enc.start() enc.write(1) res = enc.output() assert res == b'\x02\x01\x01'