diff options
author | Jakob Unterwurzacher | 2016-08-30 00:20:31 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2016-09-25 16:43:17 +0200 |
commit | 5931eea3877ae34cdb18ac36e5cf5fba3f74b82b (patch) | |
tree | f6cd8dd41c213013741ae893e67ec1adf3ff5b4c /internal/contentenc/intrablock.go | |
parent | 1d4c6288f29d74efce83ada1ea2a7b3819178bde (diff) |
contentenc: add helpers for reverse mode
Add the reverse variant of DecryptBlocks etc:
* EncryptBlocks
* JointPlaintextRange
* ExplodeCipherRange
Diffstat (limited to 'internal/contentenc/intrablock.go')
-rw-r--r-- | internal/contentenc/intrablock.go | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/internal/contentenc/intrablock.go b/internal/contentenc/intrablock.go index 9a22ea2..632e76b 100644 --- a/internal/contentenc/intrablock.go +++ b/internal/contentenc/intrablock.go @@ -2,10 +2,19 @@ package contentenc // intraBlock identifies a part of a file block type intraBlock struct { - BlockNo uint64 // Block number in file - Skip uint64 // Offset into block plaintext - Length uint64 // Length of plaintext data in this block - fs *ContentEnc + // Block number in the file + BlockNo uint64 + // Offset into block payload + // In forwared mode: block plaintext + // In reverse mode: offset into block ciphertext. Takes the header into + // account. + Skip uint64 + // Length of payload data in this block + // In forwared mode: length of the plaintext + // In reverse mode: length of the ciphertext. Takes header and trailer into + // account. + Length uint64 + fs *ContentEnc } // isPartial - is the block partial? This means we have to do read-modify-write. @@ -47,3 +56,14 @@ func (ib *intraBlock) JointCiphertextRange(blocks []intraBlock) (offset uint64, return offset, length } + +// Plaintext range corresponding to the sum of all "blocks" (complete blocks) +func JointPlaintextRange(blocks []intraBlock) (offset uint64, length uint64) { + firstBlock := blocks[0] + lastBlock := blocks[len(blocks)-1] + + offset = firstBlock.BlockPlainOff() + length = lastBlock.BlockPlainOff() + lastBlock.fs.PlainBS() - offset + + return offset, length +} |