diff options
author | Jakob Unterwurzacher | 2015-09-05 20:30:20 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2015-09-05 20:30:20 +0200 |
commit | 11fb037e7e7d84405b3bed9de2aa500e49d9502d (patch) | |
tree | f94eea4b2cccc1620b51f163837d26082e6cae58 /cryptfs/intrablock.go | |
parent | 7e564f928fef80b0485210603a8aa58b14ca5109 (diff) |
Cleanup and rename files
Diffstat (limited to 'cryptfs/intrablock.go')
-rw-r--r-- | cryptfs/intrablock.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/cryptfs/intrablock.go b/cryptfs/intrablock.go new file mode 100644 index 0000000..78fd140 --- /dev/null +++ b/cryptfs/intrablock.go @@ -0,0 +1,39 @@ +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 + 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 { + return true + } + return false +} + +// CiphertextRange - get byte range in ciphertext file corresponding to BlockNo +// (complete block) +func (ib *intraBlock) CiphertextRange() (offset uint64, length uint64) { + return ib.BlockNo * ib.fs.cipherBS, 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 +} + +// 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) + if lenHave < lenWant { + return d[ib.Offset:lenHave] + } + return d[ib.Offset:lenWant] +} |