How can I fit large integer (public key) INTEGER of ASN.1 into small int64 of struct?


I have to represent (ASN.1/DER SEQUENCE) pseudocode:

      SEQUENCE {...}

Where INTEGER should be a PUBLIC KEY

In terms of Golang struct I have so far pseudocode:

type ... struct {
      num int64,

But when compile, I got runtime error, saying:

panic: asn1: structure error: integer too large

I understand, that problem is with fitting LARGE PUBLIC KEY into small int64, how should I overcome that problem? When I change num int64 to num []int64 I got another error, saying, that type mismatch (which also MAKE SENSE, since was INTEGER and now SEQUENCE)…

So, again, how do you fit PUBLIC KEY INTEGER into int of Golang or any other prog. lang?


I think this could help you: Why is unmarshalling of a DER ASN.1 large integer limited to SEQUENCE in Golang? (look at the answer)

Note on your comment:
Go Big.Int is NOT an asn1 SEQUENCE (asn1 is agnostic, it is up to you or the tool you use to define how you will map asn1 INTEGER to something you can use)

Answered By – YaFred

Answer Checked By – Gilberto Lyons (GoLangFix Admin)

Leave a Reply

Your email address will not be published.