Add mailru hash (mrhash)

This commit is contained in:
Ivan Andreev
2019-09-09 21:34:15 +01:00
committed by Nick Craig-Wood
parent 94eb9a4014
commit bdcd0b4c64
4 changed files with 229 additions and 1 deletions
+12 -1
View File
@@ -13,6 +13,7 @@ import (
"github.com/jzelinskie/whirlpool"
"github.com/pkg/errors"
"github.com/rclone/rclone/backend/dropbox/dbhash"
"github.com/rclone/rclone/backend/mailru/mrhash"
"github.com/rclone/rclone/backend/onedrive/quickxorhash"
)
@@ -44,13 +45,16 @@ const (
// CRC32 indicates CRC-32 support
CRC32
// Mailru indicates Mailru special hash
Mailru
// None indicates no hashes are supported
None Type = 0
)
// Supported returns a set of all the supported hashes by
// HashStream and MultiHasher.
var Supported = NewHashSet(MD5, SHA1, Dropbox, QuickXorHash, Whirlpool, CRC32)
var Supported = NewHashSet(MD5, SHA1, Dropbox, QuickXorHash, Whirlpool, CRC32, Mailru)
// Width returns the width in characters for any HashType
var Width = map[Type]int{
@@ -60,6 +64,7 @@ var Width = map[Type]int{
QuickXorHash: 40,
Whirlpool: 128,
CRC32: 8,
Mailru: 40,
}
// Stream will calculate hashes of all supported hash types.
@@ -103,6 +108,8 @@ func (h Type) String() string {
return "Whirlpool"
case CRC32:
return "CRC-32"
case Mailru:
return "MailruHash"
default:
err := fmt.Sprintf("internal error: unknown hash type: 0x%x", int(h))
panic(err)
@@ -126,6 +133,8 @@ func (h *Type) Set(s string) error {
*h = Whirlpool
case "CRC-32":
*h = CRC32
case "MailruHash":
*h = Mailru
default:
return errors.Errorf("Unknown hash type %q", s)
}
@@ -160,6 +169,8 @@ func fromTypes(set Set) (map[Type]hash.Hash, error) {
hashers[t] = whirlpool.New()
case CRC32:
hashers[t] = crc32.NewIEEE()
case Mailru:
hashers[t] = mrhash.New()
default:
err := fmt.Sprintf("internal error: Unsupported hash type %v", t)
panic(err)
+2
View File
@@ -75,6 +75,7 @@ var hashTestSet = []hashTest{
hash.QuickXorHash: "0110c000085000031c0001095ec00218d0000700",
hash.Whirlpool: "eddf52133d4566d763f716e853d6e4efbabd29e2c2e63f56747b1596172851d34c2df9944beb6640dbdbe3d9b4eb61180720a79e3d15baff31c91e43d63869a4",
hash.CRC32: "a6041d7e",
hash.Mailru: "0102030405060708090a0b0c0d0e000000000000",
},
},
// Empty data set
@@ -87,6 +88,7 @@ var hashTestSet = []hashTest{
hash.QuickXorHash: "0000000000000000000000000000000000000000",
hash.Whirlpool: "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3",
hash.CRC32: "00000000",
hash.Mailru: "0000000000000000000000000000000000000000",
},
},
}