mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Add Domain Name Matcher
Design difference from original vision: Skipped FQDN step to make it more generalized https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/28651#note_2787394
This commit is contained in:
parent
5578b4dd76
commit
38f0e00e5d
2 changed files with 81 additions and 0 deletions
26
common/namematcher/matcher.go
Normal file
26
common/namematcher/matcher.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package namematcher
|
||||
|
||||
import "strings"
|
||||
|
||||
func NewNameMatcher(rule string) NameMatcher {
|
||||
return NameMatcher{suffix: strings.TrimPrefix(rule, "^"), exact: strings.HasPrefix(rule, "^")}
|
||||
}
|
||||
|
||||
type NameMatcher struct {
|
||||
exact bool
|
||||
suffix string
|
||||
}
|
||||
|
||||
func (m *NameMatcher) IsSupersetOf(matcher NameMatcher) bool {
|
||||
if m.exact {
|
||||
return matcher.exact && m.suffix == matcher.suffix
|
||||
}
|
||||
return strings.HasSuffix(matcher.suffix, m.suffix)
|
||||
}
|
||||
|
||||
func (m *NameMatcher) IsMember(s string) bool {
|
||||
if m.exact {
|
||||
return s == m.suffix
|
||||
}
|
||||
return strings.HasSuffix(s, m.suffix)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue