本文整理汇总了Golang中encoding/asn1.Marshal函数的典型用法代码### 示例。如果您正苦于以下问题:Golang Marshal函数的具体用法?Golang Marshal怎么用?Golang Marshal使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了Marshal函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: ForMarshaling
func (attrs *attributes) ForMarshaling() ([]attribute, error) {
sortables := make(attributeSet, len(attrs.types))
for i := range sortables {
attrType := attrs.types[i]
attrValue := attrs.values[i]
asn1Value, err := asn1.Marshal(attrValue)
if err != nil {
return nil, err
}
attr := attribute{
Type: attrType,
Value: asn1.RawValue{Tag: 17, IsCompound: true, Bytes: asn1Value}, // 17 == SET tag
}
encoded, err := asn1.Marshal(attr)
if err != nil {
return nil, err
}
sortables[i] = sortableAttribute{
SortKey: encoded,
Attribute: attr,
}
}
sort.Sort(sortables)
return sortables.Attributes(), nil
}
开发者ID:GauntletWizard,项目名称:vault,代码行数:25,代码来源:pkcs7.go
示例2: MarshalPKIXPublicKey
// MarshalPKIXPublicKey serialises a public key to DER-encoded PKIX format.
func MarshalPKIXPublicKey(pub interface{}) ([]byte, error) {
var pubBytes []byte
switch pub := pub.(type) {
case *rsa.PublicKey:
pubBytes, _ = asn1.Marshal(rsaPublicKey{
N: pub.N,
E: pub.E,
})
default:
return nil, errors.New("MarshalPKIXPublicKey: unknown public key type")
}
pkix := pkixPublicKey{
Algo: pkix.AlgorithmIdentifier{
Algorithm: []int{1, 2, 840, 113549, 1, 1, 1},
// This is a NULL parameters value which is technically
// superfluous, but most other code includes it and, by
// doing this, we match their public key hashes.
Parameters: asn1.RawValue{
Tag: 5,
},
},
BitString: asn1.BitString{
Bytes: pubBytes,
BitLength: 8 * len(pubBytes),
},
}
ret, _ := asn1.Marshal(pkix)
return ret, nil
}
开发者ID:jmcadden,项目名称:EbbRT-gcc,代码行数:33,代码来源:x509.go
示例3:
func makeSafeContents (bags []safeBag, password []byte, alg String) (ci []contentInfo, err error) {
ci = make([]contentInfo, 2)
for i, b := range bags {
switch b.ID {
case oidCertTypeX509Certificate:
ci[i].ContentType = oidDataContentType
ci[i].Content, err = asn1.Marshal(b)
if err != nil{
return nil, err
}
case oidPkcs8ShroudedKeyBagType
ci[i].Content, err = pbEncrypt(b, alg, password)
if err != nil{
return nil, err
}
ci[i].Content, err = asn1.Marshal(ki.Content)
if err != nil{
return nil, err
}
}
}
return ci, err
}
开发者ID:tudorvio,项目名称:go-pkcs12,代码行数:26,代码来源:pkcs12.go
示例4: marshalPublicKey
func marshalPublicKey(pub interface{}) (publicKeyBytes []byte, publicKeyAlgorithm pkix.AlgorithmIdentifier, err error) {
switch pub := pub.(type) {
case *rsa.PublicKey:
publicKeyBytes, err = asn1.Marshal(rsaPublicKey{
N: pub.N,
E: pub.E,
})
publicKeyAlgorithm.Algorithm = oidPublicKeyRSA
// This is a NULL parameters value which is technically
// superfluous, but most other code includes it and, by
// doing this, we match their public key hashes.
publicKeyAlgorithm.Parameters = asn1.RawValue{
Tag: 5,
}
case *ecdsa.PublicKey:
publicKeyBytes = elliptic.Marshal(pub.Curve, pub.X, pub.Y)
oid, ok := oidFromNamedCurve(pub.Curve)
if !ok {
return nil, pkix.AlgorithmIdentifier{}, errors.New("x509: unsupported elliptic curve")
}
publicKeyAlgorithm.Algorithm = oidPublicKeyECDSA
var paramBytes []byte
paramBytes, err = asn1.Marshal(oid)
if err != nil {
return
}
publicKeyAlgorithm.Parameters.FullBytes = paramBytes
default:
return nil, pkix.AlgorithmIdentifier{}, errors.New("x509: only RSA and ECDSA public keys supported")
}
return publicKeyBytes, publicKeyAlgorithm, nil
}
开发者ID:ArtemL,项目名称:GCC,代码行数:33,代码来源:x509.go
示例5: Marshal
func (msg *messageV3) Marshal() (b []byte, err error) {
var buf []byte
raw := asn1.RawValue{Class: classUniversal, Tag: tagSequence, IsCompound: true}
buf, err = asn1.Marshal(msg.version)
if err != nil {
return
}
raw.Bytes = buf
buf, err = msg.globalDataV3.Marshal()
if err != nil {
return
}
raw.Bytes = append(raw.Bytes, buf...)
buf, err = msg.securityParameterV3.Marshal()
if err != nil {
return
}
raw.Bytes = append(raw.Bytes, buf...)
raw.Bytes = append(raw.Bytes, msg.pduBytes...)
return asn1.Marshal(raw)
}
开发者ID:mgenov,项目名称:snmpgo,代码行数:25,代码来源:message.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng