MCPcopy Create free account
hub / github.com/astercloud/aster / RedactWithMasking

Method RedactWithMasking

pkg/security/redaction.go:80–99  ·  view source on GitHub ↗

RedactWithMasking 使用掩码脱敏

(text string, maskLength int)

Source from the content-addressed store, hash-verified

78
79// RedactWithMasking 使用掩码脱敏
80func (r *PIIRedactor) RedactWithMasking(text string, maskLength int) string {
81 if r.detector == nil || text == "" {
82 return text
83 }
84
85 ctx := context.Background()
86 matches, err := r.detector.Detect(ctx, text)
87 if err != nil || len(matches) == 0 {
88 return text
89 }
90
91 // 按位置倒序排列
92 for i := len(matches) - 1; i >= 0; i-- {
93 match := matches[i]
94 maskedValue := r.maskValue(match.Value, maskLength)
95 text = text[:match.Start] + maskedValue + text[match.End:]
96 }
97
98 return text
99}
100
101// maskValue 创建掩码值
102func (r *PIIRedactor) maskValue(value string, maskLength int) string {

Callers

nothing calls this directly

Calls 2

maskValueMethod · 0.95
DetectMethod · 0.65

Tested by

no test coverage detected