Go encoding/asn1: parse DER-encoded ASN.1 structures
Answer: Package asn1 implements parsing of DER-encoded ASN.1 data structures.
What the package parses
Here the package deals with DER, the Distinguished Encoding Rules.
Unmarshal fills a pointer; passing nil or a non-pointer fails.
Unmarshal uses the reflect package, so destination structs must use upper case field names.
When an encoded value does not fit the Go type, Unmarshal returns a parse error.
Common ASN.1 types
An ASN.1 INTEGER can be written to an int, int32, int64, or *big.Int.
An ASN.1 OCTET STRING can be written to a []byte.
OBJECT IDENTIFIER values use the ObjectIdentifier type.
ENUMERATED values use the Enumerated type.
See also
Claims
- id: C1 claim: The package parses DER-encoded ASN.1 structures. source: S1 evidence: "parsing of DER-encoded ASN.1 data structures"
- id: C2 claim: Destination structs must use upper case field names. source: S1 evidence: "must use upper case field names"
- id: C3 claim: A nil or non-pointer value makes Unmarshal return an error. source: S1 evidence: "If val is nil or not a pointer, Unmarshal returns an error."
- id: C4 claim: The package comment describes parsing DER-encoded ASN.1 structures. source: S2 evidence: "Package asn1 implements parsing of DER-encoded ASN.1 data structures"
Sources
- [S1] encoding/asn1. The Go Authors. https://pkg.go.dev/encoding/asn1 . License: BSD-3-Clause. Accessed 2026-11-26.
- [S2] encoding/asn1 source. The Go Authors. https://go.dev/src/encoding/asn1/asn1.go . License: BSD-3-Clause. Accessed 2026-11-26.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, encoding/asn1; The Go Authors, encoding/asn1 source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors, encoding/asn1; The Go Authors, encoding/asn1 source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go encoding/asn1: parse DER-encoded ASN.1 structures." iinventedlight Library, iil:note:23ga7979, version of 2026-11-26. https://iinventedlight.com/library/notes/go-encoding-asn1/. License: CC-BY-4.0.
@misc{iil_note_23ga7979,
author = {{iinventedlight}},
title = {{Go encoding/asn1: parse DER-encoded ASN.1 structures}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/go-encoding-asn1/},
note = {Permanent ID iil:note:23ga7979. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-encoding-asn1.schema.json (schema; CC-BY-4.0)
- go-encoding-asn1.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-encoding-asn1.md.