Documentation
¶
Index ¶
- type KeyStore
- func New(ctx context.Context, filename string, ...) (*KeyStore, error)
- func NewFromDB(ctx context.Context, db *sql.DB, own bool, ...) (*KeyStore, error)
- func NewSchema(ctx context.Context, filename, migrationsTable string, ...) (*KeyStore, error)
- func NewSchemaFromDB(ctx context.Context, db *sql.DB, migrationsTable string, own bool, ...) (*KeyStore, error)
- func (ks *KeyStore) Close() error
- func (ks *KeyStore) DecoderByID(ctx context.Context, id int64) (typ int, dec encid.Decrypter, err error)
- func (ks *KeyStore) EncoderByType(ctx context.Context, typ int) (id int64, enc encid.Encrypter, err error)
- func (ks *KeyStore) NewKey(ctx context.Context, typ, keysize int) (int64, error)
- func (ks *KeyStore) Version() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyStore ¶
type KeyStore struct {
// contains filtered or unexported fields
}
KeyStore is an implementation of encid.KeyStore backed by a SQLite database.
func New ¶
func New(ctx context.Context, filename string, newcipher func([]byte) (cipher.Block, error)) (*KeyStore, error)
New creates a new SQLite-backed keystore using the given file.
The newcipher function takes a key and returns a cipher for encrypting and decrypting. If newcipher is nil, it defaults to aes.NewCipher.
If the keystore is new (i.e., contains no keys), the version number of the keystore is set to 2. If the keystore is non-empty and was created before v1.5.0 of this module, its version will be 1. The version number controls whether the resulting encoded ids include a checksum. Version 1 ids are not compatible with version 2 ids.
The caller is responsible for closing the keystore with [Close] when it is no longer needed.
func NewFromDB ¶ added in v2.2.0
func NewFromDB(ctx context.Context, db *sql.DB, own bool, newcipher func([]byte) (cipher.Block, error)) (*KeyStore, error)
NewFromDB creates a new SQLite-backed keystore using the given database connection.
The newcipher function takes a key and returns a cipher for encrypting and decrypting. If newcipher is nil, it defaults to aes.NewCipher.
If the keystore is new (i.e., contains no keys), the version number of the keystore is set to 2. If the keystore is non-empty and was created before v1.5.0 of this module, its version will be 1. The version number controls whether the resulting encoded ids include a checksum. Version 1 ids are not compatible with version 2 ids.
If own is true, then [Close] will close the underlying database connection. Otherwise, closing the database connection is the caller's responsibility and should not be done until after a call to Close.
func NewSchema ¶ added in v2.3.0
func NewSchema(ctx context.Context, filename, migrationsTable string, newcipher func([]byte) (cipher.Block, error)) (*KeyStore, error)
NewSchema creates a new SQLite-backed keystore using the given file.
The newcipher function takes a key and returns a cipher for encrypting and decrypting. If newcipher is nil, it defaults to aes.NewCipher.
If migrationsTable is non-empty, it is used as the name of the table used to record applied schema migrations. When empty, the default goose table name is used ("goose_db_version"). Callers wishing to combine an encid schema in the same database as other goose-based migrations should set this to a non-empty value to avoid conflicts. Beware: Use a consistent value for migrationsTable! Changing the value of migrationsTable in a database where an encid schema already exists can lead to data loss.
If the keystore is new (i.e., contains no keys), the version number of the keystore is set to 2. If the keystore is non-empty and was created before v1.5.0 of this module, its version will be 1. The version number controls whether the resulting encoded ids include a checksum. Version 1 ids are not compatible with version 2 ids.
The caller is responsible for closing the keystore with [Close] when it is no longer needed.
func NewSchemaFromDB ¶ added in v2.3.0
func NewSchemaFromDB(ctx context.Context, db *sql.DB, migrationsTable string, own bool, newcipher func([]byte) (cipher.Block, error)) (*KeyStore, error)
NewSchemaFromDB creates a new SQLite-backed keystore using the given database connection.
The newcipher function takes a key and returns a cipher for encrypting and decrypting. If newcipher is nil, it defaults to aes.NewCipher.
If migrationsTable is non-empty, it is used as the name of the table used to record applied schema migrations. When empty, the default goose table name is used ("goose_db_version"). Callers wishing to combine an encid schema in the same database as other goose-based migrations should set this to a non-empty value to avoid conflicts. Beware: Use a consistent value for migrationsTable! Changing the value of migrationsTable in a database where an encid schema already exists can lead to data loss.
If the keystore is new (i.e., contains no keys), the version number of the keystore is set to 2. If the keystore is non-empty and was created before v1.5.0 of this module, its version will be 1. The version number controls whether the resulting encoded ids include a checksum. Version 1 ids are not compatible with version 2 ids.
If own is true, then [Close] will close the underlying database connection. Otherwise, closing the database connection is the caller's responsibility and should not be done until after a call to Close.
func (*KeyStore) Close ¶ added in v2.2.0
Close finalizes the KeyStore, releasing resources. The KeyStore must not be used after calling Close.
If the KeyStore "owns" the underlying database connection, (which is the case unless it was created via NewFromDB or NewSchemaFromDB with own == false), Close closes the underlying database connection, otherwise closing the database connection is the caller's responsibility and should not be done until after closing the KeyStore.