diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2016-11-17 18:38:10 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2016-11-17 18:38:10 +0100 |
| commit | cd74cc9cf40795144dfbd7e933dcd10d220916f6 (patch) | |
| tree | 6c1e55891acf53909da12aad34c86409be8c20a6 /hash | |
| parent | 3ad1f7a214ba9f22499ae6b2b8cc1f0b824073eb (diff) | |
syz-hub: add program
syz-hub is used to exchange programs between syz-managers.
Diffstat (limited to 'hash')
| -rw-r--r-- | hash/hash.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/hash/hash.go b/hash/hash.go new file mode 100644 index 000000000..d640536fe --- /dev/null +++ b/hash/hash.go @@ -0,0 +1,35 @@ +// 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 +} |
