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

Reduce num dependencies, improve class implementation and add explicit tags #7

Merged
merged 1 commit into from Dec 14, 2018

Conversation

Flakebi
Copy link
Contributor

@Flakebi Flakebi commented Dec 9, 2018

Hi,
I used yasna to parse ASN.1 before, but as it is not maintained anymore since a while I switched to this library. It works great for almost everything I want to do, just one thing is missing to encode OpenSSL EC keys.
OpenSSL uses for some reason an explicitely tagged value, which is in general used to distinguish multiple optional values with the same type. In the encoding it is a block where the constructed flag is set and the type is not Universal which wraps another block.

I did some reading on ASN.1 and DER (mostly this) and came up with the following:

The default datatypes always have Universal as their class. If we
encounter another class while parsing, it is a tagged block.

I am not sure how (and if at all) we can distinguish explicitly and
implicitly tagged data. For now they should be parsed as unknown (or
explicit if they are a valid ASN.1 block).

PS: As a small change I copied a small pull request from yasna, that reduces the dependencies quite a bit by only importing the needed num crates.

…t tags

The default datatypes always have Universal as their class. If we
encounter another class while parsing, it is a tagged block.

I am not sure how (and if at all) we can distinguish explicitly and
implicitly tagged data. For now they should be parsed as unknown (or
explicit if they are a valid ASN.1 block).
@acw
Copy link
Owner

acw commented Dec 13, 2018

Interesting. The version number stuff is a no-brainer, obviously. Thanks for that.

I'm curious, do you have an online citation for your class/tag interaction? I'm not doubting you -- I looked at what I'll admit was a pretty basic set of resources when I wrote this -- but I'd love to have something I could point at. Failing that, I should accept that if my test cases pass, this must be a correct interpretation of spec. :)

@Flakebi
Copy link
Contributor Author

Flakebi commented Dec 14, 2018

Thanks for taking the time to look at my pr.

I got most information from http://luca.ntop.org/Teaching/Appunti/asn1.html.
Sometimes it is a bit cryptic to read. In the beginning of section 2, it talks about the different classes of tags and for me it seems like only for Universal, the types are defined.

This StackOverflow answer gives a nice explanation why tagging is sometimes needed: https://stackoverflow.com/questions/3296761/i-need-an-example-to-understand-implicit-tagging-in-asn-1

I am by no mean an asn.1 expert, so if you find something that looks fishy, tell me.

Btw your quickcheck tests were really valuable and found one or two bugs in my changes. :)

@acw
Copy link
Owner

acw commented Dec 14, 2018

Cool, that helps. And yes, I ❤️ QuickCheck :)

@acw acw merged commit 56f0c5a into acw:master Dec 14, 2018
@acw
Copy link
Owner

acw commented Dec 14, 2018

... and this is now pushed to crates.io as 0.3.0. Thanks for the patch!

@Flakebi
Copy link
Contributor Author

Flakebi commented Dec 15, 2018

Thanks!

@mehcode
Copy link
Contributor

mehcode commented Dec 15, 2018

With this change, ToASN1::to_asn1_class feels very odd to use (as it passes in a class and ASN1Blocks no longer take the class in all forms.

@acw Also, have you thought about #5 ?

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

Successfully merging this pull request may close these issues.

None yet

3 participants