@@ -26,6 +26,7 @@ func (h *hbshVFS) OpenFilename(name *vfs.Filename, flags vfs.OpenFlag) (file vfs
26
26
} else {
27
27
file , flags , err = h .Open (name .String (), flags )
28
28
}
29
+
29
30
// Encrypt everything except super journals and memory files.
30
31
if err != nil || flags & (vfs .OPEN_SUPER_JOURNAL | vfs .OPEN_MEMORY ) != 0 {
31
32
return file , flags , err
@@ -47,7 +48,12 @@ func (h *hbshVFS) OpenFilename(name *vfs.Filename, flags vfs.OpenFlag) (file vfs
47
48
}
48
49
hbsh = h .hbsh .HBSH (key )
49
50
}
50
- return & hbshFile {File : file , hbsh : hbsh , reset : h .hbsh }, flags , err
51
+
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
+ }
56
+ return nil , flags , sqlite3 .CANTOPEN
51
57
}
52
58
53
59
const (
@@ -87,9 +93,11 @@ func (h *hbshFile) Pragma(name string, value string) (string, error) {
87
93
88
94
func (h * hbshFile ) ReadAt (p []byte , off int64 ) (n int , err error ) {
89
95
if h .hbsh == nil {
96
+ // Only OPEN_MAIN_DB can have a missing key.
90
97
if off == 0 && len (p ) == 100 {
91
- // SQLite is trying to read the header of a database.
92
- // Pretend the file is empty so the key can be specified later.
98
+ // 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.
93
101
return 0 , io .EOF
94
102
}
95
103
return 0 , sqlite3 .CANTOPEN
@@ -140,7 +148,7 @@ func (h *hbshFile) WriteAt(p []byte, off int64) (n int, err error) {
140
148
if err != io .EOF {
141
149
return n , err
142
150
}
143
- // Writing past the EOF:
151
+ // Writing past the EOF.
144
152
// We're either appending an entirely new block,
145
153
// or the final block was only partially written.
146
154
// A partially written block can't be decrypted,
0 commit comments