♻️ cidr: build keys through net.IPNet instead of hand-masking bytes

CIDRKeys masked the address byte by byte and formatted the result with
string concatenation, while SetCIDR/DeleteCIDR format their keys with
net.IPNet.String() via NormalizeCIDR. The two agreed only by coincidence:
any divergence in formatting silently stops every range decision from
matching, with no test covering the invariant.

Mask with net.IP.Mask and format through net.IPNet.String() so both sides
go through the same formatter. Output is byte for byte identical to the
previous implementation (checked against a golden dump of both IPv4 and
IPv6 keys, including ::ffff: forms).

Dropping the inner byte loops also removes the only intrange violation in
the tree, so the linter exclusion added for them is no longer needed, and
the redundant import alias on pkg/ip goes away with it.
This commit is contained in:
mhx
2026-08-03 13:39:53 +02:00
parent 1ba556e918
commit 1b1247823c
3 changed files with 26 additions and 27 deletions
-1
View File
@@ -75,7 +75,6 @@ linters:
- mnd
- exportloopref
- contextcheck
- intrange # not supported by yaegi
issues:
exclude-use-default: false
max-same-issues: 0