storage

package
v1.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const SaltFile = "SALT"

SaltFile is the standard filename to store an encrypted config's SALT under beside it

Variables

This section is empty.

Functions

func CreateKey

func CreateKey(password string, salt []byte) [32]byte

CreateKey derives a key from a password and salt

func CreateKeySalt

func CreateKeySalt(password string) ([32]byte, [128]byte, error)

CreateKeySalt derives a key and salt from a password: returns key, salt, err

func DecryptFile

func DecryptFile(ciphertext []byte, key [32]byte) ([]byte, error)

DecryptFile decrypts the passed ciphertext with the supplied key.

func EncryptFileData

func EncryptFileData(data []byte, key [32]byte) ([]byte, error)

EncryptFileData encrypts the data with the supplied key

func GenerateRandomID

func GenerateRandomID() string

GenerateRandomID generates a random 16 byte hex id code

func InitV1Directory

func InitV1Directory(directory, password string) ([32]byte, [128]byte, error)

InitV1Directory generates a key and salt from a password, writes a SALT and VERSION file and returns the key and salt

func ReadEncryptedFile

func ReadEncryptedFile(directory, filename string, key [32]byte) ([]byte, error)

ReadEncryptedFile reads data from an encrypted file in directory with key

Types

type FileStore

type FileStore interface {
	Write([]byte) error
	Read() ([]byte, error)
	Delete()
	ChangeKey(newkey [32]byte)
}

FileStore is a primitive around storing encrypted files

func NewFileStore

func NewFileStore(directory string, filename string, key [32]byte) FileStore

NewFileStore instantiates a fileStore given a filename and a password

type MessageStoreInterface

type MessageStoreInterface interface {
	AddMessage(groups.EncryptedGroupMessage)
	FetchMessages() []*groups.EncryptedGroupMessage
	MessagesCount() int
	FetchMessagesFrom(signature []byte) []*groups.EncryptedGroupMessage
	SetMessageCap(newcap int)
	Close()
}

MessageStoreInterface defines an interface to interact with a store of cwtch messages.

type SqliteMessageStore

type SqliteMessageStore struct {
	// contains filtered or unexported fields
}

SqliteMessageStore is an sqlite3 backed message store

func InitializeSqliteMessageStore

func InitializeSqliteMessageStore(dbfile string, messageCap int, incMessageCounterFn func()) (*SqliteMessageStore, error)

InitializeSqliteMessageStore creates a database `dbfile` with the necessary tables (if it doesn't already exist) and returns an open database

func (*SqliteMessageStore) AddMessage

func (s *SqliteMessageStore) AddMessage(message groups.EncryptedGroupMessage)

AddMessage implements the MessageStoreInterface AddMessage for sqlite message store

func (*SqliteMessageStore) Close

func (s *SqliteMessageStore) Close()

Close closes the underlying sqlite3 database to further changes

func (*SqliteMessageStore) FetchMessages

func (s *SqliteMessageStore) FetchMessages() []*groups.EncryptedGroupMessage

FetchMessages implements the MessageStoreInterface FetchMessages for sqlite message store

func (*SqliteMessageStore) FetchMessagesFrom

func (s *SqliteMessageStore) FetchMessagesFrom(signature []byte) []*groups.EncryptedGroupMessage

FetchMessagesFrom implements the MessageStoreInterface FetchMessagesFrom for sqlite message store

func (*SqliteMessageStore) MessagesCount

func (s *SqliteMessageStore) MessagesCount() int

func (*SqliteMessageStore) SetMessageCap

func (s *SqliteMessageStore) SetMessageCap(newcap int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL