This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CRAND "crypto/rand" | |
// GenMQTTClientID generates a random client id for mqtt | |
func GenMQTTClientID(prefix string) (string, error) { | |
r, err := CRAND.Int(CRAND.Reader, new(big.Int).SetInt64(100000)) | |
if err != nil { | |
return "", fmt.Errorf("Failed to generate MQTT client ID: %v", err) | |
} | |
return prefix + r.String(), nil | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// isValidHex indicates if value is a proper hex strings that can be contained | |
// with the given number of bits | |
func isValidHex(value string, bits int) bool { | |
str := strings.ToLower(value) | |
precZeros := true | |
bitcount := 0 | |
for _, c := range str { | |
// Ensure the rune is a HEX character | |
if !strings.Contains("0123456789abcdef", string(c)) { | |
return false |
NewerOlder