Go – 解码/编码 ASN.1

huangapple go评论102阅读模式
英文:

Go - decode/encode asn.1

问题

有人知道在Go中如何使用asn1 Marshal和Unmarshal函数的好例子吗?

我对使用ASN.1进行DER编码的概念很熟悉,但在代码中直接处理它没有经验(通常我使用另一个库来封装它,比如openldap之类的)。

是的,我看过文档(http://golang.org/pkg/encoding/asn1/),它似乎描述了一种类似于Go中JSON和XML可用的标记系统;然而,我还没有找到关于encoding/asn1包的好的实际示例(嗯,好吧,我在asn1_test.go中看到了Certificate的示例,还有其他的吗?)

(总的来说,我正在尝试在Go中实现LDAP的一个非常小的子集(服务器端)。)

更新:我的问题存在错误,因为LDAP使用的是BER,而不是DER。所以encoding/asn.1对我没有帮助。无论如何,我最终做了这个:https://github.com/bradleypeabody/godap(它使用这个库来进行BER+ASN1:https://github.com/go-asn1-ber/asn1-ber)

英文:

Does anyone know where there is a good example of how to use the asn1 Marshal and Unmarshal funcs in Go?

I'm familiar with the concept of how DER encoding with ASN.1 works, but do not have experience dealing with it directly in code (usually I'm using another library with wraps it - openldap or whatever).

Yes, I've looked at the documentation (http://golang.org/pkg/encoding/asn1/), which seems to describe a tagging system much like what is available for JSON and XML in Go; however I have yet to find a good practical example of this anywhere for the encoding/asn1 package. (Hm, okay I see the Certificate example in asn1_test.go - anyone know of anything else?)

(Overall, I'm trying to implement a very small subset of LDAP (the server side) in Go.)

UPDATE: My question is flawed by the fact that LDAP uses BER, not DER. So encoding/asn.1 isn't going to help. In any case, I ended up making this: https://github.com/bradleypeabody/godap (which uses this for BER+ASN1: https://github.com/go-asn1-ber/asn1-ber )

答案1

得分: 5

以下是要翻译的内容:

https://web.archive.org/web/20160816005220/https://jan.newmarch.name/go/serialisation/chapter-serialisation.html

https://ipfs.io/ipfs/QmfYeDhGH9bZzihBUDEQbCbTc5k5FZKURMUoUvfmc27BwL/dataserialisation/asn1.html

都有很多关于asn1.Marshal / asn1.Unmarshal的示例。

英文:

https://web.archive.org/web/20160816005220/https://jan.newmarch.name/go/serialisation/chapter-serialisation.html

and

https://ipfs.io/ipfs/QmfYeDhGH9bZzihBUDEQbCbTc5k5FZKURMUoUvfmc27BwL/dataserialisation/asn1.html

have quite a few examples with asn1.Marshal / asn1.Unmarshal

huangapple
  • 本文由 发表于 2014年10月31日 07:36:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/26665263.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定