geoffgarside / ber

Fork of golang pkg `encoding/asn1` to support the Basic Encoding Rules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Indefinite length values

dimuls opened this issue · comments

Can you implement indefinite length values, please?

Is this already implemented in the Golang encoding/asn1 package? If not, can you point me to the specs for it?

No, it isn't. There is abandoned implementation https://go-review.googlesource.com/c/go/+/13746 which i have found. But it seems not working well: it doesn't parse BER data i need.

Spec is T-REC-X.690-201508-I!!PDF-E.pdf, it starts from 8.1.3.1.

Thanks, I'm getting the code cleaned up and brought up to date for 1.14 first, then I'll start looking at this.

You mentioned the abandoned implementation wasn't parsing the BER data you need it to. Do you have any examples of the bytes and expected output you can share? (there may be some in the PDF, I've not looked yet)

I wrote my own implementation of indefinite length values (based on abandoned implementation which i mentioned above) but i'm not sure if it will work in all cases.

About examples: i can't share them due to legal restrictions, but the main problem was in alignment zeros in files (which is not in BER specification). Second problem was fixed by removing all DER restrictions from parseTagAndLength function.

If you will implement BER with indefinite lengths i can help with testing it on my files.

Can you have a look at #4 when you get a chance

I decided to write my own BER parser because using golang DER based parser it is hard to parse CHOICE type (which is common in my data). Anyway, thank you, maybe some one will find this useful.