diff --git a/api/auth.go b/api/auth.go index 5882f87..5b9c2fd 100644 --- a/api/auth.go +++ b/api/auth.go @@ -146,10 +146,7 @@ func (c *Client) Login(ctx context.Context) error { } // Validate that this Publickey that the Server gave us actually Matches our Privatekey - randomString, err := randStringBytesRmndr(50) - if err != nil { - return fmt.Errorf("Generating Random String as PublicKey Validation Message: %w", err) - } + randomString := randStringBytesRmndr(50) armor, err := helper.EncryptMessageArmored(user.GPGKey.ArmoredKey, randomString) if err != nil { return fmt.Errorf("Encryping PublicKey Validation Message: %w", err) diff --git a/api/misc.go b/api/misc.go index eeebdfd..9990219 100644 --- a/api/misc.go +++ b/api/misc.go @@ -1,25 +1,15 @@ package api import ( - "crypto/rand" - "math/big" + "math/rand" ) -func randStringBytesRmndr(length int) (string, error) { - result := "" - for { - if len(result) >= length { - return result, nil - } - num, err := rand.Int(rand.Reader, big.NewInt(int64(127))) - if err != nil { - return "", err - } - n := num.Int64() - // Make sure that the number/byte/letter is inside - // the range of printable ASCII characters (excluding space and DEL) - if n > 32 && n < 127 { - result += string(n) - } +const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + +func randStringBytesRmndr(length int) string { + b := make([]byte, length) + for i := range b { + b[i] = letterBytes[rand.Intn(len(letterBytes))] } + return string(b) }