summaryrefslogtreecommitdiff
path: root/cryptfs/intrablock.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-11-01 12:11:36 +0100
committerJakob Unterwurzacher2015-11-01 12:11:36 +0100
commit902babdf22199d73171716e643f1ffbb65e6fb48 (patch)
treec3194bce9fd9b4db0a569fca3b5041abd278be70 /cryptfs/intrablock.go
parent14276c96328a1a1ad2b354c65d8db7fa720559e1 (diff)
Refactor ciphertext <-> plaintext offset translation functions
Move all the intelligence into the new file address_translation.go. That the calculations were spread out too much became apparent when adding the file header. This should make the code much easier to modify in the future.
Diffstat (limited to 'cryptfs/intrablock.go')
-rw-r--r--cryptfs/intrablock.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/cryptfs/intrablock.go b/cryptfs/intrablock.go
index c83976c..faff471 100644
--- a/cryptfs/intrablock.go
+++ b/cryptfs/intrablock.go
@@ -19,13 +19,13 @@ func (ib *intraBlock) IsPartial() bool {
// CiphertextRange - get byte range in ciphertext file corresponding to BlockNo
// (complete block)
func (ib *intraBlock) CiphertextRange() (offset uint64, length uint64) {
- return HEADER_LEN + ib.BlockNo * ib.fs.cipherBS, ib.fs.cipherBS
+ return ib.fs.BlockNoToCipherOff(ib.BlockNo), ib.fs.cipherBS
}
// PlaintextRange - get byte range in plaintext corresponding to BlockNo
// (complete block)
func (ib *intraBlock) PlaintextRange() (offset uint64, length uint64) {
- return ib.BlockNo * ib.fs.plainBS, ib.fs.plainBS
+ return ib.fs.BlockNoToPlainOff(ib.BlockNo), ib.fs.plainBS
}
// CropBlock - crop a potentially larger plaintext block down to the relevant part
@@ -37,3 +37,15 @@ func (ib *intraBlock) CropBlock(d []byte) []byte {
}
return d[ib.Skip:lenWant]
}
+
+// Ciphertext range corresponding to the sum of all "blocks" (complete blocks)
+func (ib *intraBlock) JointCiphertextRange(blocks []intraBlock) (offset uint64, length uint64) {
+ firstBlock := blocks[0]
+ lastBlock := blocks[len(blocks)-1]
+
+ offset = ib.fs.BlockNoToCipherOff(firstBlock.BlockNo)
+ offsetLast := ib.fs.BlockNoToCipherOff(lastBlock.BlockNo)
+ length = offsetLast + ib.fs.cipherBS - offset
+
+ return offset, length
+}