Skip to content

Commit

Permalink
Merge pull request #11 from ValentinMontmirail/encryption
Browse files Browse the repository at this point in the history
Put back test to ensure encryption.
  • Loading branch information
ValentinMontmirail authored Dec 26, 2023
2 parents 62f3831 + 8c8da4c commit 4bd1a59
Show file tree
Hide file tree
Showing 4 changed files with 52,135 additions and 59,867 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
go: ['1.18', '1.19', '1.20','1.21']
go: ['1.19', '1.20','1.21']
fail-fast: false
env:
OS: ${{ matrix.os }}
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:

strategy:
matrix:
go: ['1.18', '1.19', '1.20','1.21']
go: ['1.19', '1.20','1.21']
fail-fast: false
env:
OS: windows-latest
Expand Down
35 changes: 35 additions & 0 deletions sqlcipher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package sqlite3

import (
"bytes"
"errors"
"os"
)

// sqlite3Header defines the header string used by SQLite 3.
var sqlite3Header = []byte("SQLite format 3\000")

// IsEncrypted returns true, if the database with the given filename is
// encrypted, and false otherwise.
// If the database header cannot be read properly an error is returned.
func IsEncrypted(filename string) (bool, error) {
// open file
db, err := os.Open(filename)
if err != nil {
return false, err
}
defer db.Close()
// read header
var header [16]byte
n, err := db.Read(header[:])
if err != nil {
return false, err
}
if n != len(header) {
return false, errors.New("go-sqlcipher: could not read full header")
}
// SQLCipher encrypts also the header, the file is encrypted if the read
// header does not equal the header string used by SQLite 3.
encrypted := !bytes.Equal(header[:], sqlite3Header)
return encrypted, nil
}
Loading

0 comments on commit 4bd1a59

Please sign in to comment.