diff --git a/armor/armor_test.go b/armor/armor_test.go index 55ccb1c..bb51e48 100644 --- a/armor/armor_test.go +++ b/armor/armor_test.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build go1.18 -// +build go1.18 package armor_test diff --git a/cmd/age-inspect/inspect.go b/cmd/age-inspect/inspect.go index aa48b4f..976a78d 100644 --- a/cmd/age-inspect/inspect.go +++ b/cmd/age-inspect/inspect.go @@ -118,7 +118,7 @@ func main() { // l is a logger with no prefixes. var l = log.New(os.Stderr, "", 0) -func errorf(format string, v ...interface{}) { +func errorf(format string, v ...any) { l.Printf("age-inspect: error: "+format, v...) l.Printf("age-inspect: report unexpected or unhelpful errors at https://filippo.io/age/report") os.Exit(1) diff --git a/cmd/age-keygen/keygen.go b/cmd/age-keygen/keygen.go index 269b560..d2c0685 100644 --- a/cmd/age-keygen/keygen.go +++ b/cmd/age-keygen/keygen.go @@ -170,7 +170,7 @@ func convert(in io.Reader, out io.Writer) { } } -func errorf(format string, v ...interface{}) { +func errorf(format string, v ...any) { log.Printf("age-keygen: error: "+format, v...) log.Fatalf("age-keygen: report unexpected or unhelpful errors at https://filippo.io/age/report") } diff --git a/cmd/age/age.go b/cmd/age/age.go index 41b41b0..621ba5a 100644 --- a/cmd/age/age.go +++ b/cmd/age/age.go @@ -156,11 +156,8 @@ func main() { safe := true unsafeShell := regexp.MustCompile(`[^\w@%+=:,./-]`) - for _, arg := range os.Args { - if unsafeShell.MatchString(arg) { - safe = false - break - } + if slices.ContainsFunc(os.Args, unsafeShell.MatchString) { + safe = false } if safe { i := len(os.Args) - flag.NArg() @@ -316,7 +313,7 @@ func passphrasePromptForEncryption() (string, error) { p := string(pass) if p == "" { var words []string - for i := 0; i < 10; i++ { + for range 10 { words = append(words, randomWord()) } p = strings.Join(words, "-") diff --git a/cmd/age/tui.go b/cmd/age/tui.go index 4876367..d94d7d2 100644 --- a/cmd/age/tui.go +++ b/cmd/age/tui.go @@ -30,17 +30,17 @@ import ( // l is a logger with no prefixes. var l = log.New(os.Stderr, "", 0) -func printf(format string, v ...interface{}) { +func printf(format string, v ...any) { l.Printf("age: "+format, v...) } -func errorf(format string, v ...interface{}) { +func errorf(format string, v ...any) { l.Printf("age: error: "+format, v...) l.Printf("age: report unexpected or unhelpful errors at https://filippo.io/age/report") os.Exit(1) } -func warningf(format string, v ...interface{}) { +func warningf(format string, v ...any) { l.Printf("age: warning: "+format, v...) } @@ -53,7 +53,7 @@ func errorWithHint(error string, hints ...string) { os.Exit(1) } -func printfToTerminal(format string, v ...interface{}) error { +func printfToTerminal(format string, v ...any) error { return term.WithTerminal(func(_, out *os.File) error { _, err := fmt.Fprintf(out, "age: "+format+"\n", v...) return err diff --git a/extra/age-plugin-pq/plugin-pq.go b/extra/age-plugin-pq/plugin-pq.go index 0773e62..62d8837 100644 --- a/extra/age-plugin-pq/plugin-pq.go +++ b/extra/age-plugin-pq/plugin-pq.go @@ -138,7 +138,7 @@ func convert(in io.Reader, out io.Writer) { } } -func errorf(format string, v ...interface{}) { +func errorf(format string, v ...any) { log.Printf("age-plugin-pq: error: "+format, v...) log.Fatalf("age-plugin-pq: report unexpected or unhelpful errors at https://filippo.io/age/report") } diff --git a/internal/bech32/bech32.go b/internal/bech32/bech32.go index 6f8a48c..a5d8330 100644 --- a/internal/bech32/bech32.go +++ b/internal/bech32/bech32.go @@ -37,7 +37,7 @@ func polymod(values []byte) uint32 { top := chk >> 25 chk = (chk & 0x1ffffff) << 5 chk = chk ^ uint32(v) - for i := 0; i < 5; i++ { + for i := range 5 { bit := top >> i & 1 if bit == 1 { chk ^= generator[i] diff --git a/internal/format/format.go b/internal/format/format.go index 36eaad0..cc788c3 100644 --- a/internal/format/format.go +++ b/internal/format/format.go @@ -77,10 +77,7 @@ func (w *WrappedBase64Encoder) writeWrapped(p []byte) (int, error) { panic("age: internal error: non-empty WrappedBase64Encoder.buf") } for len(p) > 0 { - toWrite := ColumnsPerLine - (w.written % ColumnsPerLine) - if toWrite > len(p) { - toWrite = len(p) - } + toWrite := min(ColumnsPerLine-(w.written%ColumnsPerLine), len(p)) n, _ := w.buf.Write(p[:toWrite]) w.written += n p = p[n:] @@ -228,7 +225,7 @@ func (e *ParseError) Unwrap() error { return e.err } -func errorf(format string, a ...interface{}) error { +func errorf(format string, a ...any) error { return &ParseError{fmt.Errorf(format, a...)} } diff --git a/internal/format/format_test.go b/internal/format/format_test.go index de96abc..dca10e6 100644 --- a/internal/format/format_test.go +++ b/internal/format/format_test.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build go1.18 -// +build go1.18 package format_test diff --git a/plugin/plugin.go b/plugin/plugin.go index d0ca76c..ad833d9 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -566,13 +566,13 @@ func (p *Plugin) Confirm(prompt, yes, no string) (choseYes bool, err error) { // fatalInteractf prints the error to stderr and sets the broken flag, so the // Wrap/Unwrap caller can exit with an error. -func (p *Plugin) fatalInteractf(format string, args ...interface{}) error { +func (p *Plugin) fatalInteractf(format string, args ...any) error { p.broken = true fmt.Fprintf(p.stderr, format, args...) return fmt.Errorf(format, args...) } -func (p *Plugin) fatalf(format string, args ...interface{}) int { +func (p *Plugin) fatalf(format string, args ...any) int { fmt.Fprintf(p.stderr, format, args...) return 1 } diff --git a/plugin/tui.go b/plugin/tui.go index 2266385..5a4533a 100644 --- a/plugin/tui.go +++ b/plugin/tui.go @@ -13,7 +13,7 @@ import ( // The terminal is reached directly through /dev/tty or CONIN$/CONOUT$, // bypassing standard input and output, so this UI can be used even when // standard input or output are redirected. -func NewTerminalUI(printf, warningf func(format string, v ...interface{})) *ClientUI { +func NewTerminalUI(printf, warningf func(format string, v ...any)) *ClientUI { return &ClientUI{ DisplayMessage: func(name, message string) error { printf("%s plugin: %s", name, message) diff --git a/testkit_test.go b/testkit_test.go index 5e4f271..292350e 100644 --- a/testkit_test.go +++ b/testkit_test.go @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. //go:build go1.18 -// +build go1.18 package age_test