Add BlockNoPlainOff() and BlockNoCipherOff() + test
Also, fix key, it is now []byte, not [16]byte
This commit is contained in:
parent
fa88741770
commit
5229b8f5f5
@ -19,7 +19,7 @@ func TestSplitRange(t *testing.T) {
|
||||
testRange{65444, 54},
|
||||
testRange{6654, 8945})
|
||||
|
||||
var key [16]byte
|
||||
key := make([]byte, 16)
|
||||
f := NewCryptFS(key, true)
|
||||
|
||||
for _, r := range(ranges) {
|
||||
@ -42,7 +42,7 @@ func TestCiphertextRange(t *testing.T) {
|
||||
testRange{65444, 54},
|
||||
testRange{6654, 8945})
|
||||
|
||||
var key [16]byte
|
||||
key := make([]byte, 16)
|
||||
f := NewCryptFS(key, true)
|
||||
|
||||
for _, r := range(ranges) {
|
||||
@ -58,3 +58,25 @@ func TestCiphertextRange(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockNo(t *testing.T) {
|
||||
key := make([]byte, 16)
|
||||
f := NewCryptFS(key, true)
|
||||
|
||||
b := f.BlockNoCipherOff(788)
|
||||
if b != 0 {
|
||||
t.Errorf("actual: %d", b)
|
||||
}
|
||||
b = f.BlockNoCipherOff(f.CipherBS())
|
||||
if b != 1 {
|
||||
t.Errorf("actual: %d", b)
|
||||
}
|
||||
b = f.BlockNoPlainOff(788)
|
||||
if b != 0 {
|
||||
t.Errorf("actual: %d", b)
|
||||
}
|
||||
b = f.BlockNoPlainOff(f.PlainBS())
|
||||
if b != 1 {
|
||||
t.Errorf("actual: %d", b)
|
||||
}
|
||||
}
|
||||
|
@ -219,3 +219,13 @@ func (be *CryptFS) MergeBlocks(oldData []byte, newData []byte, offset int) []byt
|
||||
}
|
||||
return out[0:outLen]
|
||||
}
|
||||
|
||||
// Get the block number at plain-text offset
|
||||
func (be *CryptFS) BlockNoPlainOff(plainOffset uint64) uint64 {
|
||||
return plainOffset / be.plainBS
|
||||
}
|
||||
|
||||
// Get the block number at ciphter-text offset
|
||||
func (be *CryptFS) BlockNoCipherOff(cipherOffset uint64) uint64 {
|
||||
return cipherOffset / be.cipherBS
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ func TestTranslatePath(t *testing.T) {
|
||||
s = append(s, "foo12312312312312312313123123123")
|
||||
s = append(s, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")
|
||||
|
||||
var key [16]byte
|
||||
key := make([]byte, 16)
|
||||
fs := NewCryptFS(key, true)
|
||||
|
||||
for _, n := range(s) {
|
||||
@ -32,8 +32,10 @@ func TestPad16(t *testing.T) {
|
||||
s = append(s, []byte("foo"))
|
||||
s = append(s, []byte("12345678901234567"))
|
||||
s = append(s, []byte("12345678901234567abcdefg"))
|
||||
var key [16]byte
|
||||
|
||||
key := make([]byte, 16)
|
||||
fs := NewCryptFS(key, true)
|
||||
|
||||
for i := range(s) {
|
||||
orig := s[i]
|
||||
padded := fs.pad16(orig)
|
||||
|
Loading…
Reference in New Issue
Block a user