Encode primitive vs constructed form #6

Merged
mehcode merged 1 commits from feature/constructed into master 2018-11-16 10:31:12 -08:00
mehcode commented 2018-11-06 15:15:27 -08:00 (Migrated from github.com)

SEQUENCE should always be encoded as 0x30 which is 0b10_0000 | 0x10 which means type 16 in "constructed" form. Bit5 unset means "primitive" form and is illegal for SEQUENCE but Go is strict and without this patch I couldn't get keys generated and encoded in Rust that Go would accept.

Example public key I generated without this patch:

102a100506032b6570032100b87ffc42162808917fa511a266446f5ab53c2737f45f3f79c0fc48314d902be3

Example now with this patch:

302a300506032b6570032100b87ffc42162808917fa511a266446f5ab53c2737f45f3f79c0fc48314d902be3

https://github.com/hashgraph/hedera-sdk-rust/blob/master/examples/generate_keys.rs#L8


https://lapo.it/asn1js/ fails to parse SEQUENCE as 0x10 as well.

`SEQUENCE` should always be encoded as `0x30` which is `0b10_0000 | 0x10` which means type `16` in "constructed" form. Bit5 unset means "primitive" form and is illegal for `SEQUENCE` but Go is strict and without this patch I couldn't get keys generated and encoded in Rust that Go would accept. Example public key I generated without this patch: ``` 102a100506032b6570032100b87ffc42162808917fa511a266446f5ab53c2737f45f3f79c0fc48314d902be3 ``` Example now with this patch: ``` 302a300506032b6570032100b87ffc42162808917fa511a266446f5ab53c2737f45f3f79c0fc48314d902be3 ``` https://github.com/hashgraph/hedera-sdk-rust/blob/master/examples/generate_keys.rs#L8 --- https://lapo.it/asn1js/ fails to parse `SEQUENCE` as `0x10` as well.
acw (Migrated from github.com) reviewed 2018-11-06 17:05:09 -08:00
acw (Migrated from github.com) commented 2018-11-06 17:05:09 -08:00

This appears to mask off the ASN.1 class associated with this tag. Is there something about large tag values that means that the class must be universal? I would have expected a mask of 0b11011111 given the rest of your description.

This appears to mask off the ASN.1 class associated with this tag. Is there something about large tag values that means that the class *must* be universal? I would have expected a mask of `0b11011111` given the rest of your description.
acw commented 2018-11-06 17:07:04 -08:00 (Migrated from github.com)

Another question; do you have any sources we can cite, somewhere in a comment, about this annoying thing? [I'll merge the change without such a source, pending the mask issue I pointed out, but I'd love to make this mask be not totally mysterious.]

Another question; do you have any sources we can cite, somewhere in a comment, about this annoying thing? [I'll merge the change without such a source, pending the mask issue I pointed out, but I'd love to make this mask be not totally mysterious.]
mehcode (Migrated from github.com) reviewed 2018-11-14 09:52:23 -08:00
mehcode (Migrated from github.com) commented 2018-11-14 09:52:23 -08:00

Not sure I follow.

Class byte should be at most 0b11_00_00_00.
Encoding form byte is 0b00_10_00_00.

Not sure I follow. Class byte should be at most `0b11_00_00_00`. Encoding form byte is `0b00_10_00_00`.
mehcode commented 2018-11-14 09:52:58 -08:00 (Migrated from github.com)
@acw See https://docs.microsoft.com/en-us/windows/desktop/seccertenroll/about-encoded-tag-bytes
mehcode commented 2018-11-14 18:54:34 -08:00 (Migrated from github.com)

Looking back at this we can simply change the sequence tag byte to 0x30 instead of my primitive flag

Looking back at this we can simply change the sequence tag byte to 0x30 instead of my primitive flag
mehcode commented 2018-11-14 21:32:03 -08:00 (Migrated from github.com)

@acw Cleaned up the PR and cited documentation in the code


I'd appreciate if you could merge and release as soon as you can. I need to cut a new release of hedera and am blocked on this. Anything else you need me to do, please let me know.

@acw Cleaned up the PR and cited documentation in the code --- I'd appreciate if you could merge and release as soon as you can. I need to cut a new release of [`hedera`](https://github.com/hashgraph/hedera-sdk-rust) and am blocked on this. Anything else you need me to do, please let me know.
acw commented 2018-11-16 10:47:17 -08:00 (Migrated from github.com)

... and pushed it to crates. It's version 0.2.1, for your Cargo.toml pleasure.

... and pushed it to crates. It's version 0.2.1, for your Cargo.toml pleasure.
mehcode commented 2018-11-16 11:01:10 -08:00 (Migrated from github.com)

Thank you very much @acw 😄

Thank you very much @acw 😄
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: acw/simple_asn1#6