Skip to content

DER: Over-eager consumption in AnyRef #815

Description

@woodruffw

This is a discrete issue for the behavior I'm seeing while testing #813, specifically in #813 (comment).

There, we have a struct that's annotated like so:

#[derive(Clone,Copy,Debug,Eq,PartialEq,Sequence)]pubstructEncapsulatedContentInfo<'a>{/// indicates the type of content.pube_content_type:ObjectIdentifier,/// encapsulated content#[asn1(context_specific = "0", optional = "true", tag_mode = "EXPLICIT")]pube_content:Option<AnyRef<'a>>,}

My expectation is that this definition would consume a DER structure like this:

SEQUENCE
OBJECT IDENTIFIER 1.2.3.4
[0]
SEQUENCE
ANYTHING HERE POSSIBLY JUST AN OCTET STRING

...leaving e_content_type as 1.2.3.4 and e_content as:

SEQUENCE
ANYTHING HERE POSSIBLY JUST AN OCTET STRING

Experimentally, however, the borrowed slice in e_content's AnyRef contains:

ANYTHING HERE POSSIBLY JUST AN OCTET STRING

...meaning that the surrounding SEQUENCE was consumed. When I remove the #[asn1(...)] annotation from e_content, the behavior changes to what I expect:

SEQUENCE
ANYTHING HERE POSSIBLY JUST AN OCTET STRING

This suggests a bug to me, somewhere in the interaction between the #[asn1(...)] annotation and AnyRef.

I'll work on a minimal reproduction now, but this behavior is currently visible with the PKCS7 blob I shared on the other PR (https://github.com/RustCrypto/formats/files/10270816/authroot.stl.zip) and the changes in that PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions