From b34009912a238a39ffb33936f0d096b70848c4e3 Mon Sep 17 00:00:00 2001 From: Mehdi Teymorian Date: Tue, 6 Jun 2023 14:18:11 +0330 Subject: [PATCH] feat: make key output easier for copying --- internal/cmd/key/ecdsa.go | 9 +++++---- internal/cmd/key/hmac.go | 12 +++++++++--- internal/cmd/key/rsa.go | 9 +++++---- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/internal/cmd/key/ecdsa.go b/internal/cmd/key/ecdsa.go index ed5b522..bbf3692 100644 --- a/internal/cmd/key/ecdsa.go +++ b/internal/cmd/key/ecdsa.go @@ -1,6 +1,7 @@ package key import ( + "fmt" "github.com/AlecAivazis/survey/v2" "github.com/mehditeymorian/jwt/internal/cmd" "github.com/mehditeymorian/jwt/internal/config" @@ -39,10 +40,10 @@ func ecdsa(c *cobra.Command, _ []string) { publicKey, privateKey := keyGenerator.GenerateEcdsaKeys(ellipticCurve) - publicBox := pterm.DefaultBox.WithTitle("Public Key").Sprint(publicKey) - privateBox := pterm.DefaultBox.WithTitle("Private Key").Sprint(privateKey) - render, _ := pterm.DefaultPanel.WithPanels(pterm.Panels{{{Data: publicBox}, {Data: privateBox}}}).Srender() - pterm.Println(render) + pterm.Info.Println("Public Key") + fmt.Println(publicKey) + pterm.Info.Println("Private Key") + fmt.Println(privateKey) if saveFile { SaveKey("/public.pem", []byte(publicKey)) diff --git a/internal/cmd/key/hmac.go b/internal/cmd/key/hmac.go index 53c28c8..8cf6151 100644 --- a/internal/cmd/key/hmac.go +++ b/internal/cmd/key/hmac.go @@ -1,6 +1,7 @@ package key import ( + "fmt" "strconv" "github.com/AlecAivazis/survey/v2" @@ -39,12 +40,17 @@ func hmac(c *cobra.Command, _ []string) { } cfg.PrintMode() - pterm.Info.Println("size: " + pterm.Blue(size)) - pterm.Info.Println("base64Encoded: " + pterm.Blue(base64Encoded)) + pterm.Info.Println("Size: " + pterm.Blue(size)) + pterm.Info.Println("Base64 Encoded: " + pterm.Blue(base64Encoded)) hmacKey := keyGenerator.GenerateHmacKey(size, base64Encoded) - pterm.Info.Println("key: " + pterm.Blue(string(hmacKey))) + pterm.Info.Println("Key:") + if base64Encoded { + fmt.Println(string(hmacKey)) + } else { + fmt.Println(hmacKey) + } if saveFile { SaveKey("/key.txt", hmacKey) diff --git a/internal/cmd/key/rsa.go b/internal/cmd/key/rsa.go index dd5a581..46651bc 100644 --- a/internal/cmd/key/rsa.go +++ b/internal/cmd/key/rsa.go @@ -1,6 +1,7 @@ package key import ( + "fmt" "strconv" "github.com/AlecAivazis/survey/v2" @@ -41,10 +42,10 @@ func rsa(c *cobra.Command, _ []string) { publicKey, privateKey := keyGenerator.GenerateRsaKeys(bits) - publicBox := pterm.DefaultBox.WithTitle("Public Key").Sprint(publicKey) - privateBox := pterm.DefaultBox.WithTitle("Private Key").Sprint(privateKey) - render, _ := pterm.DefaultPanel.WithPanels(pterm.Panels{{{Data: publicBox}, {Data: privateBox}}}).Srender() - pterm.Println(render) + pterm.Info.Println("Public Key") + fmt.Println(publicKey) + pterm.Info.Println("Private Key") + fmt.Println(privateKey) if saveFile { SaveKey("/public.pem", []byte(publicKey))