JesseCoretta / go-asn1int

Basic ASN.1 INTEGER implementation for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ASN.1 Go Report Card Go Reference CodeQL License codecov contributions welcome GitHub Workflow Status (with event) Author GitHub release (with filter) Help Animals

go-asn1int

Basic ASN.1 INTEGER implementation for Go, free of magnitude limits.

func main() {
	// INITIALIZE NEW INTEGER INSTANCE
        m, err := New(58986943) // can also init using string, [u]int64, *big.Int
        if err != nil {
                return
        }

	// MARSHAL TO ASN.1 BYTES
        var asn1Bytes []byte
	if asn1Bytes, err = m.Marshal(); err != nil {
		return
	}

        fmt.Printf("%v", asn1Bytes)
        // Output: [48 6 2 4 3 132 17 191]

	// UNMARSHAL ASN.1 BYTES BACK TO INTEGER
	var ui INTEGER
	if err = ui.Unmarshal(asn1Bytes); err != nil {
		return
	}

	fmt.Printf("%s", ui)
	// Output: 58986943
}

About

Basic ASN.1 INTEGER implementation for Go

License:MIT License


Languages

Language:Go 100.0%