mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 11:13:33 +01:00
- Bump Go from 1.19 to 1.26 and update all dependencies - Rewrite CI workflow with matrix strategy (Linux, macOS, Windows) - Update GitHub Actions to current versions (checkout@v4, setup-go@v5) - Update CodeQL actions from v1 to v3 - Fix cross-platform bug in mock/path.go (path.Join -> filepath.Join) - Clean up dependabot config (weekly schedule, remove stale ignore) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
27 lines
846 B
Go
27 lines
846 B
Go
package s2k
|
|
|
|
// Cache stores keys derived with s2k functions from one passphrase
|
|
// to avoid recomputation if multiple items are encrypted with
|
|
// the same parameters.
|
|
type Cache map[Params][]byte
|
|
|
|
// GetOrComputeDerivedKey tries to retrieve the key
|
|
// for the given s2k parameters from the cache.
|
|
// If there is no hit, it derives the key with the s2k function from the passphrase,
|
|
// updates the cache, and returns the key.
|
|
func (c *Cache) GetOrComputeDerivedKey(passphrase []byte, params *Params, expectedKeySize int) ([]byte, error) {
|
|
key, found := (*c)[*params]
|
|
if !found || len(key) != expectedKeySize {
|
|
var err error
|
|
derivedKey := make([]byte, expectedKeySize)
|
|
s2k, err := params.Function()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
s2k(derivedKey, passphrase)
|
|
(*c)[*params] = key
|
|
return derivedKey, nil
|
|
}
|
|
return key, nil
|
|
}
|