duanjiangzhi6851 2018-05-26 02:47
浏览 423
已采纳

无效的ASN.1对象标识符编码错误

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

  • 写回答

1条回答 默认 最新

  • dtd793353 2018-05-26 06:38
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?