MCPcopy Index your code
hub / github.com/coder/coder / MaskSecret

Function MaskSecret

aibridge/utils/mask.go:6–21  ·  view source on GitHub ↗

MaskSecret masks the middle of a secret string, revealing a small prefix and suffix for identification. The number of characters revealed scales with string length.

(s string)

Source from the content-addressed store, hash-verified

4// prefix and suffix for identification. The number of characters
5// revealed scales with string length.
6func MaskSecret(s string) string {
7 if s == "" {
8 return ""
9 }
10
11 runes := []rune(s)
12 reveal := revealLength(len(runes))
13
14 if len(runes) <= reveal*2 {
15 return "..."
16 }
17
18 prefix := string(runes[:reveal])
19 suffix := string(runes[len(runes)-reveal:])
20 return prefix + "..." + suffix
21}
22
23// revealLength returns the number of runes to show at each end.
24func revealLength(n int) int {

Calls 1

revealLengthFunction · 0.85