@ac-kit/net-address 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/LICENSE +28 -0
- package/README.md +65 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +10 -0
- package/dist/errors.js.map +1 -0
- package/dist/eui/constants.d.ts +7 -0
- package/dist/eui/constants.d.ts.map +1 -0
- package/dist/eui/constants.js +7 -0
- package/dist/eui/constants.js.map +1 -0
- package/dist/eui/eui-bits.d.ts +99 -0
- package/dist/eui/eui-bits.d.ts.map +1 -0
- package/dist/eui/eui-bits.js +138 -0
- package/dist/eui/eui-bits.js.map +1 -0
- package/dist/eui/eui-convert.d.ts +37 -0
- package/dist/eui/eui-convert.d.ts.map +1 -0
- package/dist/eui/eui-convert.js +76 -0
- package/dist/eui/eui-convert.js.map +1 -0
- package/dist/eui/interface-identifier.d.ts +24 -0
- package/dist/eui/interface-identifier.d.ts.map +1 -0
- package/dist/eui/interface-identifier.js +47 -0
- package/dist/eui/interface-identifier.js.map +1 -0
- package/dist/eui/parse-eui.d.ts +31 -0
- package/dist/eui/parse-eui.d.ts.map +1 -0
- package/dist/eui/parse-eui.js +93 -0
- package/dist/eui/parse-eui.js.map +1 -0
- package/dist/eui/print-eui.d.ts +44 -0
- package/dist/eui/print-eui.d.ts.map +1 -0
- package/dist/eui/print-eui.js +64 -0
- package/dist/eui/print-eui.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/ipv4/classify-ipv4.d.ts +69 -0
- package/dist/ipv4/classify-ipv4.d.ts.map +1 -0
- package/dist/ipv4/classify-ipv4.js +129 -0
- package/dist/ipv4/classify-ipv4.js.map +1 -0
- package/dist/ipv4/constants.d.ts +5 -0
- package/dist/ipv4/constants.d.ts.map +1 -0
- package/dist/ipv4/constants.js +5 -0
- package/dist/ipv4/constants.js.map +1 -0
- package/dist/ipv4/ipv4-prefix.d.ts +52 -0
- package/dist/ipv4/ipv4-prefix.d.ts.map +1 -0
- package/dist/ipv4/ipv4-prefix.js +81 -0
- package/dist/ipv4/ipv4-prefix.js.map +1 -0
- package/dist/ipv4/parse-ipv4.d.ts +49 -0
- package/dist/ipv4/parse-ipv4.d.ts.map +1 -0
- package/dist/ipv4/parse-ipv4.js +169 -0
- package/dist/ipv4/parse-ipv4.js.map +1 -0
- package/dist/ipv4/print-ipv4.d.ts +50 -0
- package/dist/ipv4/print-ipv4.d.ts.map +1 -0
- package/dist/ipv4/print-ipv4.js +76 -0
- package/dist/ipv4/print-ipv4.js.map +1 -0
- package/dist/ipv6/classify-ipv6.d.ts +79 -0
- package/dist/ipv6/classify-ipv6.d.ts.map +1 -0
- package/dist/ipv6/classify-ipv6.js +148 -0
- package/dist/ipv6/classify-ipv6.js.map +1 -0
- package/dist/ipv6/constants.d.ts +5 -0
- package/dist/ipv6/constants.d.ts.map +1 -0
- package/dist/ipv6/constants.js +5 -0
- package/dist/ipv6/constants.js.map +1 -0
- package/dist/ipv6/ipv4-mapped.d.ts +43 -0
- package/dist/ipv6/ipv4-mapped.d.ts.map +1 -0
- package/dist/ipv6/ipv4-mapped.js +65 -0
- package/dist/ipv6/ipv4-mapped.js.map +1 -0
- package/dist/ipv6/ipv6-prefix.d.ts +51 -0
- package/dist/ipv6/ipv6-prefix.d.ts.map +1 -0
- package/dist/ipv6/ipv6-prefix.js +78 -0
- package/dist/ipv6/ipv6-prefix.js.map +1 -0
- package/dist/ipv6/parse-ipv6.d.ts +50 -0
- package/dist/ipv6/parse-ipv6.d.ts.map +1 -0
- package/dist/ipv6/parse-ipv6.js +148 -0
- package/dist/ipv6/parse-ipv6.js.map +1 -0
- package/dist/ipv6/print-ipv6.d.ts +37 -0
- package/dist/ipv6/print-ipv6.d.ts.map +1 -0
- package/dist/ipv6/print-ipv6.js +93 -0
- package/dist/ipv6/print-ipv6.js.map +1 -0
- package/dist/port/endpoint.d.ts +47 -0
- package/dist/port/endpoint.d.ts.map +1 -0
- package/dist/port/endpoint.js +104 -0
- package/dist/port/endpoint.js.map +1 -0
- package/dist/port/ephemeral-port.d.ts +17 -0
- package/dist/port/ephemeral-port.d.ts.map +1 -0
- package/dist/port/ephemeral-port.js +26 -0
- package/dist/port/ephemeral-port.js.map +1 -0
- package/dist/port/port.d.ts +69 -0
- package/dist/port/port.d.ts.map +1 -0
- package/dist/port/port.js +94 -0
- package/dist/port/port.js.map +1 -0
- package/dist/prefix/_numeric-range.d.ts +23 -0
- package/dist/prefix/_numeric-range.d.ts.map +1 -0
- package/dist/prefix/_numeric-range.js +57 -0
- package/dist/prefix/_numeric-range.js.map +1 -0
- package/dist/prefix/_prefix-length.d.ts +7 -0
- package/dist/prefix/_prefix-length.d.ts.map +1 -0
- package/dist/prefix/_prefix-length.js +13 -0
- package/dist/prefix/_prefix-length.js.map +1 -0
- package/dist/prefix/aggregate.d.ts +45 -0
- package/dist/prefix/aggregate.d.ts.map +1 -0
- package/dist/prefix/aggregate.js +97 -0
- package/dist/prefix/aggregate.js.map +1 -0
- package/dist/prefix/bit-address.d.ts +110 -0
- package/dist/prefix/bit-address.d.ts.map +1 -0
- package/dist/prefix/bit-address.js +165 -0
- package/dist/prefix/bit-address.js.map +1 -0
- package/dist/prefix/bit-prefix.d.ts +79 -0
- package/dist/prefix/bit-prefix.d.ts.map +1 -0
- package/dist/prefix/bit-prefix.js +135 -0
- package/dist/prefix/bit-prefix.js.map +1 -0
- package/dist/prefix/bit-range.d.ts +49 -0
- package/dist/prefix/bit-range.d.ts.map +1 -0
- package/dist/prefix/bit-range.js +100 -0
- package/dist/prefix/bit-range.js.map +1 -0
- package/dist/prefix/compare.d.ts +21 -0
- package/dist/prefix/compare.d.ts.map +1 -0
- package/dist/prefix/compare.js +33 -0
- package/dist/prefix/compare.js.map +1 -0
- package/dist/prefix/mask.d.ts +26 -0
- package/dist/prefix/mask.d.ts.map +1 -0
- package/dist/prefix/mask.js +48 -0
- package/dist/prefix/mask.js.map +1 -0
- package/dist/prefix/set-ops.d.ts +38 -0
- package/dist/prefix/set-ops.d.ts.map +1 -0
- package/dist/prefix/set-ops.js +71 -0
- package/dist/prefix/set-ops.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type BitAddress } from "../prefix/bit-address.js";
|
|
2
|
+
import type { BitPrefix } from "../prefix/bit-prefix.js";
|
|
3
|
+
import type { Ipv6ScopedAddress } from "./parse-ipv6.js";
|
|
4
|
+
/**
|
|
5
|
+
* Prints the RFC 5952 canonical form: lowercase, no leading zeros in a group,
|
|
6
|
+
* the longest run of zero groups compressed to `::` — leftmost on a tie, and
|
|
7
|
+
* never for a single group. An IPv4-mapped address is printed `::ffff:a.b.c.d`,
|
|
8
|
+
* per §5.
|
|
9
|
+
*
|
|
10
|
+
* O(1): the address has a fixed eight groups.
|
|
11
|
+
*
|
|
12
|
+
* @throws RangeError When the address is not 128 bits wide.
|
|
13
|
+
*/
|
|
14
|
+
export declare function printIpv6Address(address: BitAddress): string;
|
|
15
|
+
/**
|
|
16
|
+
* Prints the canonical form followed by `%zone` when the address carries one.
|
|
17
|
+
*
|
|
18
|
+
* The zone is emitted verbatim, not percent-encoded: RFC 6874's `%25` belongs
|
|
19
|
+
* to whatever URI the caller is building.
|
|
20
|
+
*
|
|
21
|
+
* @throws RangeError When the address is not 128 bits wide.
|
|
22
|
+
*/
|
|
23
|
+
export declare function printIpv6ScopedAddress(scoped: Ipv6ScopedAddress): string;
|
|
24
|
+
/**
|
|
25
|
+
* Prints CIDR notation, keeping any host bits the prefix carries.
|
|
26
|
+
*
|
|
27
|
+
* @throws RangeError When the prefix is not over a 128-bit address.
|
|
28
|
+
*/
|
|
29
|
+
export declare function printIpv6Prefix(prefix: BitPrefix): string;
|
|
30
|
+
/**
|
|
31
|
+
* The `ip6.arpa` name for the address, as RFC 3596 §2.5 defines it: the 32
|
|
32
|
+
* nibbles in reverse order, dot-separated, with no trailing dot.
|
|
33
|
+
*
|
|
34
|
+
* @throws RangeError When the address is not 128 bits wide.
|
|
35
|
+
*/
|
|
36
|
+
export declare function ipv6ReverseName(address: BitAddress): string;
|
|
37
|
+
//# sourceMappingURL=print-ipv6.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print-ipv6.d.ts","sourceRoot":"","sources":["../../src/ipv6/print-ipv6.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,UAAU,EAEf,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAqCzD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAuB5D;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAIxE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAY3D"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { printIpv4Address } from "../ipv4/print-ipv4.js";
|
|
2
|
+
import { assertBitAddressWidth, } from "../prefix/bit-address.js";
|
|
3
|
+
import { IPV6_BIT_WIDTH, IPV6_GROUP_COUNT } from "./constants.js";
|
|
4
|
+
import { ipv4FromIpv6, isIpv6Ipv4Mapped } from "./ipv4-mapped.js";
|
|
5
|
+
/**
|
|
6
|
+
* The longest run of zero groups, leftmost on a tie; `null` when none is worth
|
|
7
|
+
* compressing.
|
|
8
|
+
*/
|
|
9
|
+
function longestZeroRun(groups) {
|
|
10
|
+
let best = null;
|
|
11
|
+
let runStart = -1;
|
|
12
|
+
for (let index = 0; index <= groups.length; index++) {
|
|
13
|
+
if (index < groups.length && groups[index] === 0) {
|
|
14
|
+
if (runStart < 0) {
|
|
15
|
+
runStart = index;
|
|
16
|
+
}
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (runStart >= 0) {
|
|
20
|
+
const length = index - runStart;
|
|
21
|
+
// Strictly greater keeps the leftmost run on a tie, as RFC 5952 §4.2.3
|
|
22
|
+
// requires; a single zero group is never compressed (§4.2.2).
|
|
23
|
+
if (length >= 2 && (best === null || length > best.length)) {
|
|
24
|
+
best = { start: runStart, length };
|
|
25
|
+
}
|
|
26
|
+
runStart = -1;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return best;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Prints the RFC 5952 canonical form: lowercase, no leading zeros in a group,
|
|
33
|
+
* the longest run of zero groups compressed to `::` — leftmost on a tie, and
|
|
34
|
+
* never for a single group. An IPv4-mapped address is printed `::ffff:a.b.c.d`,
|
|
35
|
+
* per §5.
|
|
36
|
+
*
|
|
37
|
+
* O(1): the address has a fixed eight groups.
|
|
38
|
+
*
|
|
39
|
+
* @throws RangeError When the address is not 128 bits wide.
|
|
40
|
+
*/
|
|
41
|
+
export function printIpv6Address(address) {
|
|
42
|
+
assertBitAddressWidth(address, IPV6_BIT_WIDTH);
|
|
43
|
+
if (isIpv6Ipv4Mapped(address)) {
|
|
44
|
+
// Non-null: a mapped address always embeds an IPv4 address.
|
|
45
|
+
return `::ffff:${printIpv4Address(ipv4FromIpv6(address))}`;
|
|
46
|
+
}
|
|
47
|
+
const groups = Array.from({ length: IPV6_GROUP_COUNT }, (_, index) => Number((address.value >> BigInt((IPV6_GROUP_COUNT - 1 - index) * 16)) & 0xffffn));
|
|
48
|
+
const text = groups.map((group) => group.toString(16));
|
|
49
|
+
const run = longestZeroRun(groups);
|
|
50
|
+
if (run === null) {
|
|
51
|
+
return text.join(":");
|
|
52
|
+
}
|
|
53
|
+
return `${text.slice(0, run.start).join(":")}::${text
|
|
54
|
+
.slice(run.start + run.length)
|
|
55
|
+
.join(":")}`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Prints the canonical form followed by `%zone` when the address carries one.
|
|
59
|
+
*
|
|
60
|
+
* The zone is emitted verbatim, not percent-encoded: RFC 6874's `%25` belongs
|
|
61
|
+
* to whatever URI the caller is building.
|
|
62
|
+
*
|
|
63
|
+
* @throws RangeError When the address is not 128 bits wide.
|
|
64
|
+
*/
|
|
65
|
+
export function printIpv6ScopedAddress(scoped) {
|
|
66
|
+
const text = printIpv6Address(scoped.address);
|
|
67
|
+
return scoped.zoneId === null ? text : `${text}%${scoped.zoneId}`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Prints CIDR notation, keeping any host bits the prefix carries.
|
|
71
|
+
*
|
|
72
|
+
* @throws RangeError When the prefix is not over a 128-bit address.
|
|
73
|
+
*/
|
|
74
|
+
export function printIpv6Prefix(prefix) {
|
|
75
|
+
return `${printIpv6Address(prefix.address)}/${prefix.prefixLength}`;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The `ip6.arpa` name for the address, as RFC 3596 §2.5 defines it: the 32
|
|
79
|
+
* nibbles in reverse order, dot-separated, with no trailing dot.
|
|
80
|
+
*
|
|
81
|
+
* @throws RangeError When the address is not 128 bits wide.
|
|
82
|
+
*/
|
|
83
|
+
export function ipv6ReverseName(address) {
|
|
84
|
+
assertBitAddressWidth(address, IPV6_BIT_WIDTH);
|
|
85
|
+
const nibbles = [];
|
|
86
|
+
let rest = address.value;
|
|
87
|
+
for (let index = 0; index < IPV6_BIT_WIDTH / 4; index++) {
|
|
88
|
+
nibbles.push(Number(rest & 0xfn).toString(16));
|
|
89
|
+
rest >>= 4n;
|
|
90
|
+
}
|
|
91
|
+
return `${nibbles.join(".")}.ip6.arpa`;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=print-ipv6.js.map
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AC,CAAC,CAAC,GAAG,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;AACnE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAiB;IAChD,OAAO,GAAG,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;AACrE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,OAAmB;IAClD,qBAAqB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IAE/C,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC;IAEzB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,cAAc,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/C,IAAI,KAAK,EAAE,CAAC;IACb,CAAC;IAED,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { BitAddress } from "../prefix/bit-address.js";
|
|
2
|
+
import { type PortNumber } from "./port.js";
|
|
3
|
+
/**
|
|
4
|
+
* What the host part of an endpoint turned out to be.
|
|
5
|
+
*
|
|
6
|
+
* A registered name stays a name even when it is all digits: `2130706433` is a
|
|
7
|
+
* name here, not an address, because only a resolver can say what it points at.
|
|
8
|
+
* An allowlist must classify what the resolver returned, never this string.
|
|
9
|
+
*/
|
|
10
|
+
export type EndpointHost = {
|
|
11
|
+
readonly kind: "ipv4";
|
|
12
|
+
readonly address: BitAddress;
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: "ipv6";
|
|
15
|
+
readonly address: BitAddress;
|
|
16
|
+
readonly zoneId: string | null;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: "name";
|
|
19
|
+
readonly name: string;
|
|
20
|
+
};
|
|
21
|
+
/** A host with an optional port — `example.org:443`, `[::1]:8080`, `10.0.0.1`. */
|
|
22
|
+
export type NetEndpoint = {
|
|
23
|
+
readonly host: EndpointHost;
|
|
24
|
+
readonly port: PortNumber | null;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Parses `host`, `host:port`, `[v6]` or `[v6]:port`, with the bracket form of
|
|
28
|
+
* RFC 3986 §3.2.2.
|
|
29
|
+
*
|
|
30
|
+
* An IPv6 literal must be bracketed, so a port can never be mistaken for the
|
|
31
|
+
* final group. Inside the brackets a zone identifier is taken verbatim after
|
|
32
|
+
* `%`; RFC 6874's `%25` encoding is the caller's to decode.
|
|
33
|
+
*
|
|
34
|
+
* @throws NetAddressSyntaxError When `text` is not an endpoint.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseEndpoint(text: string): NetEndpoint;
|
|
37
|
+
/** {@link parseEndpoint}, answering `null` instead of throwing. O(1). */
|
|
38
|
+
export declare function tryParseEndpoint(text: string): NetEndpoint | null;
|
|
39
|
+
/**
|
|
40
|
+
* Prints the endpoint, bracketing an IPv6 host whenever a port is present — and
|
|
41
|
+
* also when it is not, so the result is always safe to concatenate a `:port`
|
|
42
|
+
* onto.
|
|
43
|
+
*/
|
|
44
|
+
export declare function printEndpoint(endpoint: NetEndpoint): string;
|
|
45
|
+
/** Prints the host alone, bracketing an IPv6 literal. */
|
|
46
|
+
export declare function printEndpointHost(host: EndpointHost): string;
|
|
47
|
+
//# sourceMappingURL=endpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/port/endpoint.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,KAAK,UAAU,EAAgB,MAAM,WAAW,CAAC;AAE1D;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAA;CAAE,GACvD;IACA,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpD,kFAAkF;AAClF,MAAM,MAAM,WAAW,GAAG;IACzB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;CACjC,CAAC;AAoCF;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAQvD;AAED,yEAAyE;AACzE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAiBjE;AA0BD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,CAI3D;AAED,yDAAyD;AACzD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAe5D"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { NetAddressSyntaxError } from "../errors.js";
|
|
2
|
+
import { tryParseIpv4Address } from "../ipv4/parse-ipv4.js";
|
|
3
|
+
import { printIpv4Address } from "../ipv4/print-ipv4.js";
|
|
4
|
+
import { tryParseIpv6ScopedAddress, } from "../ipv6/parse-ipv6.js";
|
|
5
|
+
import { printIpv6ScopedAddress } from "../ipv6/print-ipv6.js";
|
|
6
|
+
import { tryParsePort } from "./port.js";
|
|
7
|
+
const REGISTERED_NAME_PATTERN = /^[0-9a-zA-Z._~%!$&'()*+,;=-]+$/;
|
|
8
|
+
function splitHostAndPort(text) {
|
|
9
|
+
if (text.startsWith("[")) {
|
|
10
|
+
const closing = text.indexOf("]");
|
|
11
|
+
if (closing < 0) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const rest = text.slice(closing + 1);
|
|
15
|
+
const inside = text.slice(1, closing);
|
|
16
|
+
if (rest === "") {
|
|
17
|
+
return [inside, null];
|
|
18
|
+
}
|
|
19
|
+
return rest.startsWith(":") ? [inside, rest.slice(1)] : null;
|
|
20
|
+
}
|
|
21
|
+
const colon = text.indexOf(":");
|
|
22
|
+
// An unbracketed literal with more than one colon is an IPv6 address written
|
|
23
|
+
// without its brackets, which RFC 3986 §3.2.2 does not allow — and accepting
|
|
24
|
+
// it would make `::1:8080` ambiguous.
|
|
25
|
+
if (colon < 0) {
|
|
26
|
+
return [text, null];
|
|
27
|
+
}
|
|
28
|
+
return text.includes(":", colon + 1)
|
|
29
|
+
? null
|
|
30
|
+
: [text.slice(0, colon), text.slice(colon + 1)];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Parses `host`, `host:port`, `[v6]` or `[v6]:port`, with the bracket form of
|
|
34
|
+
* RFC 3986 §3.2.2.
|
|
35
|
+
*
|
|
36
|
+
* An IPv6 literal must be bracketed, so a port can never be mistaken for the
|
|
37
|
+
* final group. Inside the brackets a zone identifier is taken verbatim after
|
|
38
|
+
* `%`; RFC 6874's `%25` encoding is the caller's to decode.
|
|
39
|
+
*
|
|
40
|
+
* @throws NetAddressSyntaxError When `text` is not an endpoint.
|
|
41
|
+
*/
|
|
42
|
+
export function parseEndpoint(text) {
|
|
43
|
+
const endpoint = tryParseEndpoint(text);
|
|
44
|
+
if (endpoint === null) {
|
|
45
|
+
throw new NetAddressSyntaxError(text, "not a host or host:port endpoint");
|
|
46
|
+
}
|
|
47
|
+
return endpoint;
|
|
48
|
+
}
|
|
49
|
+
/** {@link parseEndpoint}, answering `null` instead of throwing. O(1). */
|
|
50
|
+
export function tryParseEndpoint(text) {
|
|
51
|
+
const split = splitHostAndPort(text);
|
|
52
|
+
if (split === null) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const [hostText, portText] = split;
|
|
56
|
+
const port = portText === null ? null : tryParsePort(portText);
|
|
57
|
+
if (portText !== null && port === null) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const host = tryParseEndpointHost(hostText, text.startsWith("["));
|
|
61
|
+
return host === null ? null : { host, port };
|
|
62
|
+
}
|
|
63
|
+
function tryParseEndpointHost(hostText, bracketed) {
|
|
64
|
+
if (bracketed) {
|
|
65
|
+
const scoped = tryParseIpv6ScopedAddress(hostText);
|
|
66
|
+
return scoped === null
|
|
67
|
+
? null
|
|
68
|
+
: { kind: "ipv6", address: scoped.address, zoneId: scoped.zoneId };
|
|
69
|
+
}
|
|
70
|
+
const ipv4 = tryParseIpv4Address(hostText);
|
|
71
|
+
if (ipv4 !== null) {
|
|
72
|
+
return { kind: "ipv4", address: ipv4 };
|
|
73
|
+
}
|
|
74
|
+
return REGISTERED_NAME_PATTERN.test(hostText)
|
|
75
|
+
? { kind: "name", name: hostText }
|
|
76
|
+
: null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Prints the endpoint, bracketing an IPv6 host whenever a port is present — and
|
|
80
|
+
* also when it is not, so the result is always safe to concatenate a `:port`
|
|
81
|
+
* onto.
|
|
82
|
+
*/
|
|
83
|
+
export function printEndpoint(endpoint) {
|
|
84
|
+
const host = printEndpointHost(endpoint.host);
|
|
85
|
+
return endpoint.port === null ? host : `${host}:${endpoint.port}`;
|
|
86
|
+
}
|
|
87
|
+
/** Prints the host alone, bracketing an IPv6 literal. */
|
|
88
|
+
export function printEndpointHost(host) {
|
|
89
|
+
switch (host.kind) {
|
|
90
|
+
case "ipv4": {
|
|
91
|
+
return printIpv4Address(host.address);
|
|
92
|
+
}
|
|
93
|
+
case "ipv6": {
|
|
94
|
+
return `[${printIpv6ScopedAddress({
|
|
95
|
+
address: host.address,
|
|
96
|
+
zoneId: host.zoneId,
|
|
97
|
+
})}]`;
|
|
98
|
+
}
|
|
99
|
+
case "name": {
|
|
100
|
+
return host.name;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=endpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../src/port/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAEN,yBAAyB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,EAAmB,YAAY,EAAE,MAAM,WAAW,CAAC;AAwB1D,MAAM,uBAAuB,GAAG,gCAAgC,CAAC;AAEjE,SAAS,gBAAgB,CAAC,IAAY;IACrC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;QACrC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAEtC,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;YACjB,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,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AI,EAAE,CAAC;AACnE,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,iBAAiB,CAAC,IAAkB;IACnD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,MAAM,EAAE,CAAC;YACb,OAAO,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC;QACD,KAAK,MAAM,EAAE,CAAC;YACb,OAAO,IAAI,sBAAsB,CAAC;gBACjC,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,MAAM,EAAE,IAAI,CAAC,MAAM;aACnB,CAAC,GAAG,CAAC;QACP,CAAC;QACD,KAAK,MAAM,EAAE,CAAC;YACb,OAAO,IAAI,CAAC,IAAI,CAAC;QAClB,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type PortNumber } from "./port.js";
|
|
2
|
+
/** First port of the RFC 6335 dynamic / private range. */
|
|
3
|
+
export declare const EPHEMERAL_PORT_MIN_VALUE = 49152;
|
|
4
|
+
/** Last port of the RFC 6335 dynamic / private range. */
|
|
5
|
+
export declare const EPHEMERAL_PORT_MAX_VALUE = 65535;
|
|
6
|
+
/**
|
|
7
|
+
* A random port from the range RFC 6335 and IANA set aside for dynamic or
|
|
8
|
+
* private use, 49152 through 65535.
|
|
9
|
+
*
|
|
10
|
+
* Drawn from `crypto.getRandomValues`, so it is unpredictable — which matters
|
|
11
|
+
* when the port is a weak secret, as an ephemeral source port is. It says
|
|
12
|
+
* nothing about whether the port is free; binding is still the only test.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getRandomEphemeralPort(): PortNumber;
|
|
15
|
+
/** Whether the port falls in the IANA ephemeral range. */
|
|
16
|
+
export declare function isEphemeralPort(port: PortNumber): boolean;
|
|
17
|
+
//# sourceMappingURL=ephemeral-port.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ephemeral-port.d.ts","sourceRoot":"","sources":["../../src/port/ephemeral-port.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAgB,MAAM,WAAW,CAAC;AAE1D,0DAA0D;AAC1D,eAAO,MAAM,wBAAwB,QAAQ,CAAC;AAE9C,yDAAyD;AACzD,eAAO,MAAM,wBAAwB,QAAQ,CAAC;AAK9C;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,IAAI,UAAU,CASnD;AAED,0DAA0D;AAC1D,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAEzD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { toPortNumber } from "./port.js";
|
|
2
|
+
/** First port of the RFC 6335 dynamic / private range. */
|
|
3
|
+
export const EPHEMERAL_PORT_MIN_VALUE = 49152;
|
|
4
|
+
/** Last port of the RFC 6335 dynamic / private range. */
|
|
5
|
+
export const EPHEMERAL_PORT_MAX_VALUE = 65535;
|
|
6
|
+
const EPHEMERAL_PORT_COUNT = EPHEMERAL_PORT_MAX_VALUE - EPHEMERAL_PORT_MIN_VALUE + 1;
|
|
7
|
+
/**
|
|
8
|
+
* A random port from the range RFC 6335 and IANA set aside for dynamic or
|
|
9
|
+
* private use, 49152 through 65535.
|
|
10
|
+
*
|
|
11
|
+
* Drawn from `crypto.getRandomValues`, so it is unpredictable — which matters
|
|
12
|
+
* when the port is a weak secret, as an ephemeral source port is. It says
|
|
13
|
+
* nothing about whether the port is free; binding is still the only test.
|
|
14
|
+
*/
|
|
15
|
+
export function getRandomEphemeralPort() {
|
|
16
|
+
const draw = new Uint16Array(1);
|
|
17
|
+
crypto.getRandomValues(draw);
|
|
18
|
+
// 65536 is an exact multiple of the 16384-port range, so the modulo is unbiased.
|
|
19
|
+
// Non-null: the array was allocated with one element.
|
|
20
|
+
return toPortNumber(EPHEMERAL_PORT_MIN_VALUE + (draw[0] % EPHEMERAL_PORT_COUNT));
|
|
21
|
+
}
|
|
22
|
+
/** Whether the port falls in the IANA ephemeral range. */
|
|
23
|
+
export function isEphemeralPort(port) {
|
|
24
|
+
return port >= EPHEMERAL_PORT_MIN_VALUE && port <= EPHEMERAL_PORT_MAX_VALUE;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=ephemeral-port.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ephemeral-port.js","sourceRoot":"","sources":["../../src/port/ephemeral-port.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,YAAY,EAAE,MAAM,WAAW,CAAC;AAE1D,0DAA0D;AAC1D,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAE9C,yDAAyD;AACzD,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAE9C,MAAM,oBAAoB,GACzB,wBAAwB,GAAG,wBAAwB,GAAG,CAAC,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB;IACrC,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;IAChC,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAE7B,iFAAiF;IACjF,sDAAsD;IACtD,OAAO,YAAY,CAClB,wBAAwB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAE,GAAG,oBAAoB,CAAC,CAC5D,CAAC;AACH,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,eAAe,CAAC,IAAgB;IAC/C,OAAO,IAAI,IAAI,wBAAwB,IAAI,IAAI,IAAI,wBAAwB,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
declare const portNumberTag: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* A validated TCP or UDP port number.
|
|
4
|
+
*
|
|
5
|
+
* The tag is declared, never constructed, so the type costs nothing at runtime.
|
|
6
|
+
* It exists so a function taking a port cannot be handed an arbitrary `number`
|
|
7
|
+
* that nobody range-checked: the only ways in are {@link toPortNumber},
|
|
8
|
+
* {@link parsePort} and the {@link isPortNumber} guard.
|
|
9
|
+
*/
|
|
10
|
+
export type PortNumber = number & {
|
|
11
|
+
readonly [portNumberTag]: true;
|
|
12
|
+
};
|
|
13
|
+
/** The lowest port number. RFC 6335 reserves it and it is never assigned. */
|
|
14
|
+
export declare const PORT_MIN_VALUE = 0;
|
|
15
|
+
/** The highest port number: ports are a 16-bit field. */
|
|
16
|
+
export declare const PORT_MAX_VALUE = 65535;
|
|
17
|
+
/** Last of the RFC 6335 System (well-known) range. */
|
|
18
|
+
export declare const SYSTEM_PORT_MAX_VALUE = 1023;
|
|
19
|
+
/** First of the RFC 6335 User (registered) range. */
|
|
20
|
+
export declare const USER_PORT_MIN_VALUE = 1024;
|
|
21
|
+
/** Last of the RFC 6335 User (registered) range. */
|
|
22
|
+
export declare const USER_PORT_MAX_VALUE = 49151;
|
|
23
|
+
/** Whether `value` is an integer in `[0, 65535]`. */
|
|
24
|
+
export declare function isPortNumber(value: number): value is PortNumber;
|
|
25
|
+
/**
|
|
26
|
+
* Narrows a number to a {@link PortNumber}.
|
|
27
|
+
*
|
|
28
|
+
* @throws RangeError When `value` is not an integer in `[0, 65535]`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function toPortNumber(value: number): PortNumber;
|
|
31
|
+
/**
|
|
32
|
+
* Parses a decimal port number, strictly: digits only, no sign, no leading
|
|
33
|
+
* zero, no whitespace.
|
|
34
|
+
*
|
|
35
|
+
* A leading zero is rejected for the same reason `parseIpv4Address` rejects it
|
|
36
|
+
* — `080` must not read as 80 here and as something else in the next hop's
|
|
37
|
+
* parser. O(1).
|
|
38
|
+
*
|
|
39
|
+
* @throws NetAddressSyntaxError When `text` is not such a number, or is out of
|
|
40
|
+
* range.
|
|
41
|
+
*/
|
|
42
|
+
export declare function parsePort(text: string): PortNumber;
|
|
43
|
+
/** {@link parsePort}, answering `null` instead of throwing. O(1). */
|
|
44
|
+
export declare function tryParsePort(text: string): PortNumber | null;
|
|
45
|
+
/** Prints the port as a decimal number. */
|
|
46
|
+
export declare function printPort(port: PortNumber): string;
|
|
47
|
+
/** The RFC 6335 §6 ranges. */
|
|
48
|
+
export type PortRange =
|
|
49
|
+
/** 0–1023, assigned by IANA after IETF review. */
|
|
50
|
+
"system"
|
|
51
|
+
/** 1024–49151, assigned by IANA on request. */
|
|
52
|
+
| "user"
|
|
53
|
+
/** 49152–65535, never assigned; free for ephemeral use. */
|
|
54
|
+
| "dynamic";
|
|
55
|
+
/**
|
|
56
|
+
* Which RFC 6335 range a port falls in.
|
|
57
|
+
*
|
|
58
|
+
* Port 0 answers `"system"` — it sits in that numeric range even though RFC
|
|
59
|
+
* 6335 reserves it and no service is ever assigned to it.
|
|
60
|
+
*/
|
|
61
|
+
export declare function classifyPort(port: PortNumber): PortRange;
|
|
62
|
+
/** Whether the port is in the IANA-assigned well-known range. */
|
|
63
|
+
export declare function isWellKnownPort(port: PortNumber): boolean;
|
|
64
|
+
/** Whether the port is in the IANA registered range. */
|
|
65
|
+
export declare function isRegisteredPort(port: PortNumber): boolean;
|
|
66
|
+
/** Whether the port is in the dynamic / private range. */
|
|
67
|
+
export declare function isDynamicPort(port: PortNumber): boolean;
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=port.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"port.d.ts","sourceRoot":"","sources":["../../src/port/port.ts"],"names":[],"mappings":"AAIA,OAAO,CAAC,MAAM,aAAa,EAAE,OAAO,MAAM,CAAC;AAE3C;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,aAAa,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAErE,6EAA6E;AAC7E,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,yDAAyD;AACzD,eAAO,MAAM,cAAc,QAAS,CAAC;AAErC,sDAAsD;AACtD,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,qDAAqD;AACrD,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC,oDAAoD;AACpD,eAAO,MAAM,mBAAmB,QAAS,CAAC;AAE1C,qDAAqD;AACrD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,UAAU,CAM/D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAMtD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAQlD;AAED,qEAAqE;AACrE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAsB5D;AAED,2CAA2C;AAC3C,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAElD;AAED,8BAA8B;AAC9B,MAAM,MAAM,SAAS;AACpB,kDAAkD;AAChD,QAAQ;AACV,+CAA+C;GAC7C,MAAM;AACR,2DAA2D;GACzD,SAAS,CAAC;AAEb;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,CAMxD;AAED,iEAAiE;AACjE,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAEzD;AAED,wDAAwD;AACxD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAE1D;AAED,0DAA0D;AAC1D,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAEvD"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { isAsciiDigit } from "@ac-kit/core";
|
|
2
|
+
import { NetAddressSyntaxError } from "../errors.js";
|
|
3
|
+
/** The lowest port number. RFC 6335 reserves it and it is never assigned. */
|
|
4
|
+
export const PORT_MIN_VALUE = 0;
|
|
5
|
+
/** The highest port number: ports are a 16-bit field. */
|
|
6
|
+
export const PORT_MAX_VALUE = 65535;
|
|
7
|
+
/** Last of the RFC 6335 System (well-known) range. */
|
|
8
|
+
export const SYSTEM_PORT_MAX_VALUE = 1023;
|
|
9
|
+
/** First of the RFC 6335 User (registered) range. */
|
|
10
|
+
export const USER_PORT_MIN_VALUE = 1024;
|
|
11
|
+
/** Last of the RFC 6335 User (registered) range. */
|
|
12
|
+
export const USER_PORT_MAX_VALUE = 49151;
|
|
13
|
+
/** Whether `value` is an integer in `[0, 65535]`. */
|
|
14
|
+
export function isPortNumber(value) {
|
|
15
|
+
return (Number.isInteger(value) &&
|
|
16
|
+
value >= PORT_MIN_VALUE &&
|
|
17
|
+
value <= PORT_MAX_VALUE);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Narrows a number to a {@link PortNumber}.
|
|
21
|
+
*
|
|
22
|
+
* @throws RangeError When `value` is not an integer in `[0, 65535]`.
|
|
23
|
+
*/
|
|
24
|
+
export function toPortNumber(value) {
|
|
25
|
+
if (!isPortNumber(value)) {
|
|
26
|
+
throw new RangeError(`not a port number: ${value}`);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parses a decimal port number, strictly: digits only, no sign, no leading
|
|
32
|
+
* zero, no whitespace.
|
|
33
|
+
*
|
|
34
|
+
* A leading zero is rejected for the same reason `parseIpv4Address` rejects it
|
|
35
|
+
* — `080` must not read as 80 here and as something else in the next hop's
|
|
36
|
+
* parser. O(1).
|
|
37
|
+
*
|
|
38
|
+
* @throws NetAddressSyntaxError When `text` is not such a number, or is out of
|
|
39
|
+
* range.
|
|
40
|
+
*/
|
|
41
|
+
export function parsePort(text) {
|
|
42
|
+
const port = tryParsePort(text);
|
|
43
|
+
if (port === null) {
|
|
44
|
+
throw new NetAddressSyntaxError(text, "not a port number");
|
|
45
|
+
}
|
|
46
|
+
return port;
|
|
47
|
+
}
|
|
48
|
+
/** {@link parsePort}, answering `null` instead of throwing. O(1). */
|
|
49
|
+
export function tryParsePort(text) {
|
|
50
|
+
if (text.length === 0 || text.length > 5) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (text.length > 1 && text.charCodeAt(0) === 0x30) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
let value = 0;
|
|
57
|
+
for (let index = 0; index < text.length; index++) {
|
|
58
|
+
const code = text.charCodeAt(index);
|
|
59
|
+
if (!isAsciiDigit(code)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
value = value * 10 + (code - 0x30);
|
|
63
|
+
}
|
|
64
|
+
return isPortNumber(value) ? value : null;
|
|
65
|
+
}
|
|
66
|
+
/** Prints the port as a decimal number. */
|
|
67
|
+
export function printPort(port) {
|
|
68
|
+
return String(port);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Which RFC 6335 range a port falls in.
|
|
72
|
+
*
|
|
73
|
+
* Port 0 answers `"system"` — it sits in that numeric range even though RFC
|
|
74
|
+
* 6335 reserves it and no service is ever assigned to it.
|
|
75
|
+
*/
|
|
76
|
+
export function classifyPort(port) {
|
|
77
|
+
if (port <= SYSTEM_PORT_MAX_VALUE) {
|
|
78
|
+
return "system";
|
|
79
|
+
}
|
|
80
|
+
return port <= USER_PORT_MAX_VALUE ? "user" : "dynamic";
|
|
81
|
+
}
|
|
82
|
+
/** Whether the port is in the IANA-assigned well-known range. */
|
|
83
|
+
export function isWellKnownPort(port) {
|
|
84
|
+
return classifyPort(port) === "system";
|
|
85
|
+
}
|
|
86
|
+
/** Whether the port is in the IANA registered range. */
|
|
87
|
+
export function isRegisteredPort(port) {
|
|
88
|
+
return classifyPort(port) === "user";
|
|
89
|
+
}
|
|
90
|
+
/** Whether the port is in the dynamic / private range. */
|
|
91
|
+
export function isDynamicPort(port) {
|
|
92
|
+
return classifyPort(port) === "dynamic";
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=port.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"port.js","sourceRoot":"","sources":["../../src/port/port.ts"],"names":[],"mappings":"AAAA,OA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AAC1D,MAAM,UAAU,aAAa,CAAC,IAAgB;IAC7C,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BitPrefix } from "./bit-prefix.js";
|
|
2
|
+
/**
|
|
3
|
+
* Inclusive address ranges as flat, stride-2 `[first, last, first, last, …]`
|
|
4
|
+
* integers — `@ac-kit/algo`'s interval form, so its set algebra applies
|
|
5
|
+
* directly.
|
|
6
|
+
*
|
|
7
|
+
* `BitRange` is the same idea over `BitAddress` and is what callers see; this
|
|
8
|
+
* is the shape the algebra runs on, and the two conversions below are the only
|
|
9
|
+
* boundary between them.
|
|
10
|
+
*/
|
|
11
|
+
export type NumericRanges = readonly bigint[];
|
|
12
|
+
/**
|
|
13
|
+
* The one width every prefix in `prefixes` must share.
|
|
14
|
+
*
|
|
15
|
+
* @throws RangeError When they do not, or when the collection is empty and no
|
|
16
|
+
* `fallback` was given.
|
|
17
|
+
*/
|
|
18
|
+
export declare function commonBitWidth(prefixes: readonly BitPrefix[], fallback?: number): number;
|
|
19
|
+
/** Converts prefixes to sorted, disjoint, non-touching integer ranges. */
|
|
20
|
+
export declare function toNumericRanges(prefixes: readonly BitPrefix[]): bigint[];
|
|
21
|
+
/** Converts integer ranges back to the minimal covering prefix list. */
|
|
22
|
+
export declare function fromNumericRanges(ranges: NumericRanges, bitWidth: number): BitPrefix[];
|
|
23
|
+
//# sourceMappingURL=_numeric-range.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_numeric-range.d.ts","sourceRoot":"","sources":["../../src/prefix/_numeric-range.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAOjD;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,MAAM,EAAE,CAAC;AAE9C;;;;;GAKG;AACH,wBAAgB,cAAc,CAC7B,QAAQ,EAAE,SAAS,SAAS,EAAE,EAC9B,QAAQ,CAAC,EAAE,MAAM,GACf,MAAM,CAkBR;AAkBD,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,QAAQ,EAAE,SAAS,SAAS,EAAE,GAAG,MAAM,EAAE,CAaxE;AAED,wEAAwE;AACxE,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,MAAM,GACd,SAAS,EAAE,CAcb"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { mergeIntervals } from "@ac-kit/algo";
|
|
2
|
+
import { compareNaturalAscending } from "@ac-kit/core";
|
|
3
|
+
import { bitAddressFromBigInt, bitAddressToBigInt } from "./bit-address.js";
|
|
4
|
+
import { bitRangeFromPrefix, bitRangeToPrefixes, } from "./bit-range.js";
|
|
5
|
+
/**
|
|
6
|
+
* The one width every prefix in `prefixes` must share.
|
|
7
|
+
*
|
|
8
|
+
* @throws RangeError When they do not, or when the collection is empty and no
|
|
9
|
+
* `fallback` was given.
|
|
10
|
+
*/
|
|
11
|
+
export function commonBitWidth(prefixes, fallback) {
|
|
12
|
+
let width = fallback;
|
|
13
|
+
for (const prefix of prefixes) {
|
|
14
|
+
width ??= prefix.address.bitWidth;
|
|
15
|
+
if (prefix.address.bitWidth !== width) {
|
|
16
|
+
throw new RangeError(`prefixes mix ${width}-bit and ${prefix.address.bitWidth}-bit addresses`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (width === undefined) {
|
|
20
|
+
throw new RangeError("cannot infer a bit width from no prefixes");
|
|
21
|
+
}
|
|
22
|
+
return width;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Sorts and merges touching or adjacent ranges. O(n log n).
|
|
26
|
+
*
|
|
27
|
+
* Addresses are integers, so `10.0.0.5-10.0.0.9` and `10.0.0.10-10.0.0.20` name
|
|
28
|
+
* one contiguous block and have to coalesce — that is what the successor test
|
|
29
|
+
* says, and without it the two would stay apart and produce two prefixes where
|
|
30
|
+
* one covers them.
|
|
31
|
+
*/
|
|
32
|
+
function normalizeNumericRanges(bounds) {
|
|
33
|
+
return mergeIntervals(bounds, compareNaturalAscending, (end, next) => next === end + 1n);
|
|
34
|
+
}
|
|
35
|
+
/** Converts prefixes to sorted, disjoint, non-touching integer ranges. */
|
|
36
|
+
export function toNumericRanges(prefixes) {
|
|
37
|
+
const bounds = [];
|
|
38
|
+
for (const prefix of prefixes) {
|
|
39
|
+
const range = bitRangeFromPrefix(prefix);
|
|
40
|
+
bounds.push(bitAddressToBigInt(range.first), bitAddressToBigInt(range.last));
|
|
41
|
+
}
|
|
42
|
+
return normalizeNumericRanges(bounds);
|
|
43
|
+
}
|
|
44
|
+
/** Converts integer ranges back to the minimal covering prefix list. */
|
|
45
|
+
export function fromNumericRanges(ranges, bitWidth) {
|
|
46
|
+
const prefixes = [];
|
|
47
|
+
for (let index = 0; index < ranges.length; index += 2) {
|
|
48
|
+
// Non-null: interval bounds come in pairs.
|
|
49
|
+
const range = {
|
|
50
|
+
first: bitAddressFromBigInt(ranges[index], bitWidth),
|
|
51
|
+
last: bitAddressFromBigInt(ranges[index + 1], bitWidth),
|
|
52
|
+
};
|
|
53
|
+
prefixes.push(...bitRangeToPrefixes(range));
|
|
54
|
+
}
|
|
55
|
+
return prefixes;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=_numeric-range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_numeric-range.js","sourceRoot":"","sources":["../../src/prefix/_numeric-range.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE5E,OAAO,EAEN,kBAAkB,EAClB,kBAAkB,GAClB,MAAM,gBAAgB,CAAC;AAaxB;;;;;GAKG;AACH,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KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACvD,2CAA2C;QAC3C,MAAM,KAAK,GAAa;YACvB,KAAK,EAAE,oBAAoB,CAAC,MAAM,CAAC,KAAK,CAAE,EAAE,QAAQ,CAAC;YACrD,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAE,EAAE,QAAQ,CAAC;SACxD,CAAC;QAEF,QAAQ,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throws unless `prefixLength` names a valid cut of a `bitWidth`-bit address.
|
|
3
|
+
*
|
|
4
|
+
* @throws RangeError When it is not an integer in `[0, bitWidth]`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function assertPrefixLength(prefixLength: number, bitWidth: number): void;
|
|
7
|
+
//# sourceMappingURL=_prefix-length.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_prefix-length.d.ts","sourceRoot":"","sources":["../../src/prefix/_prefix-length.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,kBAAkB,CACjC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,GACd,IAAI,CAUN"}
|