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

der: derive(Sequence) with [u8; N] field #1730

Open
dishmaker opened this issue Mar 21, 2025 · 1 comment
Open

der: derive(Sequence) with [u8; N] field #1730

dishmaker opened this issue Mar 21, 2025 · 1 comment

Comments

@dishmaker
Copy link
Contributor

dishmaker commented Mar 21, 2025

[u8; N] arrays should be allowed as OCTET STRING fields.

#[derive(Sequence)]
pub struct MySequence {
    #[asn1(context_specific = "2", type = "OCTET STRING")]
    pub authority_reference: [u8; 8],
}
error[E0277]: the trait bound `der::asn1::OctetStringRef<'_>: TryFrom<[u8; 8]>` is not satisfied
  --> example.rs:68:10
   |
68 | #[derive(Sequence)]
   |          ^^^^^^^^ the trait `From<[u8; 8]>` is not implemented for `der::asn1::OctetStringRef<'_>`
   |
   = help: the following other types implement trait `From<T>`:
             `der::asn1::OctetStringRef<'_>` implements `From<&der::asn1::OctetString>`
             `der::asn1::OctetStringRef<'_>` implements `From<&der::asn1::OctetStringRef<'_>>`
   = note: required for `[u8; 8]` to implement `Into<der::asn1::OctetStringRef<'_>>`
   = note: required for `der::asn1::OctetStringRef<'_>` to implement `TryFrom<[u8; 8]>`
   = note: this error originates in the derive macro `Sequence`

does not work with deref ="true" too.

the trait `From<&[u8; 8]>` is not implemented for `OctetStringRef<'_>`
[Spoiler] real use case
/// EU Tachograph certificate body
#[derive(Sequence, Debug, Clone)]
#[asn1(tag_mode = "IMPLICIT")]

pub struct TachographCertificateBodyRaw {
    /// primitive, 1 byte
    #[asn1(application = "41", type = "OCTET STRING")]
    pub profile_identifier: [u8; 1],

    /// primitive, 8 bytes
    #[asn1(application = "2", type = "OCTET STRING")]
    pub authority_reference: [u8; 8],

    /// primitive, 7 bytes
    #[asn1(application = "76", type = "OCTET STRING")]
    pub holder_authorisation: [u8; 7],

    /// constructed
    #[asn1(application = "73")]
    pub public_key: CertificatePublicKeyRaw,

    /// primitive, 8 bytes
    #[asn1(application = "32", type = "OCTET STRING")]
    pub holder_reference: [u8; 8],

    /// primitive, 4 bytes
    #[asn1(application = "37", type = "OCTET STRING")]
    pub effective_date: [u8; 4],

    /// primitive, 4 bytes
    #[asn1(application = "36", type = "OCTET STRING")]
    pub expiration_date: [u8; 4],
}
@tarcieri
Copy link
Member

I think this just needs TryFrom impls to convert OctetStringRef to [u8; N]

@dishmaker dishmaker changed the title der: derive(Sequence) with [u8; 8] field der: derive(Sequence) with [u8; N] field Mar 21, 2025
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

No branches or pull requests

2 participants