本文整理汇总了Golang中encoding/asn1.Unmarshal函数的典型用法代码### 示例。如果您正苦于以下问题:Golang Unmarshal函数的具体用法?Golang Unmarshal怎么用?Golang Unmarshal使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

在下文中一共展示了Unmarshal函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: Unmarshal

func (msg *messageV3) Unmarshal(b []byte) (rest []byte, err error) {
    var raw asn1.RawValue
    rest, err = asn1.Unmarshal(b, &raw)
    if err != nil {
        return nil, err
    }
    if raw.Class != classUniversal || raw.Tag != tagSequence || !raw.IsCompound {
        return nil, asn1.StructuralError{fmt.Sprintf(
            "Invalid messageV3 object - Class [%02x], Tag [%02x] : [%s]",
            raw.FullBytes[0], tagSequence, toHexStr(b, " "))}
    }

    next := raw.Bytes

    var version int
    next, err = asn1.Unmarshal(next, &version)
    if err != nil {
        return
    }

    next, err = msg.globalDataV3.Unmarshal(next)
    if err != nil {
        return
    }

    next, err = msg.securityParameterV3.Unmarshal(next)
    if err != nil {
        return
    }

    msg.version = SNMPVersion(version)
    msg.pduBytes = next
    return
}

开发者ID:mgenov,项目名称:snmpgo,代码行数:34,代码来源:message.go

示例2: getBags

// Given a slice of PKCS #7 content infos containing PKCS #12 Safe Bag Data,
// getBags returns those Safe Bags.
func getBags(authenticatedSafe []asn1.RawValue, password []byte) (bags []safeBag, err error) {
    for _, contentInfo := range authenticatedSafe {

        var safeContents []safeBag
        bagContainer, err := pkcs7.ParsePKCS7(contentInfo.FullBytes)
        if err != nil {
            return nil, err
        }
        switch {
        case bagContainer.ContentInfo == "Data":
            if _, err = asn1.Unmarshal(bagContainer.Content.Data, &safeContents); err != nil {
                return nil, cferr.Wrap(cferr.CertificateError, cferr.ParseFailed, err)
            }
        case bagContainer.ContentInfo == "EncryptedData":
            data, err := decrypt(bagContainer.Content.EncryptedData.EncryptedContentInfo.ContentEncryptionAlgorithm,
                bagContainer.Content.EncryptedData.EncryptedContentInfo.EncryptedContent, password)
            if err != nil {
                return nil, cferr.Wrap(cferr.CertificateError, cferr.ParseFailed, err)
            }
            if _, err = asn1.Unmarshal(data, &safeContents); err != nil {
                return nil, cferr.Wrap(cferr.CertificateError, cferr.ParseFailed, err)
            }
        default:
            return nil, cferr.Wrap(cferr.CertificateError, cferr.ParseFailed, errors.New("Only support for bags encoded in Data and EncryptedData types"))
        }

        bags = append(bags, safeContents...)
    }
    return bags, nil

}

开发者ID:JoeHorn,项目名称:boulder,代码行数:33,代码来源:pkcs12.go

示例3: convertAttribute

func convertAttribute(attribute *pkcs12Attribute) (key, value string, err error) {
    key = attributeNameByOID[attribute.ID.String()]
    switch {
    case attribute.ID.Equal(oidMicrosoftCSPName):
        fallthrough
    case attribute.ID.Equal(oidFriendlyName):
        if _, err = asn1.Unmarshal(attribute.Value.Bytes, &attribute.Value); err != nil {
            return
        }
        if value, err = decodeBMPString(attribute.Value.Bytes); err != nil {
            return
        }
    case attribute.ID.Equal(oidLocalKeyID):
        id := new([]byte)
        if _, err = asn1.Unmarshal(attribute.Value.Bytes, id); err != nil {
            return
        }
        value = fmt.Sprintf("% x", *id)
    default:
        err = errors.New("don't know how to handle attribute with OID " + attribute.ID.String())
        return
    }

    return key, value, nil
}

开发者ID:haneric21,项目名称:go-pkcs12,代码行数:25,代码来源:pkcs12.go

示例4: parseSignedData

func parseSignedData(data []byte) (*PKCS7, error) {
    var sd signedData
    asn1.Unmarshal(data, &sd)
    certs, err := sd.Certificates.Parse()
    if err != nil {
        return nil, err
    }
    // fmt.Printf("--> Signed Data Version %d\n", sd.Version)

    var compound asn1.RawValue
    var content unsignedData

    // The Content.Bytes maybe empty on PKI responses.
    if len(sd.ContentInfo.Content.Bytes) > 0 {
        if _, err := asn1.Unmarshal(sd.ContentInfo.Content.Bytes, &compound); err != nil {
            return nil, err
        }
    }
    // Compound octet string
    if compound.IsCompound {
        if _, err = asn1.Unmarshal(compound.Bytes, &content); err != nil {
            return nil, err
        }
    } else {
        // assuming this is tag 04
        content = compound.Bytes
    }
    return &PKCS7{
        Content:      content,
        Certificates: certs,
        CRLs:         sd.CRLs,
        Signers:      sd.SignerInfos,
        raw:          sd}, nil
}

开发者ID:GauntletWizard,项目名称:vault,代码行数:34,代码来源:pkcs7.go

示例5: ParsePKCS8PrivateKey

// ParsePKCS8PrivateKey parses an unencrypted, PKCS#8 private key. See
// http://www.rsa.com/rsalabs/node.asp?id=2130 and RFC5208.
func ParsePKCS8PrivateKey(der []byte) (key interface{}, err error) {
    var privKey pkcs8
    if _, err := asn1.Unmarshal(der, &privKey); err != nil {
        return nil, err
    }
    switch {
    case privKey.Algo.Algorithm.Equal(oidPublicKeyRSA):
        key, err = ParsePKCS1PrivateKey(privKey.PrivateKey)
        if err != nil {
            return nil, errors.New("x509: failed to parse RSA private key embedded in PKCS#8: " + err.Error())
        }
        return key, nil

    case privKey.Algo.Algorithm.Equal(oidPublicKeyECDSA):
        bytes := privKey.Algo.Parameters.FullBytes
        namedCurveOID := new(asn1.ObjectIdentifier)
        if _, err := asn1.Unmarshal(bytes, namedCurveOID); err != nil {
            namedCurveOID = nil
        }
        key, err = parseECPrivateKey(namedCurveOID, privKey.PrivateKey)
        if err != nil {
            return nil, errors.New("x509: failed to parse EC private key embedded in PKCS#8: " + err.Error())
        }
        return key, nil

    default:
        return nil, fmt.Errorf("x509: PKCS#8 wrapping contained private key with unknown algorithm: %v", privKey.Algo.Algorithm)
    }
}

开发者ID:awesome-security,项目名称:zgrab,代码行数:31,代码来源:pkcs8.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng