MCPcopy Create free account
hub / github.com/coder/aibridge / MaskSecret

Function MaskSecret

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 {

Callers 4

TestMaskSecretFunction · 0.92
NewCredentialInfoFunction · 0.92
newMessagesServiceMethod · 0.92
writeRedactedHeadersMethod · 0.92

Calls 1

revealLengthFunction · 0.85

Tested by 1

TestMaskSecretFunction · 0.74