From dddb3a572bdc6f614ceaaa040f38a6510e8260e7 Mon Sep 17 00:00:00 2001 From: Matt Bonnell Date: Sun, 26 Jul 2020 22:58:14 -0400 Subject: [PATCH] Reduce code duplication --- cmd/jwt/app.go | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/cmd/jwt/app.go b/cmd/jwt/app.go index cdf25008..0a3e5314 100644 --- a/cmd/jwt/app.go +++ b/cmd/jwt/app.go @@ -210,25 +210,16 @@ func signToken() error { token.Header[k] = v } } - - if isEs() { - if k, ok := key.([]byte); !ok { - return fmt.Errorf("Couldn't convert key data to key") - } else { - key, err = jwt.ParseECPrivateKeyFromPEM(k) - if err != nil { - return err - } - } - } else if isRs() { - if k, ok := key.([]byte); !ok { + + if k, ok := key.([]byte); !ok { return fmt.Errorf("Couldn't convert key data to key") - } else { - key, err = jwt.ParseRSAPrivateKeyFromPEM(k) - if err != nil { - return err - } - } + } else if isEs() { + key, err = jwt.ParseECPrivateKeyFromPEM(k) + } else if isRS() { + key, err = jwt.ParseRSAPrivateKeyFromPEM(k) + } + if err != nil { + return err } if out, err := token.SignedString(key); err == nil {