← All notes

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

Sources

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

Permanent ID: iil:note:23ga7979

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.},
}

Markdown

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.

All artifact files (JSON index)

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.