mirror of
https://github.com/rclone/rclone.git
synced 2025-08-10 06:09:44 +02:00
serve sftp: add support for more hashes (crc32, sha256, blake3, xxh3, xxh128)
This commit is contained in:
@@ -1756,12 +1756,11 @@ func (f *Fs) Hashes() hash.Set {
|
|||||||
&f.opt.Xxh3sumCommand,
|
&f.opt.Xxh3sumCommand,
|
||||||
"2d06800538d394c2",
|
"2d06800538d394c2",
|
||||||
[]struct{ hashFile, hashEmpty string }{
|
[]struct{ hashFile, hashEmpty string }{
|
||||||
// The xxhsum tool uses an alternative BSD style output format for the 64-bit variant of XXH3,
|
// The xxhsum tool uses a non-standard prefix "XXH3_" preceding the hash output for the 64-bit variant
|
||||||
// otherwise optional with argument --tag, to avoid confusion with the older 64-bit algorithm XXH64.
|
// of XXH3, to avoid confusion with the older 64-bit algorithm XXH64. This was introduced in version
|
||||||
// For the same reason there is no algorithm-specific alias, xxh3sum, either. We are currently not able
|
// 0.8.3 released Dec 30, 2024. Older versions only supported the alternative BSD style output format,
|
||||||
// to parse this output format. Next release of xxHash after 0.8.2 will change to GNU style, classic
|
// otherwise optional with argument --tag. We are currently not expecting these output formats and can
|
||||||
// md5sum, output format, but will use a non-standard prefix "XXH3_" preceding the hash, so we still
|
// therefore not use the "xxhsum -H3" command or its xxh3sum alias directly.
|
||||||
// need additional changes to be able to support it.
|
|
||||||
//{"xxh3sum", "xxh3sum"},
|
//{"xxh3sum", "xxh3sum"},
|
||||||
//{"xxhsum -H3", "xxhsum -H3"},
|
//{"xxhsum -H3", "xxhsum -H3"},
|
||||||
{"rclone hashsum xxh3", "rclone hashsum xxh3"},
|
{"rclone hashsum xxh3", "rclone hashsum xxh3"},
|
||||||
|
@@ -95,12 +95,44 @@ func (c *conn) execCommand(ctx context.Context, out io.Writer, command string) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("send output failed: %w", err)
|
return fmt.Errorf("send output failed: %w", err)
|
||||||
}
|
}
|
||||||
case "md5sum", "sha1sum":
|
case "md5sum":
|
||||||
ht := hash.MD5
|
return c.handleHashsumCommand(ctx, out, hash.MD5, args)
|
||||||
if binary == "sha1sum" {
|
case "sha1sum":
|
||||||
ht = hash.SHA1
|
return c.handleHashsumCommand(ctx, out, hash.SHA1, args)
|
||||||
|
case "crc32":
|
||||||
|
return c.handleHashsumCommand(ctx, out, hash.CRC32, args)
|
||||||
|
case "sha256sum":
|
||||||
|
return c.handleHashsumCommand(ctx, out, hash.SHA256, args)
|
||||||
|
case "b3sum":
|
||||||
|
return c.handleHashsumCommand(ctx, out, hash.BLAKE3, args)
|
||||||
|
case "xxh128sum":
|
||||||
|
return c.handleHashsumCommand(ctx, out, hash.XXH128, args)
|
||||||
|
case "xxhsum":
|
||||||
|
argv := strings.SplitN(args, " ", 2)
|
||||||
|
if len(argv) == 0 || argv[0] != "-H2" {
|
||||||
|
return fmt.Errorf("%q not implemented", command)
|
||||||
|
}
|
||||||
|
if len(argv) > 1 {
|
||||||
|
args = argv[1]
|
||||||
|
} else {
|
||||||
|
args = ""
|
||||||
|
}
|
||||||
|
return c.handleHashsumCommand(ctx, out, hash.XXH128, args)
|
||||||
|
case "rclone":
|
||||||
|
argv := strings.SplitN(args, " ", 3)
|
||||||
|
if len(argv) > 1 && argv[0] == "hashsum" {
|
||||||
|
var ht hash.Type
|
||||||
|
if err := ht.Set(argv[1]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(argv) > 2 {
|
||||||
|
args = argv[2]
|
||||||
|
} else {
|
||||||
|
args = ""
|
||||||
}
|
}
|
||||||
return c.handleHashsumCommand(ctx, out, ht, args)
|
return c.handleHashsumCommand(ctx, out, ht, args)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("%q not implemented", command)
|
||||||
case "echo":
|
case "echo":
|
||||||
// Special cases for legacy rclone command detection.
|
// Special cases for legacy rclone command detection.
|
||||||
// Before rclone v1.49.0 the sftp backend used "echo 'abc' | md5sum" when
|
// Before rclone v1.49.0 the sftp backend used "echo 'abc' | md5sum" when
|
||||||
@@ -148,10 +180,23 @@ func (c *conn) handleHashsumCommand(ctx context.Context, out io.Writer, ht hash.
|
|||||||
var hashSum string
|
var hashSum string
|
||||||
if args == "" {
|
if args == "" {
|
||||||
// empty hash for no input
|
// empty hash for no input
|
||||||
if ht == hash.MD5 {
|
switch ht {
|
||||||
|
case hash.MD5:
|
||||||
hashSum = "d41d8cd98f00b204e9800998ecf8427e"
|
hashSum = "d41d8cd98f00b204e9800998ecf8427e"
|
||||||
} else {
|
case hash.SHA1:
|
||||||
hashSum = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
hashSum = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
||||||
|
case hash.CRC32:
|
||||||
|
hashSum = "00000000"
|
||||||
|
case hash.SHA256:
|
||||||
|
hashSum = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||||
|
case hash.BLAKE3:
|
||||||
|
hashSum = "af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262"
|
||||||
|
case hash.XXH3:
|
||||||
|
hashSum = "2d06800538d394c2"
|
||||||
|
case hash.XXH128:
|
||||||
|
hashSum = "99aa06d3014798d86001c324468d497f"
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("%v hash not implemented", ht)
|
||||||
}
|
}
|
||||||
args = "-"
|
args = "-"
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user