generateTokenWithFormat creates a token that matches the format of the original value.
(seed []byte, originalValue string)
| 259 | |
| 260 | // generateTokenWithFormat creates a token that matches the format of the original value. |
| 261 | func generateTokenWithFormat(seed []byte, originalValue string) (string, error) { |
| 262 | runes := []rune(originalValue) |
| 263 | result := make([]rune, len(runes)) |
| 264 | |
| 265 | // Use the seed to generate random runes that preserve the format |
| 266 | for i, char := range runes { |
| 267 | seedByte := seed[i%len(seed)] |
| 268 | |
| 269 | if 'A' <= char && char <= 'Z' { |
| 270 | // Uppercase letter |
| 271 | result[i] = 'A' + rune(seedByte%26) |
| 272 | } else if 'a' <= char && char <= 'z' { |
| 273 | // Lowercase letter |
| 274 | result[i] = 'a' + rune(seedByte%26) |
| 275 | } else if '0' <= char && char <= '9' { |
| 276 | // Digit |
| 277 | result[i] = '0' + rune(seedByte%10) |
| 278 | } else { |
| 279 | // Preserve special characters (including UTF-8 characters) |
| 280 | result[i] = char |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | return string(result), nil |
| 285 | } |
no outgoing calls