aboutsummaryrefslogtreecommitdiff
path: root/cryptfs
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-09-05 19:07:20 +0200
committerJakob Unterwurzacher2015-09-05 19:07:20 +0200
commit199d3fd79ff03222cf7498418b40e1263f8aa104 (patch)
treee20363482b6332969687302b8e0fa668160b38d0 /cryptfs
parent4ab9862ccb5911836acda9834b0b25f892229533 (diff)
Fix write path
Diffstat (limited to 'cryptfs')
-rw-r--r--cryptfs/cryptfile.go18
-rw-r--r--cryptfs/cryptfs.go4
2 files changed, 19 insertions, 3 deletions
diff --git a/cryptfs/cryptfile.go b/cryptfs/cryptfile.go
index 0cd11da..98b6d12 100644
--- a/cryptfs/cryptfile.go
+++ b/cryptfs/cryptfile.go
@@ -115,14 +115,26 @@ func (ib *intraBlock) IsPartial() bool {
return false
}
-// ciphertextRange - get byte range in ciphertext file corresponding to BlockNo
+// CiphertextRange - get byte range in ciphertext file corresponding to BlockNo
+// (complete block)
func (ib *intraBlock) CiphertextRange() (offset int64, length int64) {
return ib.BlockNo * ib.fs.cipherBS, ib.fs.cipherBS
}
-// CropBlock - crop a full plaintext block down to the relevant part
+// PlaintextRange - get byte range in plaintext corresponding to BlockNo
+// (complete block)
+func (ib *intraBlock) PlaintextRange() (offset int64, length int64) {
+ 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{
- return d[ib.Offset:ib.Offset+ib.Length]
+ lenHave := len(d)
+ lenWant := int(ib.Offset+ib.Length)
+ if lenHave < lenWant {
+ return d[ib.Offset:lenHave]
+ }
+ return d[ib.Offset:lenWant]
}
// Split a plaintext byte range into (possible partial) blocks
diff --git a/cryptfs/cryptfs.go b/cryptfs/cryptfs.go
index f5781e2..72eea61 100644
--- a/cryptfs/cryptfs.go
+++ b/cryptfs/cryptfs.go
@@ -55,6 +55,10 @@ func (fs *CryptFS) NewFile(f *os.File) *CryptFile {
}
}
+func (be *CryptFS) PlainBS() int64 {
+ return be.plainBS
+}
+
// DecryptName - decrypt filename
func (be *CryptFS) decryptName(cipherName string) (string, error) {