WIP: cheap scrypt in tests
check / check (push) Failing after 2s

This commit is contained in:
sneak committed 2026-10-05 23:50:49 +00:00
1 parent af9ac6d979
commit 9fec3d7098
6 files changed
+40 -5

No files matched your search

+14
View File
@@ -28,6 +28,16 @@ var (
// terminal to read the mnemonic from, reading it failed, or it was empty.
var ErrMnemonicNotRead = errors.New("failed to read mnemonic")
// ScryptWorkFactor, when not zero, replaces age's scrypt work factor, 18, in
// EncryptWithPassphrase. It is log2 of the number of scrypt iterations. age's
// costs about a second and 256 MiB per passphrase, on purpose, as it does each
// guess at one. Only tests set it, lower, before any test runs, so that the
// passphrase unlockers they create cost nothing; the program leaves it zero.
// Decryption reads the work factor from the encrypted data.
//
//nolint:gochecknoglobals // set by the tests of the packages that use this one
var ScryptWorkFactor int
// EncryptToRecipient encrypts data to a recipient using age
// The data parameter should be a LockedBuffer for secure memory handling
func EncryptToRecipient(
@@ -142,6 +152,10 @@ func EncryptWithPassphrase(
return nil, fmt.Errorf("failed to create scrypt recipient: %w", err)
}
if ScryptWorkFactor != 0 {
recipient.SetWorkFactor(ScryptWorkFactor)
}
return EncryptToRecipient(data, recipient)
}
+8
View File
@@ -25,6 +25,14 @@ var (
errNotImplementedInMock = errors.New("not implemented in mock")
)
// TestMain makes passphrase encryption in the tests cheap; see
// ScryptWorkFactor.
func TestMain(m *testing.M) {
ScryptWorkFactor = 1
os.Exit(m.Run())
}
// MockVault is a test implementation of the VaultInterface
type MockVault struct {
name string