// SPDX-FileCopyrightText: 2022-2023 The go-mail Authors // // SPDX-License-Identifier: MIT package mail import ( "crypto/rand" "encoding/binary" "strings" ) // Range of characters for the secure string generation const cr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" // Bitmask sizes for the string generators (based on 93 chars total) const ( letterIdxBits = 7 // 7 bits to represent a letter index letterIdxMask = 1<= 0; { if rest == 0 { _, err = rand.Read(randPool) if err != nil { return randString.String(), err } char, rest = binary.BigEndian.Uint64(randPool), letterIdxMax } if i := int(char & letterIdxMask); i < charRangeLength { randString.WriteByte(cr[i]) idx-- } char >>= letterIdxBits rest-- } return randString.String(), nil }