英文:
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://ipfs.io/ipfs/QmfYeDhGH9bZzihBUDEQbCbTc5k5FZKURMUoUvfmc27BwL/dataserialisation/asn1.html
都有很多关于asn1.Marshal
/ asn1.Unmarshal
的示例。
英文:
and
https://ipfs.io/ipfs/QmfYeDhGH9bZzihBUDEQbCbTc5k5FZKURMUoUvfmc27BwL/dataserialisation/asn1.html
have quite a few examples with asn1.Marshal
/ asn1.Unmarshal
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论