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

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

示例1: TestVerifyMac

func TestVerifyMac(t *testing.T) {
    td := macData{
        Mac: digestInfo{
            Digest: []byte{0x18, 0x20, 0x3d, 0xff, 0x1e, 0x16, 0xf4, 0x92, 0xf2, 0xaf, 0xc8, 0x91, 0xa9, 0xba, 0xd6, 0xca, 0x9d, 0xee, 0x51, 0x93},
        },
        MacSalt:    []byte{1, 2, 3, 4, 5, 6, 7, 8},
        Iterations: 2048,
    }

    message := []byte{11, 12, 13, 14, 15}
    password, _ := bmpString([]byte(""))

    td.Mac.Algorithm.Algorithm = asn1.ObjectIdentifier([]int{1, 2, 3})
    err := verifyMac(&td, message, password)
    if _, ok := err.(NotImplementedError); !ok {
        t.Errorf("err: %v", err)
    }

    td.Mac.Algorithm.Algorithm = asn1.ObjectIdentifier([]int{1, 3, 14, 3, 2, 26})
    err = verifyMac(&td, message, password)
    if err != ErrIncorrectPassword {
        t.Errorf("Expected incorrect password, got err: %v", err)
    }

    password, _ = bmpString([]byte("Sesame open"))
    err = verifyMac(&td, message, password)
    if err != nil {
        t.Errorf("err: %v", err)
    }

}

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

示例2: TestComputeMac

func TestComputeMac(t *testing.T) {
    td := macData{
        MacSalt:    []byte{1, 2, 3, 4, 5, 6, 7, 8},
        Iterations: 2048,
    }

    message := []byte{11, 12, 13, 14, 15}
    password, _ := bmpString([]byte("Sesame open"))

    td.Mac.Algorithm.Algorithm = asn1.ObjectIdentifier([]int{1, 2, 3})
    err := computeMac(&td, message, password)
    if _, ok := err.(NotImplementedError); !ok {
        t.Errorf("err: %v", err)
    }

    td.Mac.Algorithm.Algorithm = asn1.ObjectIdentifier([]int{1, 3, 14, 3, 2, 26})
    err = computeMac(&td, message, password)
    if err != nil {
        t.Errorf("err: %v", err)
    }

    expectedDigest := []byte{0x18, 0x20, 0x3d, 0xff, 0x1e, 0x16, 0xf4, 0x92, 0xf2, 0xaf, 0xc8, 0x91, 0xa9, 0xba, 0xd6, 0xca, 0x9d, 0xee, 0x51, 0x93}

    if bytes.Compare(td.Mac.Digest, expectedDigest) != 0 {
        t.Errorf("Computed incorrect MAC; expected MAC to be '%d' but got '%d'", expectedDigest, td.Mac.Digest)
    }

}

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

示例3: TestPbDecrypterFor

func TestPbDecrypterFor(t *testing.T) {
    params, _ := asn1.Marshal(pbeParams{
        Salt:       []byte{1, 2, 3, 4, 5, 6, 7, 8},
        Iterations: 2048,
    })
    alg := pkix.AlgorithmIdentifier{
        Algorithm: asn1.ObjectIdentifier([]int{1, 2, 3}),
        Parameters: asn1.RawValue{
            FullBytes: params,
        },
    }

    pass, _ := bmpString([]byte("Sesame open"))

    _, err := pbDecrypterFor(alg, pass)
    if _, ok := err.(NotImplementedError); !ok {
        t.Errorf("expected not implemented error, got: %T %s", err, err)
    }

    alg.Algorithm = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 12, 1, 3})
    cbc, err := pbDecrypterFor(alg, pass)
    if err != nil {
        t.Errorf("err: %v", err)
    }

    M := []byte{1, 2, 3, 4, 5, 6, 7, 8}
    expectedM := []byte{185, 73, 135, 249, 137, 1, 122, 247}
    cbc.CryptBlocks(M, M)

    if bytes.Compare(M, expectedM) != 0 {
        t.Errorf("expected M to be '%d', but found '%d", expectedM, M)
    }
}

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

示例4: CreateRequest

// CreateRequest returns a DER-encoded, OCSP request for the status of cert. If
// opts is nil then sensible defaults are used.
func CreateRequest(cert, issuer *x509.Certificate, opts *RequestOptions) ([]byte, error) {
    hashFunc := opts.hash()

    // OCSP seems to be the only place where these raw hash identifiers are
    // used. I took the following from
    // http://msdn.microsoft.com/en-us/library/ff635603.aspx
    var hashOID asn1.ObjectIdentifier
    switch hashFunc {
    case crypto.SHA1:
        hashOID = asn1.ObjectIdentifier([]int{1, 3, 14, 3, 2, 26})
    case crypto.SHA256:
        hashOID = asn1.ObjectIdentifier([]int{2, 16, 840, 1, 101, 3, 4, 2, 1})
    case crypto.SHA384:
        hashOID = asn1.ObjectIdentifier([]int{2, 16, 840, 1, 101, 3, 4, 2, 2})
    case crypto.SHA512:
        hashOID = asn1.ObjectIdentifier([]int{2, 16, 840, 1, 101, 3, 4, 2, 3})
    default:
        return nil, x509.ErrUnsupportedAlgorithm
    }

    if !hashFunc.Available() {
        return nil, x509.ErrUnsupportedAlgorithm
    }
    h := opts.hash().New()

    var publicKeyInfo struct {
        Algorithm pkix.AlgorithmIdentifier
        PublicKey asn1.BitString
    }
    if _, err := asn1.Unmarshal(issuer.RawSubjectPublicKeyInfo, &publicKeyInfo); err != nil {
        return nil, err
    }

    h.Write(publicKeyInfo.PublicKey.RightAlign())
    issuerKeyHash := h.Sum(nil)

    h.Reset()
    h.Write(issuer.RawSubject)
    issuerNameHash := h.Sum(nil)

    return asn1.Marshal(ocspRequest{
        tbsRequest{
            Version: 0,
            RequestList: []request{
                {
                    Cert: certID{
                        pkix.AlgorithmIdentifier{
                            Algorithm:  hashOID,
                            Parameters: asn1.RawValue{Tag: 5 /* ASN.1 NULL */},
                        },
                        issuerNameHash,
                        issuerKeyHash,
                        cert.SerialNumber,
                    },
                },
            },
        },
    })
}

开发者ID:GamerockSA,项目名称:dex,代码行数:61,代码来源:ocsp.go

示例5: BuildIdentifierCaches

func BuildIdentifierCaches(mib_file []string) {
    args := []string{"-f", "identifiers", "-k", "-u"}
    for _, x := range mib_file {
        args = append(args, x)
    }
    cmd := exec.Command("smidump", args...)
    stdout := new(bytes.Buffer)
    stderr := new(bytes.Buffer)
    cmd.Stdout = stdout
    cmd.Stderr = stderr
    cmd.Run()

    scanner := bufio.NewScanner(stdout)
    for scanner.Scan() {
        cols := pat_split.Split(scanner.Text(), -1)
        if len(cols) >= 4 {
            if oid, err := parseOID(cols[3]); err == nil {
                if len(oid) > max_cache_prefix_oid_length {
                    max_cache_prefix_oid_length = len(oid)
                }
                if len(oid) < min_cache_prefix_oid_length {
                    min_cache_prefix_oid_length = len(oid)
                }
                key := asn1.ObjectIdentifier(oid).String()
                value := fmt.Sprintf("%s::%s", cols[0], cols[1])
                cache_prefix[key] = value
            }
        }
    }
}

开发者ID:oliveagle,项目名称:gosnmp,代码行数:30,代码来源:trysnmp.go

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