rusticata / asn1-rs

Parsers/Encoders for ASN.1 BER/DER data
Apache License 2.0
10 stars 14 forks source link

Serialized tag of `SetOf` is not correct #30

Closed yestyle closed 8 months ago

yestyle commented 10 months ago

Hi there,

I was trying to use this crate to serialize a SetOf data and found that the serialized tag of SetOf is 0x30, but the correct one should be 0x31 if I understand it correctly.

The issue can be demonstrated by a simple example:

let it = [2, 3, 4].iter();
let set = SetOf::from_iter(it);
let mut der = Vec::new();
set.write_der(&mut der).unwrap();

The content of der is:

30 09 02 01 02 02 01 03 02 01 04

which I think should be:

31 09 02 01 02 02 01 03 02 01 04

My wild guess is that the tag for Vec is always Tag::Sequence.

Could you please advise if this is an issue or not? Thanks.

chifflier commented 8 months ago

Hi, You're right, the encoding is wrong. The set is internally using a Vec, and write_der_header was delegating the call. This is fixed in the next commit. Thanks