MCPcopy Index your code
hub / github.com/tinyhttp/tinyhttp / trustSingle

Function trustSingle

packages/proxy-addr/src/index.ts:178–194  ·  view source on GitHub ↗

* Compile trust function for single subnet. * * @param subnet

(subnet: IPv4 | IPv6)

Source from the content-addressed store, hash-verified

176 * @param subnet
177 */
178function trustSingle(subnet: IPv4 | IPv6) {
179 const subnetip = subnet[0]
180 const subnetkind = subnetip.kind()
181 const subnetisipv4 = subnetkind === 'ipv4'
182 const subnetrange = subnet[1]
183 return function trust(addr: string) {
184 if (!isip(addr)) return false
185 let ip = parseip(addr)
186 const kind = ip.kind()
187 if (kind !== subnetkind) {
188 if (subnetisipv4 && !(ip as IPv6).isIPv4MappedAddress()) return false
189
190 ip = subnetisipv4 ? (ip as IPv6).toIPv4Address() : (ip as IPv4).toIPv4MappedAddress()
191 }
192 return (ip as IPv6).match(subnetip, subnetrange)
193 }
194}
195
196export { alladdrs as all }
197export { compile }

Callers 1

compileTrustFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected