Reputation: 848
I am trying to create a DER file using encoding/asn1, and I keep getting an invalid Object Identifier runtime error. asn1.ObjectIdentifier
is just an []int, so I'm not sure what's invalid.
package main
import (
"encoding/asn1"
"fmt"
"log"
)
type algorithm struct {
Algo asn1.ObjectIdentifier
Null asn1.RawValue
}
func main() {
var myCert algorithm
myCert.Algo = asn1.ObjectIdentifier{42, 134, 72, 134}
myCert.Null = asn1.NullRawValue
mdata, err := asn1.Marshal(myCert)
if err != nil {
log.Fatalln(err)
}
fmt.Println(mdata)
}
The program exits with the following error: "asn1: structure error: invalid object identifier"
Playground example here
Upvotes: 0
Views: 1970
Reputation: 10008
Object identifiers are not straight forward.
There are only 3 top level arcs (the integers that form the object identifier). In other words, first arc (42 in your example) can only be 0, 1 or 2
If your first arc is 0 or 1, then the second arc must be less than 40
Note: This restriction is used by the encoding rules of the object identifier value to pack the 2 first arcs
Upvotes: 3