Skip to content

Commit 48d86fd

Browse files
committed
update README with new changes
1 parent 497d319 commit 48d86fd

2 files changed

Lines changed: 12 additions & 21 deletions

File tree

README.md

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
`pandorasbox` is a Go package that allows for simple use of both a host's filesystem, and a virtual filesystem.
66

7-
The design goal of Pandora's Box is to easily facilitate the use of a transparently-encrypted VFS (virtual filesystem), and the host's filesystem. It does this by providing functions and methods that operate and look the same as the Go standard library `os` package. If you want to interact with the VFS, pass in a path that starts with `vfs://`, and Pandora's Box will automatically use the VFS. Otherwise, the host's filesystem will be used.
7+
The design goal of Pandora's Box is to easily facilitate the use of a transparently-encrypted VFS (virtual filesystem) and the host's filesystem. It does this by providing functions and methods that operate and look the same as the Go standard library `os` package. If you want to interact with the VFS, pass in a path that starts with `vfs://`, and Pandora's Box will automatically use the VFS. Otherwise, the host's filesystem will be used.
88

99
## Using Pandora's Box
1010

@@ -23,12 +23,12 @@ func CopyFile(srcFile, dstFile string) error {
2323
in, err := os.Open(srcFile)
2424
defer in.Close()
2525
if err != nil {
26-
return err
26+
return err
2727
}
2828

2929
_, err = io.Copy(out, in)
3030
if err != nil {
31-
return err
31+
return err
3232
}
3333

3434
return nil
@@ -40,10 +40,6 @@ All it takes to make this function VFS-friendly is switching from using `os` to
4040
```go
4141
import box "github.com/capnspacehook/pandorasbox"
4242

43-
func init() {
44-
box.InitGlobalBox()
45-
}
46-
4743
func CopyFile(srcFile, dstFile string) error {
4844
out, err := box.Create(dstFile)
4945
if err != nil {
@@ -68,7 +64,6 @@ func CopyFile(srcFile, dstFile string) error {
6864

6965
### Global vs. Local VFS
7066

71-
You probably noticed the call to `box.InitGlobalBox()` in the last example. This has to be called **before** the global VFS can be used.
7267
For ease of use, Pandora's box provides a global `Box` that is easily accessible, but in some cases a local `Box` may be desired. If you don't wish to use the global `Box`, don't call `box.InitGlobalBox()`, instead create a locally scoped `Box` by calling `box.NewBox()`. This allows you to easily pass a `Box` into functions or methods or embed a `Box` in a struct.
7368

7469
### `io/ioutil` and `path/filepath` Functions
@@ -78,26 +73,19 @@ Pandora's Box also provides helper functions that are identical to functions fro
7873
Example (error handling omitted):
7974

8075
```go
81-
import (
82-
box "github.com/capnspacehook/pandorasbox"
83-
"github.com/capnspacehook/pandorasbox/ioutil"
84-
)
85-
86-
func init() {
87-
box.InitGlobalBox()
88-
}
76+
import box "github.com/capnspacehook/pandorasbox"
8977

9078
func WriteFileGlobalBox() {
91-
box.WriteFile("vfs://file.txt", []byte("Testing testing 1 2 3"), 0644)
79+
box.WriteFile("vfs://file.txt", []byte("Testing testing 1 2 3"), 0o644)
9280
data, _ := box.ReadFile("vfs://file.txt")
9381
fmt.Println(string(data))
9482
}
9583

9684
func WriteFileLocalBox() {
9785
myBox := box.NewBox()
9886

99-
ioutil.WriteFile(myBox, "vfs://file.txt", []byte("Testing testing 1 2 3"), 0644)
100-
data, _ := ioutil.ReadFile(myBox, "vfs://file.txt")
87+
myBox.WriteFile("vfs://file.txt", []byte("Testing testing 1 2 3"), 0o644)
88+
data, _ := myBox.ReadFile("vfs://file.txt")
10189
fmt.Println(string(data))
10290
}
10391
```
@@ -108,7 +96,10 @@ If for some reason you need to force the usage of either the host's filesystem o
10896

10997
### Memory Safety
11098

111-
All files in the VFS are encrypted when not in use. When files from the VFS are opened, they are decrypted for the duration of the call that opened them. VFS files are then re-encrypted with a different random key when reading or writing from them is finished. That is, files in the VFS are only decrypted in memory for a brief time while the underlying data needs to be accessed. In other words, calling `Open()` on a VFS file **will not** decrypt it until `Close()` is called on it. It will only be decrypted in memory when it is internally opened by methods like `Read()`, `Write()`, `Truncate()`, etc. And it is immediately closed afterwards. So opening a VFS file and calling `Read()` on it 3 times will decrypt and re-encrypt it 3 times. This is to make sure data is encrypted in memory whenever possible.
99+
All files in the VFS are encrypted when not in use. When files from the VFS are opened, they are decrypted for the duration of the call that opened them. VFS files are then re-encrypted with a different random key when reading or writing from them is finished. That is, files in the VFS are only decrypted in memory for a brief time while the underlying data needs to be accessed. In other words, calling `Open()` on a VFS file **will not** decrypt it until `Close()` is called on it. It will only be decrypted in memory when it is internally opened by methods like `Read()`, `Write()`, `Truncate()`, etc. Internal decrypted buffers are wiped as soon as possible. So opening a VFS file and calling `Read()` on it 3 times will decrypt and re-encrypt it 3 times. This is to make sure data is encrypted in memory whenever possible.
100+
101+
`pandorasbox` never wipes buffers that are owned by the user, so you will need to wipe buffers yourself when calling `Write()`
102+
for example if you don't want the buffer to stick around in memory unencrypted.
112103

113104
For more information about the exact cryptographic code and algorithms used, refer to this repo: https://github.com/awnumar/memguard.
114105

vfs/vfs_fuzz_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const (
5757

5858
// FuzzVFSRace preforms random operations on a virtual filesystem in
5959
// two different goroutines and checks that operations don't fail
60-
// when unexpectedly. It also tests that operations preform as expected
60+
// unexpectedly. It also tests that operations preform as expected
6161
// when multiple operations are preformed concurrently. It should be
6262
// run with the race detector enabled for best results.
6363
func FuzzVFSRace(f *testing.F) {

0 commit comments

Comments
 (0)