diff options
author | Jakob Unterwurzacher | 2021-05-26 18:28:59 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2021-05-26 18:28:59 +0200 |
commit | 07164cbb3a42946a8bb0286da1bc7ea52bb33ee1 (patch) | |
tree | 2bade682e75489597aed6a71bca64455f766e403 /internal/contentenc/offsets.go | |
parent | b4794bedecbddfd90c2a018825a798d2989a2838 (diff) |
contentenc: add PlainOffToCipherOff helper
Will be used for improving Lseek()
Diffstat (limited to 'internal/contentenc/offsets.go')
-rw-r--r-- | internal/contentenc/offsets.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/internal/contentenc/offsets.go b/internal/contentenc/offsets.go index 7487baf..3a0abf3 100644 --- a/internal/contentenc/offsets.go +++ b/internal/contentenc/offsets.go @@ -76,20 +76,20 @@ func (be *ContentEnc) CipherSizeToPlainSize(cipherSize uint64) uint64 { return cipherSize - overhead } -// PlainSizeToCipherSize calculates the ciphertext size from a plaintext size +// PlainSizeToCipherSize calculates the ciphertext size from a plaintext size. func (be *ContentEnc) PlainSizeToCipherSize(plainSize uint64) uint64 { // Zero-sized files stay zero-sized if plainSize == 0 { return 0 } + return be.PlainOffToCipherOff(plainSize-1) + 1 +} - // Block number at last byte - blockNo := be.PlainOffToBlockNo(plainSize - 1) - blockCount := blockNo + 1 - - overhead := be.BlockOverhead()*blockCount + HeaderLen - - return plainSize + overhead +// PlainOffToCipherOff tells you the highest ciphertext offset that is +// *guaranteed* to be written/read when you write/read at `plainOff`. +func (be *ContentEnc) PlainOffToCipherOff(plainOff uint64) uint64 { + startOfBlock := be.BlockNoToCipherOff(be.PlainOffToBlockNo(plainOff)) + return startOfBlock + plainOff%be.PlainBS() + be.BlockOverhead() } // ExplodePlainRange splits a plaintext byte range into (possibly partial) blocks |