-
-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recursive parsing (how to do) #198
Comments
Hello! #!/usr/bin/env python3
from asn1crypto.core import Sequence, SequenceOf, Integer
import json
class ManyFoo(SequenceOf):
_child_spec = None
class Foo(Sequence):
_fields = [
("1st", Integer),
("2nd", Integer),
("rec", ManyFoo, {"optional": True}),
]
# That part is especially ugly.
ManyFoo._child_spec = Foo
orig = {
"1st": 10,
"2nd": 20,
"rec": [
{
"1st": 7,
"2nd": 123,
"rec": [
{
"1st": 100,
"2nd": 200,
"rec": []
}
]
},
{
"1st": 70,
"2nd": 1230,
"rec": [
{
"1st": 400,
"2nd": 800,
"rec": [
{
"1st": 1000,
"2nd": 20000,
"rec": []
}
]
},
{
"1st": 500,
"2nd": 600,
"rec": []
}
]
}
]
}
encoded = Foo(orig).dump()
print(encoded.hex())
decoded = Foo.load(encoded)
print(orig == decoded.native)
print()
print(json.dumps(decoded.native, indent=4, sort_keys=True)) |
Hello Jörn, thank you for replying. That helps, to some extent, but I still cannot extract some inner field because it's a tagged field (like e.g. [3] foobar UTF8String). How do I extract a tagged field from a Sequence? If temp is a Sequence, I get an error if I try temp[0] to extract the first field (which happens to be a tagged field):
|
@defacto64 Is the tagged field an implicit or explicit field? If you look through the various modules in the package (other than |
Hi,
I have to parse a nested ASN.1 object that is a SEQUENCE OF items that are in turn SEQUENCE objects themselves. I am not sure how to do that using asn1crypto.
I mean: with Sequence.load(der_bytes) I can instantiate the outer sequence, but then how do I parse the inner objects?
Should I extract the der encoding of the inner objects, and the call load() again ? If so, how do I do that?
The text was updated successfully, but these errors were encountered: