From c859f0b2dc8825763c3b63163a014435a8cdb3cf Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 4 Oct 2015 14:24:43 +0200 Subject: intraBlock: Rename Offset to Skip "Offset" is unclear whether it is an offset from the start of file or start of block. "Skip" seems much better. --- cryptfs/content_test.go | 4 ++-- cryptfs/cryptfs_content.go | 6 +++--- cryptfs/intrablock.go | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'cryptfs') diff --git a/cryptfs/content_test.go b/cryptfs/content_test.go index 8fd33c6..8f1d48b 100644 --- a/cryptfs/content_test.go +++ b/cryptfs/content_test.go @@ -25,8 +25,8 @@ func TestSplitRange(t *testing.T) { for _, r := range(ranges) { parts := f.SplitRange(r.offset, r.length) for _, p := range(parts) { - if p.Length > DEFAULT_PLAINBS || p.Offset >= DEFAULT_PLAINBS { - fmt.Printf("Test fail: n=%d, length=%d, offset=%d\n", p.BlockNo, p.Length, p.Offset) + if p.Length > DEFAULT_PLAINBS || p.Skip >= DEFAULT_PLAINBS { + fmt.Printf("Test fail: n=%d, length=%d, offset=%d\n", p.BlockNo, p.Length, p.Skip) t.Fail() } } diff --git a/cryptfs/cryptfs_content.go b/cryptfs/cryptfs_content.go index ab5ec78..761fef5 100644 --- a/cryptfs/cryptfs_content.go +++ b/cryptfs/cryptfs_content.go @@ -112,8 +112,8 @@ func (be *CryptFS) SplitRange(offset uint64, length uint64) []intraBlock { for length > 0 { b.BlockNo = offset / be.plainBS - b.Offset = offset % be.plainBS - b.Length = be.minu64(length, be.plainBS - b.Offset) + b.Skip = offset % be.plainBS + b.Length = be.minu64(length, be.plainBS - b.Skip) parts = append(parts, b) offset += b.Length length -= b.Length @@ -187,7 +187,7 @@ func (be *CryptFS) JoinCiphertextRange(blocks []intraBlock) (uint64, uint64) { // Crop plaintext that correspons to complete cipher blocks down to what is // requested according to "iblocks" func (be *CryptFS) CropPlaintext(plaintext []byte, blocks []intraBlock) []byte { - offset := blocks[0].Offset + offset := blocks[0].Skip last := blocks[len(blocks)-1] length := (last.BlockNo - blocks[0].BlockNo + 1) * be.plainBS var cropped []byte diff --git a/cryptfs/intrablock.go b/cryptfs/intrablock.go index 78fd140..552cb3c 100644 --- a/cryptfs/intrablock.go +++ b/cryptfs/intrablock.go @@ -3,14 +3,14 @@ package cryptfs // intraBlock identifies a part of a file block type intraBlock struct { BlockNo uint64 // Block number in file - Offset uint64 // Offset into block plaintext + Skip uint64 // Offset into block plaintext Length uint64 // Length of data from this block fs *CryptFS } // isPartial - is the block partial? This means we have to do read-modify-write. func (ib *intraBlock) IsPartial() bool { - if ib.Offset > 0 || ib.Length < ib.fs.plainBS { + if ib.Skip > 0 || ib.Length < ib.fs.plainBS { return true } return false @@ -31,9 +31,9 @@ func (ib *intraBlock) PlaintextRange() (offset uint64, length uint64) { // CropBlock - crop a potentially larger plaintext block down to the relevant part func (ib *intraBlock) CropBlock(d []byte) []byte{ lenHave := len(d) - lenWant := int(ib.Offset+ib.Length) + lenWant := int(ib.Skip+ib.Length) if lenHave < lenWant { - return d[ib.Offset:lenHave] + return d[ib.Skip:lenHave] } - return d[ib.Offset:lenWant] + return d[ib.Skip:lenWant] } -- cgit v1.2.3