Main presentation file:
{ "foo": "bar", "value": 9 }
{"value":9,"foo":"bar"}
Circle ::= SEQUENCE {
center_x INTEGER,
center_y INTEGER,
radius INTEGER,
name UTF8String
}
from pyasn1.type.univ import Sequence, Integer
from pyasn1.type.char import UTF8String
from pyasn1.type.namedtype import NamedType, NamedTypes
class Circle(Sequence):
componentType = NamedTypes(
NamedType("center_x", Integer()),
NamedType("center_y", Integer()),
NamedType("radius", Integer()),
NamedType("name", UTF8String()),
)
c = Circle()
c["center_x"] = 10
c["center_y"] = 20
c["radius"] = 100
c["name"] = "Pretty circle"
from pyasn1.codec.der.encoder import encode
e = encode(c)
print(e)
# b'0\x18\x02\x01\n\x02\x01\x14\x02\x01d\x0c\rPretty circle'
print(e.hex())
# 301802010a0201140201640c0d50726574747920636972636c65
$ openssl asn1parse -inform der -in example.der -i
0:d=0 hl=2 l= 24 cons: SEQUENCE
2:d=1 hl=2 l= 1 prim: INTEGER :0A
5:d=1 hl=2 l= 1 prim: INTEGER :14
8:d=1 hl=2 l= 1 prim: INTEGER :64
11:d=1 hl=2 l= 13 prim: UTF8STRING :Pretty circle