-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WithMinLenPasswordFile pemutil option #711
Conversation
pemutil/pem.go
Outdated
re := regexp.MustCompile(`\s+`) | ||
trimmed := re.ReplaceAllString(string(b), "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method utils.ReadPasswordFromFile already returns the password properly trimmed. Don't do anything else.
pemutil/pem.go
Outdated
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if condition can be written in one line but lgtm as it is.
Co-authored-by: Mariano Cano <[email protected]>
No description provided.