Add WithMinLenPasswordFile pemutil option#711
Conversation
| re := regexp.MustCompile(`\s+`) | ||
| trimmed := re.ReplaceAllString(string(b), "") |
There was a problem hiding this comment.
The method utils.ReadPasswordFromFile already returns the password properly trimmed. Don't do anything else.
| // WithMinLenPasswordFile is a method that adds the password in a file to the context. | ||
| // If the password does not meet the minimum length requirement an error is returned. | ||
| // If minimum length input is <=0 then the requirement is ignored. | ||
| func WithMinLenPasswordFile(filename string, minlen int) Options { |
There was a problem hiding this comment.
Perhaps we want to pass variadic options to WithPasswordFile(filename) for example WithPasswordFile(filename, ValidateMinLength(10)) you could do crazy things like
WithPasswordFile(filename, func(pass []byte) error {
if bytes.Contains(pass, []byte{'a'}) {
return errors.New("password cannot contain the letter `a`")
}
return nil
})There was a problem hiding this comment.
I'm not sure this is a good idea. It's not clear if the variadic options should be applied to the file or to the resulting password. For example an option that validated the ownership on the file would be applied before the password was read. Some of the options may need to be applied before the password is read (on the file), and some after.
maraino
left a comment
There was a problem hiding this comment.
The if condition can be written in one line but lgtm as it is.
Co-authored-by: Mariano Cano <[email protected]>
No description provided.