Standard library / crypto/x509

crypto/x509.OID.MarshalBinary()

Encodes the OID as ASN.1 OID content octets, not an entire DER TLV. Expected stdout: '2a03\n'.

Formal Syntax & Structure

go syntaxgo
func (o OID) MarshalBinary() ([]byte, error)

Return Value

([]byte, error)

Result as described above; check any returned error before use.

Working Example

Example Snippetgo
package main
import (  "crypto/x509"  "fmt")
func main() { v := must(x509.ParseOID("1.2.3")); fmt.Printf("%x\n", must(v.MarshalBinary())) }
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference