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

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

示例1: SignSHA256

// Sign the given hex-endcoded hash checksum and return a Signature
// @@TODO Remove this -- undeeded
func (pk PrivateKey) SignSHA256(hexbytes []byte) (Signature, error) {
    if hex.DecodedLen(len(hexbytes)) != sha256.Size {
        return nil, ErrPrivateKeySHA256
    }

    // Decode hex bytes into raw bytes
    decodedBytes := make([]byte, hex.DecodedLen(len(hexbytes)))
    _, err := hex.Decode(decodedBytes, hexbytes)
    if err != nil {
        return nil, errors.Wrap(err, ErrPrivateKeySHA256)
    }

    // Get the rsa cryptokey for signing
    cryptoKey, err := pk.GetCryptoKey()
    if err != nil {
        return nil, errors.Wrap(err, ErrPrivatKeySign)
    }

    // Compute the signature and return the results
    rawSignature, err := rsa.SignPKCS1v15(rand.Reader, cryptoKey, crypto.SHA256, decodedBytes)
    if err != nil {
        return nil, errors.Wrap(err, ErrPrivatKeySign)
    }
    return Signature(rawSignature), nil
}

开发者ID:laprice,项目名称:cryptoballot,代码行数:27,代码来源:PrivateKey.go

示例2: ConvertHexString

func ConvertHexString(line []byte) (result []byte, err error) {
    buf := &bytes.Buffer{}
    for i, count := 0, len(line); i < count; i++ {
        b := line[i]
        if b == '\\' {
            if i+1 < count && line[i+1] == 'x' {
                if i+2+2 >= count {
                    err = errors.New("invalid character \\x")
                    return
                }
                b34hex := line[i+2 : i+2+2]
                b34 := make([]byte, hex.DecodedLen(len(b34hex)))
                _, err = hex.Decode(b34, b34hex)
                if err != nil {
                    return
                }
                buf.Write(b34)
                i += 3 // skip \xff
            } else {
                buf.WriteByte('\\')
            }
        } else {
            buf.WriteByte(b)
        }
    }
    result = buf.Bytes()
    return
}

开发者ID:WaylandGod,项目名称:GoRedis,代码行数:28,代码来源:monitor.go

示例3: main

func main() {
    flag.StringVar(&Settings.src, "src", "src", "name for traffic src")
    flag.StringVar(&Settings.dst, "dst", "dst", "name for traffic dst")
    flag.StringVar(&Settings.graphite, "graphite", "", "name for traffic dst")
    flag.StringVar(&Settings.prefix, "prefix", "", "prefix for reported timings")
    flag.Parse()

    if Settings.graphite == "" || Settings.prefix == "" {
        log.Fatal("must supply graphite server and prefix")
    }

    report.NewRecorder().
        ReportTo(Settings.graphite, Settings.prefix).
        LogToConsole().
        SetAsDefault()

    scanner := bufio.NewScanner(os.Stdin)

    for scanner.Scan() {
        encoded := scanner.Bytes()

        buf := make([]byte, hex.DecodedLen(len(encoded)))
        hex.Decode(buf, encoded)

        kind := buf[0]
        if kind == RequestFlag {
            os.Stdout.Write(encoded)
        }
        go handle(kind, buf)
    }
}

开发者ID:theevocater,项目名称:gor-speedtest,代码行数:31,代码来源:main.go

示例4: getShaFor

func getShaFor(url string) ([]byte, error) {
    res, err := http.Get(url + ".sha1")
    if err != nil {
        return nil, err
    }
    defer res.Body.Close()

    if res.StatusCode != http.StatusOK {
        return nil, fmt.Errorf("HTTP Status: %d", res.StatusCode)
    }

    b, err := ioutil.ReadAll(res.Body)
    if err != nil {
        return nil, err
    }

    b = bytes.TrimSpace(b)

    b = b[:40]

    s := make([]byte, hex.DecodedLen(len(b)))

    if _, err := hex.Decode(s, b); err != nil {
        return nil, err
    }

    return s, nil
}

开发者ID:kellegous,项目名称:bungler,代码行数:28,代码来源:util.go

示例5: Decode

// Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a
// destination.
func Decode(dst *Hash, src string) error {
    // Return error if hash string is too long.
    if len(src) > MaxHashStringSize {
        return ErrHashStrSize
    }

    // Hex decoder expects the hash to be a multiple of two.  When not, pad
    // with a leading zero.
    var srcBytes []byte
    if len(src)%2 == 0 {
        srcBytes = []byte(src)
    } else {
        srcBytes = make([]byte, 1+len(src))
        srcBytes[0] = '0'
        copy(srcBytes[1:], src)
    }

    // Hex decode the source bytes to a temporary destination.
    var reversedHash Hash
    _, err := hex.Decode(reversedHash[HashSize-hex.DecodedLen(len(srcBytes)):], srcBytes)
    if err != nil {
        return err
    }

    // Reverse copy from the temporary hash to destination.  Because the
    // temporary was zeroed, the written result will be correctly padded.
    for i, b := range reversedHash[:HashSize/2] {
        dst[i], dst[HashSize-1-i] = reversedHash[HashSize-1-i], b
    }

    return nil
}

开发者ID:decred,项目名称:dcrd,代码行数:34,代码来源:hash.go

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