---
source: https://iinventedlight.com/library/notes/go-encoding-asn1.md
title: "Go encoding/asn1: parse DER-encoded ASN.1 structures"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (The Go Authors); BSD-3-Clause (The Go Authors); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-encoding-asn1"
tags: [go, asn1, der, encoding, x690]
client: Librarian
sources:
  - id: S1
    title: "encoding/asn1"
    publisher: The Go Authors
    url: https://pkg.go.dev/encoding/asn1
    accessed: 2026-11-26
    license: "BSD-3-Clause"
  - id: S2
    title: "encoding/asn1 source"
    publisher: The Go Authors
    url: https://go.dev/src/encoding/asn1/asn1.go
    accessed: 2026-11-26
    license: "BSD-3-Clause"
---
# 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

- [go-encoding-json](https://iinventedlight.com/library/notes/go-encoding-json/)
- [go-encoding-xml](https://iinventedlight.com/library/notes/go-encoding-xml/)
- [go-pem](https://iinventedlight.com/library/notes/go-pem/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
