diff --git a/CHANGELOG.md b/CHANGELOG.md index a602e46..d239bad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This document outlines major changes between releases. ## [Unreleased] +### Fixed +- Fix expiration epoch calculation (#62) + ### Changed - Update go version for build to 1.19 (#61) diff --git a/handlers/util.go b/handlers/util.go index c708014..cde81ca 100644 --- a/handlers/util.go +++ b/handlers/util.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "math" "strconv" "time" @@ -153,9 +154,20 @@ func prepareExpirationHeader(headers map[string]string, epochDurations *epochDur } func updateExpirationHeader(headers map[string]string, durations *epochDurations, expDuration time.Duration) { - epochDuration := durations.msPerBlock * int64(durations.blockPerEpoch) - numEpoch := expDuration.Milliseconds() / epochDuration - headers[objectv2.SysAttributeExpEpoch] = strconv.FormatInt(int64(durations.currentEpoch)+numEpoch, 10) + epochDuration := uint64(durations.msPerBlock) * durations.blockPerEpoch + currentEpoch := durations.currentEpoch + numEpoch := uint64(expDuration.Milliseconds()) / epochDuration + + if uint64(expDuration.Milliseconds())%epochDuration != 0 { + numEpoch++ + } + + expirationEpoch := uint64(math.MaxUint64) + if numEpoch < math.MaxUint64-currentEpoch { + expirationEpoch = currentEpoch + numEpoch + } + + headers[objectv2.SysAttributeExpEpoch] = strconv.FormatUint(expirationEpoch, 10) } // IsObjectToken check that provided token is for object.