You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Protocols using the `fspath` encoding must not be shared between different hosts.
137
+
138
+
#### `idna`
139
+
140
+
Encodes the given Unicode representation according to IDNA-2008 ([RFC 5890](https://tools.ietf.org/html/rfc5890)) conventions using the [UTS-46](https://tools.ietf.org/html/rfc5890) input normalization and processing rules.
141
+
142
+
* String → Binary:
143
+
1. Normalize and validate the given input string according to [UTS-46 Section 4 (Processing)](https://www.unicode.org/reports/tr46/#Processing) and [UTS-46 Section 4.1 (Validity Criteria)](https://www.unicode.org/reports/tr46/#Validity_Criteria) with the following parameters:
144
+
* UseSTD3ASCIIRules = true
145
+
* CheckHyphens = true
146
+
* CheckBidi = true
147
+
* CheckJoiners = true
148
+
* Transitional_Processing = false
149
+
2. Convert the Unicode string to ASCII using the [UTS-46 Section 4.2 (ToASCII)](https://www.unicode.org/reports/tr46/#ToASCII) algorithm steps 2–6 with parameter *VerifyDnsLength* set to *true* and return the result.
150
+
* Binary → String:
151
+
Convert the ASCII text string to Unicode according to the rules of [UTS-46 Section 4.3 (ToUnicode)](https://www.unicode.org/reports/tr46/#ToUnicode) using the same parameters as in step 1 of the *String → Binary* algorithm.
152
+
153
+
Examples of libraries for performing the above steps include the [Python idna](https://pypi.org/project/idna/) library.
154
+
155
+
#### `ip4`
156
+
157
+
Encodes an IPv4 address according to the conventional [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) first specificed in [RFC 3986 section 3.2.2 page 20 § 2](https://tools.ietf.org/html/rfc3986#page-20).
158
+
159
+
Protocols using this codec must encode it as binary value of exactly 4 bytes without
160
+
an extra length value.
161
+
162
+
* String → Binary:
163
+
1. Split the input string into parts at each dot (U+002E FULL STOP):
164
+
`sparts = str.split(".")`
165
+
2. Assert that exactly 4 string parts were created by the split operation:
166
+
`assert len(parts) == 4`
167
+
3. Convert each part from its ASCII base-10 number representation to an integer type, aborting if the conversion fails for any of the decimal string parts:
168
+
`octets = [int(p) for p in parts]`
169
+
4. Validate that each part of the resulting integer list is in rage 0 – 255:
170
+
`assert all(i in range(0, 256) for i in octets)`
171
+
4. Copy each of the resulting integers into a binary string of length 4 in network byte-order:
function available in many languages implements the previously mentioned binary
185
+
to string address transformation.
186
+
187
+
#### `ip6`
188
+
189
+
Encodes an IPv6 address according to the rules of [RFC 4291 section 2.2](https://tools.ietf.org/html/rfc4291#section-2.2) and [RFC 5962 section 4](https://tools.ietf.org/html/rfc5952#section-4).
190
+
191
+
Protocols using this codec must encode it as binary value of exactly 16 bytes without
192
+
an extra length value.
193
+
194
+
* String → Binary:
195
+
Parse the given input address string according to the rules of [RFC 4291 section 2.2](https://tools.ietf.org/html/rfc4291#section-2.2) creating a 16-byte binary string. All textual variations (upper-/lower-casing, IPv4-mapped addresses, zero-compression, stripping of leading zeros) must be supported by the parser. Note that [scoped IPv6 addressed containing a zone identifier](https://tools.ietf.org/html/draft-ietf-ipngwg-scopedaddr-format-02) may not appear in the input string; external mechanisms may be used to encode the zone identifier separately through.
196
+
* Binary → String:
197
+
Generate a canonical textual representation of the given binary input address according to rules of [RFC 5962 section 4](https://tools.ietf.org/html/rfc5952#section-4). Implementations must not produce any of the variations allowed by RFC 4291 mentioned above to ensure that all implementation produce a character by character identical string representation.
198
+
199
+
Converting between string to binary addresses should be done using the equivalent
200
+
of the POSIX [`inet_pton`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_pton.html)
201
+
and [`inet_ntop`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntop.html)
and [`getnameinfo` with `NI_NUMERICHOST`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/getnameinfo.html)
205
+
may be a viable alternative for some environments.
206
+
207
+
### `onion`
208
+
209
+
Encodes a [TOR rendezvous version 2 service pointer](https://gitweb.torproject.org/torspec.git/tree/rend-spec-v2.txt?id=471af27b55ff3894551109b45848f2ce1002441b#n525) (aka .onion-address) and exposed service port on that system.
210
+
211
+
Protocols using this codec must encode it as binary value of exactly 12 bytes without
212
+
an extra length value.
213
+
214
+
* String → Binary:
215
+
1. Split the input string into 2 parts at the colon character (U+003A COLON):
216
+
`(service_str, port_str) = str.split(":")`
217
+
2. Decode the *service* part before the colon using base32 into binary:
218
+
`service_bin = b32decode(service_str)`
219
+
3. Convert the *port* part to a binary string as specified by the [`uint16be`](#uint16be) codec.
220
+
4. Concatenate the service and port parts to obtain the final binary encoding:
221
+
`return service_bin + port_bin`
222
+
* Binary → String:
223
+
1. Split the binary value at the last two bytes into an service name and a port
224
+
number:
225
+
`(service_bin, port_bin) = binary.split_at(-2)`
226
+
2. Convert the service part into a base32 string:
227
+
`service_str = b32encode(service_bin)`
228
+
3. Convert the *port* part to text as specified by the [`uint16be`](#uint16be) codec.
229
+
4. Concatenate the result strings using a colon:
230
+
`return service_str + ":" + port_str`
231
+
232
+
### `p2p`
233
+
234
+
Encodes a libp2p node address.
235
+
236
+
TBD: Is this really always a base58btc encoded string of at least 5 characters in length!?
237
+
238
+
239
+
### `uint16be`
240
+
241
+
Encodes an unsigned 16-bit integer value (such as a port number) in network byte
242
+
order (big endian).
243
+
244
+
Protocols using this codec must encode it as binary value of exactly 2 bytes without
245
+
an extra length value.
246
+
247
+
* String → Binary:
248
+
1. Parse the input string as base-10 integer:
249
+
`integer = int(str, 10)`
250
+
2. Verify that the integer is in a valid range for a positive 16-bit integer:
251
+
`assert integer in range(65536)`
252
+
3. Convert the integer to a 2-byte long big endian binary string:
0 commit comments