Skip to content

Allow derivePassword counter to accept any integer type - #486

Open
bejaratommy wants to merge 1 commit into
Masterminds:masterfrom
bejaratommy:fix-derive-password-counter-type
Open

bejaratommy wants to merge 1 commit into
Masterminds:masterfrom
bejaratommy:fix-derive-password-counter-type

Conversation

@bejaratommy

Copy link
Copy Markdown

Summary

derivePassword's counter argument was typed as uint32. Go's text/template does reflection-based argument matching, so calling derivePassword with an int — such as the loop index produced by Helm's range $i, $v := ... — fails at template execution time with a type mismatch error. There was no ergonomic way to derive multiple passwords in a loop.

This changes counter to accept interface{} and coerces it internally with cast.ToUint32, mirroring the existing toInt/toInt64 pattern in numeric.go (the github.com/spf13/cast dependency is already used elsewhere in this repo).

Fixes #108

Changes

  • crypto.go: derivePassword counter param changed from uint32 to interface{}, coerced via cast.ToUint32.
  • crypto_test.go: added TestDerivePasswordCounterTypes, a regression test covering a literal int, a template variable, and a range-produced index, all asserted to produce the same output as the existing literal-uint case.
  • docs/crypto.md: documented that the counter argument accepts any integer type.

Testing

  • go build ./...
  • go test ./... -run TestDerivePassword -v — passes
  • Full go test ./... — one pre-existing, unrelated failure (TestRound in numeric_test.go, a floating-point rounding assertion) reproduces identically on master before this change; not touched by this PR.
Previously derivePassword required its counter argument to be a
uint32, which meant it could not be called with the int index
produced by a range loop (e.g. in Helm templates) without an
explicit, awkward conversion. The counter is now accepted as
interface{} and coerced with cast.ToUint32, matching the pattern
already used by toInt/toInt64 in numeric.go.

Fixes Masterminds#108

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant