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

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

示例1: GetHash

func GetHash(a string) (hash.Hash, error) {
    var h hash.Hash
    switch a {
    case "adler32":
        h = adler32.New()
    case "crc32", "crc32ieee":
        h = crc32.New(crc32.MakeTable(crc32.IEEE))
    case "crc32castagnoli":
        h = crc32.New(crc32.MakeTable(crc32.Castagnoli))
    case "crc32koopman":
        h = crc32.New(crc32.MakeTable(crc32.Koopman))
    case "crc64", "crc64iso":
        h = crc64.New(crc64.MakeTable(crc64.ISO))
    case "crc64ecma":
        h = crc64.New(crc64.MakeTable(crc64.ECMA))
    case "fnv", "fnv32":
        h = fnv.New32()
    case "fnv32a":
        h = fnv.New32a()
    case "fnv64":
        h = fnv.New64()
    case "fnv64a":
        h = fnv.New64a()
    case "hmac", "hmacsha256":
        h = hmac.New(sha256.New, []byte(key))
    case "hmacmd5":
        h = hmac.New(md5.New, []byte(key))
    case "hmacsha1":
        h = hmac.New(sha1.New, []byte(key))
    case "hmacsha512":
        h = hmac.New(sha512.New, []byte(key))
    case "md4":
        h = md4.New()
    case "md5":
        h = md5.New()
    case "ripemd160":
        h = ripemd160.New()
    case "sha1":
        h = sha1.New()
    case "sha224":
        h = sha256.New224()
    case "sha256":
        h = sha256.New()
    case "sha384":
        h = sha512.New384()
    case "sha512":
        h = sha512.New()
    default:
        return nil, errors.New("Invalid algorithm")
    }
    return h, nil
}

开发者ID:patrickmn,项目名称:picugen,代码行数:52,代码来源:picugen.go

示例2: computeOffsets

func computeOffsets(index *nodeIndex, n *trieNode) uint16 {
    if n.leaf {
        return n.value
    }
    hasher := crc32.New(crc32.MakeTable(crc32.IEEE))
    // We only index continuation bytes.
    for i := 0; i < 64; i++ {
        var v uint16 = 0
        if nn := n.table[0x80+i]; nn != nil {
            v = computeOffsets(index, nn)
        }
        hasher.Write([]byte{uint8(v >> 8), uint8(v)})
    }
    h := hasher.Sum32()
    if n.isInternal() {
        v, ok := index.lookupBlockIdx[h]
        if !ok {
            v = uint16(len(index.lookupBlocks))
            index.lookupBlocks = append(index.lookupBlocks, n)
            index.lookupBlockIdx[h] = v
        }
        n.value = v
    } else {
        v, ok := index.valueBlockIdx[h]
        if !ok {
            v = uint16(len(index.valueBlocks))
            index.valueBlocks = append(index.valueBlocks, n)
            index.valueBlockIdx[h] = v
        }
        n.value = v
    }
    return n.value
}

开发者ID:WXB506,项目名称:golang,代码行数:33,代码来源:triegen.go

示例3: Hash

func (b *backend) Hash(ignores map[IgnoreKey]struct{}) (uint32, error) {
    h := crc32.New(crc32.MakeTable(crc32.Castagnoli))

    b.mu.RLock()
    defer b.mu.RUnlock()
    err := b.db.View(func(tx *bolt.Tx) error {
        c := tx.Cursor()
        for next, _ := c.First(); next != nil; next, _ = c.Next() {
            b := tx.Bucket(next)
            if b == nil {
                return fmt.Errorf("cannot get hash of bucket %s", string(next))
            }
            h.Write(next)
            b.ForEach(func(k, v []byte) error {
                bk := IgnoreKey{Bucket: string(next), Key: string(k)}
                if _, ok := ignores[bk]; !ok {
                    h.Write(k)
                    h.Write(v)
                }
                return nil
            })
        }
        return nil
    })

    if err != nil {
        return 0, err
    }

    return h.Sum32(), nil
}

开发者ID:CliffYuan,项目名称:etcd,代码行数:31,代码来源:backend.go

示例4: process_file

func process_file(filename string, complete chan Sumlist) {
    sumlist := Sumlist{}
    sumlist.filename = filename

    // Open the file and bail if we fail
    infile, err := os.Open(filename)
    if err != nil {
        log.Printf("Unable to open %s: %s", filename, err)
        complete <- sumlist
        return
    }
    defer infile.Close()

    // Create the checksum objects
    if flag_crc32 {
        sumlist.sums = append(sumlist.sums, Checksum{"CRC32", crc32.New(crc32.IEEETable)})
    }
    if flag_crc64 {
        sumlist.sums = append(sumlist.sums, Checksum{"CRC64", crc64.New(crc64.MakeTable(crc64.ISO))})
    }
    if flag_sha224 {
        sumlist.sums = append(sumlist.sums, Checksum{"SHA224", sha256.New224()})
    }
    if flag_sha256 {
        sumlist.sums = append(sumlist.sums, Checksum{"SHA256", sha256.New()})
    }
    if flag_sha384 {
        sumlist.sums = append(sumlist.sums, Checksum{"SHA384", sha512.New384()})
    }
    if flag_sha512 {
        sumlist.sums = append(sumlist.sums, Checksum{"SHA512", sha512.New()})
    }

    // Create our file reader
    reader := bufio.NewReader(infile)

    // Start a buffer and loop to read the entire file
    buf := make([]byte, 4096)
    for {
        read_count, err := reader.Read(buf)
        // If we get an error that is not EOF, then we have a problem
        if err != nil && err != io.EOF {
            log.Printf("Unable to open %s: %s", filename, err)
            complete <- sumlist
            return
        }
        // If the returned size is zero, we're at the end of the file
        if read_count == 0 {
            break
        }

        // Add the buffer contents to the checksum calculation
        for _, sum := range sumlist.sums {
            sum.hashFunc.Write(buf[:read_count])
        }

    }

    complete <- sumlist
}

开发者ID:joerocklin,项目名称:qhash,代码行数:60,代码来源:qhash.go

示例5: decStreamHeader

/* Decode the Stream Header field (the first 12 bytes of the .xz Stream). */
func decStreamHeader(s *xzDec) xzRet {
    if string(s.temp.buf[:len(headerMagic)]) != headerMagic {
        return xzFormatError
    }
    if xzCRC32(s.temp.buf[len(headerMagic):len(headerMagic)+2], 0) !=
        getLE32(s.temp.buf[len(headerMagic)+2:]) {
        return xzDataError
    }
    if s.temp.buf[len(headerMagic)] != 0 {
        return xzOptionsError
    }
    /*
     * Of integrity checks, we support none (Check ID = 0),
     * CRC32 (Check ID = 1), CRC64 (Check ID = 4) and SHA256 (Check ID = 10)
     * However, we will accept other check types too, but then the check
     * won't be verified and a warning (xzUnsupportedCheck) will be given.
     */
    s.checkType = xzCheck(s.temp.buf[len(headerMagic)+1])
    if s.checkType > xzCheckMax {
        return xzOptionsError
    }
    switch s.checkType {
    case xzCheckNone:
        // xzCheckNone: no action needed
    case xzCheckCRC32:
        s.check = crc32.New(xzCRC32Table)
    case xzCheckCRC64:
        s.check = crc64.New(xzCRC64Table)
    case xzCheckSHA256:
        s.check = sha256.New()
    default:
        return xzUnsupportedCheck
    }
    return xzOK
}

开发者ID:cardi,项目名称:timefind,代码行数:36,代码来源:dec_stream.go

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