Skip to content
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

Can this support loop through the records #197

Open
kmrsh opened this issue Jun 28, 2020 · 2 comments
Open

Can this support loop through the records #197

kmrsh opened this issue Jun 28, 2020 · 2 comments

Comments

@kmrsh
Copy link

kmrsh commented Jun 28, 2020

I know most ASN.1 libraries can decode the byte stream and populate the given record type. But in most cases one file could contain thousands of such records one after another. Can this library used to decode each record in turn. Another reason for this question is sometimes between two records there can be several bytes with 0 value (which I don't know exactly why, but I've seen in certain telco related data files). Is there a way to skip through these 0 value bytes and decode any valid records.
Thank you

@russhousley
Copy link

You might be able to do something like this ...

from pyasn1.codec.der.decoder import decode as der_decode

bin_file = open("test.bin", "rb")
substrate = bin_file.read()
bin_file.close()

substrate = substrate.lstrip(b'\x00')
while substrate:
    asn1Object, rest = der_decode(substrate, asn1Spec=asn1Spec)
    print(asn1Object.prettyPrint())
    substrate = rest.lstrip(b'\x00')

@ahmedelhaw
Copy link

The padding zeros are for fixed block BER files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants