1 parent
af9ac6d979
commit
9fec3d7098
6 files changed
+40
-5
No files matched your search
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user