asn1utils

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 3 Imported by: 2

README

go-asn1utils

Go CI Go Reference Go Report Card Go Version

Quality Gate Status Coverage Bugs Vulnerabilities

Description

go-asn1utils is a Go library designed to facilitate the manipulation of ASN.1 encoded data. Its primary functionality is to convert ASN.1 bytes—which may use BER (Basic Encoding Rules) features like indefinite lengths—into DER (Distinguished Encoding Rules) compliant bytes.

Key features include:

  • Parsing ASN.1 structures with support for both definite and indefinite length encodings.
  • Handling constructed and primitive types.
  • Canonicalizing output to strict DER format, including:
    • Normalizing boolean values.
    • Flattening constructed forms of primitive types (e.g., OCTET STRING, BIT STRING).
    • Sorting elements in SET types.

This utility ensures that ASN.1 data is represented in a canonical form, suitable for cryptographic operations such as signing and verification where a unique encoding is required.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeDER

func MakeDER(data []byte) ([]byte, error)

MakeDER converts ASN.1 bytes that may use BER indefinite lengths (or other non-DER forms) into DER-encoded bytes. If the input is already in DER form, it is returned unchanged (aside from necessary canonicalizations like boolean normalization or set ordering).

Types

type ASN1Object

type ASN1Object struct {
	Class         int // 0=Universal, 1=Application, 2=Context-specific, 3=Private
	TagNumber     int // The tag number (could be > 30 for extended tags)
	IsConstructed bool
	Value         []byte       // Used if primitive (holds the content bytes)
	SubObjects    []ASN1Object // Used if constructed (holds the parsed sub-elements)
}

ASN1Object represents an ASN.1 element (potentially constructed with sub-elements)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL