From a63dd6020cf8c2367ac0af405455fe1d2bd586c4 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 17 Jan 2016 10:45:17 +0000 Subject: [PATCH] onedrive: fix incorrectly decoded SHA-1 --- onedrive/onedrive.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/onedrive/onedrive.go b/onedrive/onedrive.go index e1c4ada4c..89a495293 100644 --- a/onedrive/onedrive.go +++ b/onedrive/onedrive.go @@ -4,7 +4,6 @@ package onedrive import ( "bytes" - "encoding/base64" "fmt" "io" "log" @@ -14,8 +13,6 @@ import ( "sync" "time" - "encoding/hex" - "github.com/ncw/rclone/dircache" "github.com/ncw/rclone/fs" "github.com/ncw/rclone/oauthutil" @@ -727,14 +724,15 @@ func (o *Object) setMetaData(info *api.Item) { o.hasMetaData = true o.size = info.Size + // Docs: https://dev.onedrive.com/facets/hashes_facet.htm + // + // The docs state both that the hashes are returned as hex + // strings, and as base64 strings. Testing reveals they are in + // fact uppercase hex strings. + // // In OneDrive for Business, SHA1 and CRC32 hash values are not returned for files. if info.File != nil && info.File.Hashes.Sha1Hash != "" { - sha1sumData, err := base64.StdEncoding.DecodeString(info.File.Hashes.Sha1Hash) - if err != nil { - fs.Log(o, "Bad SHA1 decode: %v", err) - } else { - o.sha1 = hex.EncodeToString(sha1sumData) - } + o.sha1 = strings.ToLower(info.File.Hashes.Sha1Hash) } if info.FileSystemInfo != nil { o.modTime = time.Time(info.FileSystemInfo.LastModifiedDateTime)