store

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package store provides encrypted storage for OmniVault.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes generates cryptographically secure random bytes.

Types

type Argon2Params

type Argon2Params struct {
	Time    uint32 `json:"time"`
	Memory  uint32 `json:"memory"`
	Threads uint8  `json:"threads"`
	KeyLen  uint32 `json:"key_len"`
}

Argon2Params contains parameters for Argon2id key derivation.

func DefaultArgon2Params

func DefaultArgon2Params() Argon2Params

DefaultArgon2Params returns secure default parameters for Argon2id. These are based on OWASP recommendations for password hashing.

type Crypto

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

Crypto handles encryption and key derivation for the vault.

func NewCrypto

func NewCrypto(salt []byte, params Argon2Params) (*Crypto, error)

NewCrypto creates a new Crypto instance with the given salt. If salt is nil, a new random salt will be generated.

func (*Crypto) CreateVerificationBlob

func (c *Crypto) CreateVerificationBlob() (string, error)

CreateVerificationBlob creates an encrypted blob that can be used to verify passwords.

func (*Crypto) Decrypt

func (c *Crypto) Decrypt(encoded string) ([]byte, error)

Decrypt decrypts base64-encoded ciphertext using AES-256-GCM.

func (*Crypto) DecryptString

func (c *Crypto) DecryptString(encoded string) (string, error)

DecryptString decrypts base64-encoded ciphertext and returns a string.

func (*Crypto) DeriveKey

func (c *Crypto) DeriveKey(password string) []byte

DeriveKey derives an encryption key from a password using Argon2id.

func (*Crypto) Encrypt

func (c *Crypto) Encrypt(plaintext []byte) (string, error)

Encrypt encrypts plaintext using AES-256-GCM. Returns base64-encoded ciphertext (nonce + ciphertext + tag).

func (*Crypto) EncryptString

func (c *Crypto) EncryptString(plaintext string) (string, error)

EncryptString encrypts a string and returns base64-encoded ciphertext.

func (*Crypto) IsUnlocked

func (c *Crypto) IsUnlocked() bool

IsUnlocked returns true if the vault is unlocked.

func (*Crypto) Lock

func (c *Crypto) Lock()

Lock clears the derived key from memory.

func (*Crypto) Params

func (c *Crypto) Params() Argon2Params

Params returns the Argon2 parameters.

func (*Crypto) Salt

func (c *Crypto) Salt() []byte

Salt returns the salt used for key derivation.

func (*Crypto) Unlock

func (c *Crypto) Unlock(password string)

Unlock derives the key from the password and stores it for encryption/decryption.

func (*Crypto) VerifyPassword

func (c *Crypto) VerifyPassword(password string, verificationBlob string) bool

VerifyPassword checks if the given password matches by attempting to decrypt a verification blob. Returns true if password is correct.

type EncryptedStore

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

EncryptedStore implements vault.Vault with encrypted file storage.

func NewEncryptedStore

func NewEncryptedStore(vaultPath, metaPath string) *EncryptedStore

NewEncryptedStore creates a new encrypted store.

func (*EncryptedStore) Capabilities

func (s *EncryptedStore) Capabilities() vault.Capabilities

Capabilities returns the provider capabilities.

func (*EncryptedStore) ChangePassword

func (s *EncryptedStore) ChangePassword(oldPassword, newPassword string) error

ChangePassword changes the master password.

func (*EncryptedStore) Close

func (s *EncryptedStore) Close() error

Close releases resources and locks the vault.

func (*EncryptedStore) Delete

func (s *EncryptedStore) Delete(ctx context.Context, path string) error

Delete removes a secret from the vault.

func (*EncryptedStore) Exists

func (s *EncryptedStore) Exists(ctx context.Context, path string) (bool, error)

Exists checks if a secret exists at the given path.

func (*EncryptedStore) Get

func (s *EncryptedStore) Get(ctx context.Context, path string) (*vault.Secret, error)

Get retrieves a secret from the vault.

func (*EncryptedStore) Initialize

func (s *EncryptedStore) Initialize(password string) error

Initialize creates a new vault with the given master password.

func (*EncryptedStore) IsLocked

func (s *EncryptedStore) IsLocked() bool

IsLocked returns true if the vault is locked.

func (*EncryptedStore) List

func (s *EncryptedStore) List(ctx context.Context, prefix string) ([]string, error)

List returns all secret paths matching the given prefix.

func (*EncryptedStore) Lock

func (s *EncryptedStore) Lock() error

Lock locks the vault.

func (*EncryptedStore) Name

func (s *EncryptedStore) Name() string

Name returns the provider name.

func (*EncryptedStore) SecretCount

func (s *EncryptedStore) SecretCount() int

SecretCount returns the number of secrets in the vault.

func (*EncryptedStore) Set

func (s *EncryptedStore) Set(ctx context.Context, path string, secret *vault.Secret) error

Set stores a secret in the vault.

func (*EncryptedStore) Unlock

func (s *EncryptedStore) Unlock(password string) error

Unlock unlocks the vault with the master password.

func (*EncryptedStore) UnlockTime

func (s *EncryptedStore) UnlockTime() time.Time

UnlockTime returns when the vault was unlocked.

func (*EncryptedStore) VaultExists

func (s *EncryptedStore) VaultExists() bool

VaultExists returns true if the vault exists on disk.

type VaultData

type VaultData struct {
	Secrets map[string]string `json:"secrets"` // path -> encrypted secret JSON
}

VaultData contains encrypted vault data.

type VaultMeta

type VaultMeta struct {
	Version      int          `json:"version"`
	CreatedAt    time.Time    `json:"created_at"`
	Salt         []byte       `json:"salt"`
	Argon2Params Argon2Params `json:"argon2_params"`
	Verification string       `json:"verification"` // Encrypted verification blob
}

VaultMeta contains unencrypted vault metadata.

Jump to

Keyboard shortcuts

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