Skip to content

proposal: encoding/asn1: allow setting params on elements of slices #39027

@rolandshoemaker

Description

@rolandshoemaker

encoding/asn1 currently provides a number of struct field tags to manipulate how fields are parsed/encoded, notably setting the time type, string type, or marking slices or structs as a SET rather than a SEQUENCE.

Unfortunately it is impossible to set these fields on elements of a slice. This makes it impossible to encode certain things like SEQUENCE OF IA5String or parse SEQUENCE OF SET (see #27426 and #18834 for examples).

The only real workaround for this is manually encoding/parsing each element of a slice with MarshalWithParams/UnmarshalWithParams, and then constructing/parsing a SEQUENCE yourself, which is obviously quite prone to errors and overly complex.

Ideally there would be a way to set parameters for each member of the slice. Probably the simplest solution to this problem would be adding a new struct tag, element-param:x or something, which would be passed through to makeField/parseField. For example this would then allow the following struct

type example struct {
	A []string `asn1:"element-param:ia5"`
}

to be encoded as a SEQUENCE OF IA5String.

cc @FiloSottile @katiehockman

Metadata

Metadata

Assignees

No one assigned

    Labels

    ProposalProposal-CryptoProposal related to crypto packages or other security issues

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions