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

encoding/asn1: unmarshal doesn't support the same encoding field tags as marshal #72078

Open
rolandshoemaker opened this issue Mar 3, 2025 · 1 comment
Assignees
Labels
NeedsFix The path to resolution is known, but the work has not been done.

Comments

@rolandshoemaker
Copy link
Member

When using implicit tags, Marshal/Unmarshal provide a number of struct field tags that allow forcing specific encodings to be used for confusable types.

Marshal supports a larger set of these tags than Unmarshal, causing some data to be impossible to roundtrip.

package main

import (
	"encoding/asn1"
	"fmt"
	"time"
)

func main() {
	out, err := asn1.MarshalWithParams(time.Now(), "tag:2,generalized")
	if err != nil {
		fmt.Printf("failed to marshal: %v\n", err)
	}
	fmt.Printf("out: %x\n", out)
	var t time.Time
	_, err = asn1.UnmarshalWithParams(out, &t, "tag:2,generalized")
	if err != nil {
		fmt.Printf("failed to unmarshal: %v\n", err)
	}
	fmt.Printf("time: %v\n", t)
}

Unmarshal should support the same set of field tags.

@rolandshoemaker rolandshoemaker added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 3, 2025
@rolandshoemaker rolandshoemaker self-assigned this Mar 3, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/654275 mentions this issue: encoding/asn1: make sure implicit fields roundtrip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants