alex / alex/rust-asn1

New feature: Tag classes should be accounted when writing to DER

オープン
#365 コメント 14 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Rust
スター
135
フォーク
35
平均マージ
1時間 23分
マージ済み PR(30日)
1

説明

Hello again,

thanks for your help so far! :)

I wanted to encode an asn1 specifiction, that uses `application` tags (also given implicit), i.e.:

```
InitiateSession ::= [APPLICATION 0] IMPLICIT SEQUENCE {
a [APPLICATION 10] IMPLICIT OCTET STRING (SIZE(8..32)),
b [APPLICATION 11] IMPLICIT OCTET STRING,
c [APPLICATION 31] IMPLICIT UTF8String (SIZE(1..512)) OPTIONAL,
d [APPLICATION 32] IMPLICIT OCTET STRING (SIZE(2..2)) OPTIONAL
}
```

and my first try was to use this struct with given derive macros:
```Rust

#[derive(asn1::Asn1Read, asn1::Asn1Write, PartialEq, Debug)]
struct InitiateSession<'a> {
#[implicit(10, required)]
a: &'a [u8],
#[implicit(11, required)]
b: &'a [u8],
#[implicit(31)]
c: Option>,
#[implicit(32)]
d: Option<&'a [u8]>,
};

let sid_a: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8];
let login_protocol_list: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8];
let system_use_text = "Hallo Yasin";
let server_msg_buf_size: Vec = vec![1, 2];

let session = InitiateSession {
a: &sid_a,
b: &login_protocol_list,
c: Some(Utf8String::new(system_use_text)),
d: Some(&server_msg_buf_size),
};

let bytes = asn1::write_single(&session).unwrap();
```

What I get are these bytes:
`30 27 8a 08 01 02 03 04 05 06 07 08 8b 08 01 02 03 04 05 06 07 08 9f 1f 0b 48 61 6c 6c 6f 20 59 61 73 69 6e 9f 20 02 01 02`

What I expect them to be (given with [asn1tools](https://pypi.org/project/asn1tools/))
`60 27 4a 08 01 02 03 04 05 06 07 08 4b 08 01 02 03 04 05 06 07 08 5f 1f 0b 48 61 6c 6c 6f 20 59 61 73 69 6e 5f 20 02 01 02`

What I am missing is the definition of [tag classes](https://letsencrypt.org/docs/a-warm-welcome-to-asn1-and-der/#tag-classes) when encoding. The above structure seems to use `universal` tags, as `0x30` is the encoding for the sequence (I think) in universal tags.

TLDR: Is there already a way to define the tag classes, when you want to encode?

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。