Skip to content

Conversation

@dopey
Copy link
Contributor

@dopey dopey commented Feb 26, 2025

No description provided.

pemutil/pem.go Outdated
Comment on lines 179 to 180
re := regexp.MustCompile(`\s+`)
trimmed := re.ReplaceAllString(string(b), "")
Copy link
Contributor

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 {
Copy link
Contributor

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
})

Copy link
Contributor Author

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.

@dopey dopey requested a review from maraino February 27, 2025 07:32
maraino
maraino previously approved these changes Feb 27, 2025
Copy link
Contributor

@maraino maraino left a 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 <mariano.cano@gmail.com>
@dopey dopey merged commit 84f676b into master Feb 27, 2025
10 of 12 checks passed
@dopey dopey deleted the max/WithMinLenPasswordFile branch February 27, 2025 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants