Skip to content

Commit 67d859a

Browse files
committed
Support custom pepper.
1 parent 57daee7 commit 67d859a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

vfs/adiantum/adiantum.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import (
88
"lukechampine.com/adiantum/hbsh"
99
)
1010

11-
const pepper = "github.com/ncruces/go-sqlite3/vfs/adiantum"
11+
// This variable can be replaced with -ldflags:
12+
//
13+
// go build -ldflags="-X github.com/ncruces/go-sqlite3/vfs/adiantum.pepper=adiantum"
14+
var pepper = "github.com/ncruces/go-sqlite3/vfs/adiantum"
1215

1316
type adiantumCreator struct{}
1417

vfs/adiantum/hbsh.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,17 @@ func (h *hbshVFS) OpenFilename(name *vfs.Filename, flags vfs.OpenFlag) (file vfs
4545
key, _ = hex.DecodeString(t[0])
4646
} else if t, ok := params["textkey"]; ok {
4747
key = h.hbsh.KDF(t[0])
48+
} else if flags&vfs.OPEN_MAIN_DB != 0 {
49+
// Main datatabases may have their key specified as a PRAGMA.
50+
return &hbshFile{File: file, reset: h.hbsh}, flags, nil
4851
}
4952
hbsh = h.hbsh.HBSH(key)
5053
}
5154

52-
// Main datatabases may have their key specified later, as a PRAGMA.
53-
if hbsh != nil || flags&vfs.OPEN_MAIN_DB != 0 {
54-
return &hbshFile{File: file, hbsh: hbsh, reset: h.hbsh}, flags, nil
55+
if hbsh == nil {
56+
return nil, flags, sqlite3.CANTOPEN
5557
}
56-
return nil, flags, sqlite3.CANTOPEN
58+
return &hbshFile{File: file, hbsh: hbsh, reset: h.hbsh}, flags, nil
5759
}
5860

5961
const (
@@ -96,8 +98,7 @@ func (h *hbshFile) ReadAt(p []byte, off int64) (n int, err error) {
9698
// Only OPEN_MAIN_DB can have a missing key.
9799
if off == 0 && len(p) == 100 {
98100
// SQLite is trying to read the header of a database file.
99-
// Pretend the file is empty so the key may specified later,
100-
// as a PRAGMA.
101+
// Pretend the file is empty so the key may specified as a PRAGMA.
101102
return 0, io.EOF
102103
}
103104
return 0, sqlite3.CANTOPEN

0 commit comments

Comments
 (0)