mirror of
https://github.com/reactos/syzkaller.git
synced 2024-11-25 04:19:53 +00:00
cd74cc9cf4
syz-hub is used to exchange programs between syz-managers.
36 lines
733 B
Go
36 lines
733 B
Go
// Copyright 2016 syzkaller project authors. All rights reserved.
|
|
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
|
|
|
|
package hash
|
|
|
|
import (
|
|
"crypto/sha1"
|
|
"encoding/hex"
|
|
"fmt"
|
|
)
|
|
|
|
type Sig [sha1.Size]byte
|
|
|
|
func Hash(data []byte) Sig {
|
|
return Sig(sha1.Sum(data))
|
|
}
|
|
|
|
func (sig *Sig) String() string {
|
|
return hex.EncodeToString((*sig)[:])
|
|
}
|
|
|
|
func FromString(str string) (Sig, error) {
|
|
bin, err := hex.DecodeString(str)
|
|
if err != nil {
|
|
return Sig{}, fmt.Errorf("failed to decode sig '%v': %v", str, err)
|
|
}
|
|
if len(bin) != len(Sig{}) {
|
|
return Sig{}, fmt.Errorf("failed to decode sig '%v': bad len", str)
|
|
}
|
|
var sig Sig
|
|
for i, v := range bin {
|
|
sig[i] = v
|
|
}
|
|
return sig, err
|
|
}
|