/
types.go
95 lines (74 loc) · 2.17 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package storage
import (
"context"
"github.com/jmoiron/sqlx"
)
// SQLXConnection is a *sqlx.DB or *sqlx.Tx.
type SQLXConnection interface {
sqlx.Execer
sqlx.ExecerContext
sqlx.Preparer
sqlx.PreparerContext
sqlx.Queryer
sqlx.QueryerContext
sqlx.Ext
sqlx.ExtContext
}
// EncryptionChangeKeyFunc handles encryption key changes for a specific table or tables.
type EncryptionChangeKeyFunc func(ctx context.Context, provider *SQLProvider, tx *sqlx.Tx, key [32]byte) (err error)
// EncryptionCheckKeyFunc handles encryption key checking for a specific table or tables.
type EncryptionCheckKeyFunc func(ctx context.Context, provider *SQLProvider) (table string, result EncryptionValidationTableResult)
type encOAuth2Session struct {
ID int `db:"id"`
Session []byte `db:"session_data"`
}
type encWebauthnDevice struct {
ID int `db:"id"`
PublicKey []byte `db:"public_key"`
}
type encTOTPConfiguration struct {
ID int `db:"id" json:"-"`
Secret []byte `db:"secret" json:"-"`
}
// EncryptionValidationResult contains information about the success of a schema encryption validation.
type EncryptionValidationResult struct {
InvalidCheckValue bool
Tables map[string]EncryptionValidationTableResult
}
// Success returns true if no validation errors occurred.
func (r EncryptionValidationResult) Success() bool {
if r.InvalidCheckValue {
return false
}
for _, table := range r.Tables {
if table.Invalid != 0 || table.Error != nil {
return false
}
}
return true
}
// Checked returns true the validation completed all phases even if there were errors.
func (r EncryptionValidationResult) Checked() bool {
for _, table := range r.Tables {
if table.Error != nil {
return false
}
}
return true
}
// EncryptionValidationTableResult contains information about the success of a table schema encryption validation.
type EncryptionValidationTableResult struct {
Error error
Total int
Invalid int
}
// ResultDescriptor returns a string representing the result.
func (r EncryptionValidationTableResult) ResultDescriptor() string {
if r.Total == 0 {
return na
}
if r.Error != nil || r.Invalid != 0 {
return "FAILURE"
}
return "SUCCESS"
}