Project files
This commit is contained in:
21
receipeServer/frontend_old/node_modules/@leichtgewicht/ip-codec/LICENSE
generated
vendored
Normal file
21
receipeServer/frontend_old/node_modules/@leichtgewicht/ip-codec/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Martin Heidegger
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
69
receipeServer/frontend_old/node_modules/@leichtgewicht/ip-codec/Readme.md
generated
vendored
Normal file
69
receipeServer/frontend_old/node_modules/@leichtgewicht/ip-codec/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
# @leichtgewicht/ip-codec
|
||||
|
||||
Small package to encode or decode IP addresses from buffers to strings.
|
||||
Supports IPV4 and IPV6.
|
||||
|
||||
## Usage
|
||||
|
||||
The basics are straigthforward
|
||||
|
||||
```js
|
||||
const { encode, decode, sizeOf, familyOf } = require('@leichtgewicht/ip-codec')
|
||||
|
||||
const uint8Array = encode("127.0.0.1")
|
||||
const str = decode(uint8Array)
|
||||
|
||||
try {
|
||||
switch sizeOf(str) {
|
||||
case 4: // IPv4
|
||||
case 16: // IPv6
|
||||
}
|
||||
switch familyOf(str) {
|
||||
case: 1: // IPv4
|
||||
case: 2: // IPv6
|
||||
}
|
||||
} catch (err) {
|
||||
// Invalid IP
|
||||
}
|
||||
```
|
||||
|
||||
By default the library will work with Uint8Array's but you can bring your own buffer:
|
||||
|
||||
```js
|
||||
const buf = Buffer.alloc(4)
|
||||
encode('127.0.0.1', buf)
|
||||
```
|
||||
|
||||
It is also possible to de-encode at a location inside a given buffer
|
||||
|
||||
```js
|
||||
const buf = Buffer.alloc(10)
|
||||
encode('127.0.0.1', buf, 4)
|
||||
```
|
||||
|
||||
Allocation of a buffer may be difficult if you don't know what type the buffer:
|
||||
you can pass in a generator to allocate it for you:
|
||||
|
||||
```js
|
||||
encode('127.0.0.1', Buffer.alloc)
|
||||
```
|
||||
|
||||
You can also de/encode ipv4 or ipv6 specifically:
|
||||
|
||||
```js
|
||||
const { v4, v6 } = require('@leichtgewicht/ip-codec')
|
||||
|
||||
v4.decode(v4.encode('127.0.0.1'))
|
||||
v6.decode(v6.encode('::'))
|
||||
```
|
||||
|
||||
## History
|
||||
|
||||
The code in this package was originally extracted from [node-ip](https://github.com/indutny/node-ip) and since improved.
|
||||
|
||||
Notable changes are the removal of the `Buffer` dependency and better support for detection of
|
||||
formats and allocation of buffers.
|
||||
|
||||
## License
|
||||
|
||||
[MIT](./LICENSE)
|
||||
202
receipeServer/frontend_old/node_modules/@leichtgewicht/ip-codec/index.js
generated
vendored
Normal file
202
receipeServer/frontend_old/node_modules/@leichtgewicht/ip-codec/index.js
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
const v4Regex = /^(\d{1,3}\.){3,3}\d{1,3}$/
|
||||
const v4Size = 4
|
||||
const v6Regex = /^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i
|
||||
const v6Size = 16
|
||||
|
||||
const v4 = {
|
||||
name: 'v4',
|
||||
size: v4Size,
|
||||
isFormat: ip => v4Regex.test(ip),
|
||||
encode (ip, buff, offset) {
|
||||
offset = ~~offset
|
||||
buff = buff || new Uint8Array(offset + v4Size)
|
||||
const max = ip.length
|
||||
let n = 0
|
||||
for (let i = 0; i < max;) {
|
||||
const c = ip.charCodeAt(i++)
|
||||
if (c === 46) { // "."
|
||||
buff[offset++] = n
|
||||
n = 0
|
||||
} else {
|
||||
n = n * 10 + (c - 48)
|
||||
}
|
||||
}
|
||||
buff[offset] = n
|
||||
return buff
|
||||
},
|
||||
decode (buff, offset) {
|
||||
offset = ~~offset
|
||||
return `${buff[offset++]}.${buff[offset++]}.${buff[offset++]}.${buff[offset]}`
|
||||
}
|
||||
}
|
||||
|
||||
const v6 = {
|
||||
name: 'v6',
|
||||
size: v6Size,
|
||||
isFormat: ip => ip.length > 0 && v6Regex.test(ip),
|
||||
encode (ip, buff, offset) {
|
||||
offset = ~~offset
|
||||
let end = offset + v6Size
|
||||
let fill = -1
|
||||
let hexN = 0
|
||||
let decN = 0
|
||||
let prevColon = true
|
||||
let useDec = false
|
||||
buff = buff || new Uint8Array(offset + v6Size)
|
||||
// Note: This algorithm needs to check if the offset
|
||||
// could exceed the buffer boundaries as it supports
|
||||
// non-standard compliant encodings that may go beyond
|
||||
// the boundary limits. if (offset < end) checks should
|
||||
// not be necessary...
|
||||
for (let i = 0; i < ip.length; i++) {
|
||||
let c = ip.charCodeAt(i)
|
||||
if (c === 58) { // :
|
||||
if (prevColon) {
|
||||
if (fill !== -1) {
|
||||
// Not Standard! (standard doesn't allow multiple ::)
|
||||
// We need to treat
|
||||
if (offset < end) buff[offset] = 0
|
||||
if (offset < end - 1) buff[offset + 1] = 0
|
||||
offset += 2
|
||||
} else if (offset < end) {
|
||||
// :: in the middle
|
||||
fill = offset
|
||||
}
|
||||
} else {
|
||||
// : ends the previous number
|
||||
if (useDec === true) {
|
||||
// Non-standard! (ipv4 should be at end only)
|
||||
// A ipv4 address should not be found anywhere else but at
|
||||
// the end. This codec also support putting characters
|
||||
// after the ipv4 address..
|
||||
if (offset < end) buff[offset] = decN
|
||||
offset++
|
||||
} else {
|
||||
if (offset < end) buff[offset] = hexN >> 8
|
||||
if (offset < end - 1) buff[offset + 1] = hexN & 0xff
|
||||
offset += 2
|
||||
}
|
||||
hexN = 0
|
||||
decN = 0
|
||||
}
|
||||
prevColon = true
|
||||
useDec = false
|
||||
} else if (c === 46) { // . indicates IPV4 notation
|
||||
if (offset < end) buff[offset] = decN
|
||||
offset++
|
||||
decN = 0
|
||||
hexN = 0
|
||||
prevColon = false
|
||||
useDec = true
|
||||
} else {
|
||||
prevColon = false
|
||||
if (c >= 97) {
|
||||
c -= 87 // a-f ... 97~102 -87 => 10~15
|
||||
} else if (c >= 65) {
|
||||
c -= 55 // A-F ... 65~70 -55 => 10~15
|
||||
} else {
|
||||
c -= 48 // 0-9 ... starting from charCode 48
|
||||
decN = decN * 10 + c
|
||||
}
|
||||
// We don't know yet if its a dec or hex number
|
||||
hexN = (hexN << 4) + c
|
||||
}
|
||||
}
|
||||
if (prevColon === false) {
|
||||
// Commiting last number
|
||||
if (useDec === true) {
|
||||
if (offset < end) buff[offset] = decN
|
||||
offset++
|
||||
} else {
|
||||
if (offset < end) buff[offset] = hexN >> 8
|
||||
if (offset < end - 1) buff[offset + 1] = hexN & 0xff
|
||||
offset += 2
|
||||
}
|
||||
} else if (fill === 0) {
|
||||
// Not Standard! (standard doesn't allow multiple ::)
|
||||
// This means that a : was found at the start AND end which means the
|
||||
// end needs to be treated as 0 entry...
|
||||
if (offset < end) buff[offset] = 0
|
||||
if (offset < end - 1) buff[offset + 1] = 0
|
||||
offset += 2
|
||||
} else if (fill !== -1) {
|
||||
// Non-standard! (standard doens't allow multiple ::)
|
||||
// Here we find that there has been a :: somewhere in the middle
|
||||
// and the end. To treat the end with priority we need to move all
|
||||
// written data two bytes to the right.
|
||||
offset += 2
|
||||
for (let i = Math.min(offset - 1, end - 1); i >= fill + 2; i--) {
|
||||
buff[i] = buff[i - 2]
|
||||
}
|
||||
buff[fill] = 0
|
||||
buff[fill + 1] = 0
|
||||
fill = offset
|
||||
}
|
||||
if (fill !== offset && fill !== -1) {
|
||||
// Move the written numbers to the end while filling the everything
|
||||
// "fill" to the bytes with zeros.
|
||||
if (offset > end - 2) {
|
||||
// Non Standard support, when the cursor exceeds bounds.
|
||||
offset = end - 2
|
||||
}
|
||||
while (end > fill) {
|
||||
buff[--end] = offset < end && offset > fill ? buff[--offset] : 0
|
||||
}
|
||||
} else {
|
||||
// Fill the rest with zeros
|
||||
while (offset < end) {
|
||||
buff[offset++] = 0
|
||||
}
|
||||
}
|
||||
return buff
|
||||
},
|
||||
decode (buff, offset) {
|
||||
offset = ~~offset
|
||||
let result = ''
|
||||
for (let i = 0; i < v6Size; i += 2) {
|
||||
if (i !== 0) {
|
||||
result += ':'
|
||||
}
|
||||
result += (buff[offset + i] << 8 | buff[offset + i + 1]).toString(16)
|
||||
}
|
||||
return result
|
||||
.replace(/(^|:)0(:0)*:0(:|$)/, '$1::$3')
|
||||
.replace(/:{3,4}/, '::')
|
||||
}
|
||||
}
|
||||
|
||||
function sizeOf (ip) {
|
||||
if (v4.isFormat(ip)) return v4.size
|
||||
if (v6.isFormat(ip)) return v6.size
|
||||
throw Error(`Invalid ip address: ${ip}`)
|
||||
}
|
||||
|
||||
module.exports = Object.freeze({
|
||||
name: 'ip',
|
||||
sizeOf,
|
||||
familyOf: string => sizeOf(string) === v4.size ? 1 : 2,
|
||||
v4,
|
||||
v6,
|
||||
encode (ip, buff, offset) {
|
||||
offset = ~~offset
|
||||
const size = sizeOf(ip)
|
||||
if (typeof buff === 'function') {
|
||||
buff = buff(offset + size)
|
||||
}
|
||||
if (size === v4.size) {
|
||||
return v4.encode(ip, buff, offset)
|
||||
}
|
||||
return v6.encode(ip, buff, offset)
|
||||
},
|
||||
decode (buff, offset, length) {
|
||||
offset = ~~offset
|
||||
length = length || (buff.length - offset)
|
||||
if (length === v4.size) {
|
||||
return v4.decode(buff, offset, length)
|
||||
}
|
||||
if (length === v6.size) {
|
||||
return v6.decode(buff, offset, length)
|
||||
}
|
||||
throw Error(`Invalid buffer size needs to be ${v4.size} for v4 or ${v6.size} for v6.`)
|
||||
}
|
||||
})
|
||||
38
receipeServer/frontend_old/node_modules/@leichtgewicht/ip-codec/package.json
generated
vendored
Normal file
38
receipeServer/frontend_old/node_modules/@leichtgewicht/ip-codec/package.json
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "@leichtgewicht/ip-codec",
|
||||
"version": "2.0.3",
|
||||
"description": "Small package to encode or decode IP addresses from buffers to strings.",
|
||||
"main": "index.js",
|
||||
"types": "types",
|
||||
"scripts": {
|
||||
"lint": "standard && dtslint --localTs node_modules/typescript/lib types",
|
||||
"test": "fresh-tape test.js",
|
||||
"test-cov": "c8 npm run test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/martinheidegger/ip-codec.git"
|
||||
},
|
||||
"keywords": [
|
||||
"ip",
|
||||
"ipv4",
|
||||
"ipv6",
|
||||
"codec",
|
||||
"codecs",
|
||||
"buffer",
|
||||
"conversion"
|
||||
],
|
||||
"author": "Martin Heidegger",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/martinheidegger/ip-codec/issues"
|
||||
},
|
||||
"homepage": "https://github.com/martinheidegger/ip-codec#readme",
|
||||
"devDependencies": {
|
||||
"c8": "^7.7.3",
|
||||
"dtslint": "^4.1.1",
|
||||
"fresh-tape": "^5.2.4",
|
||||
"standard": "^16.0.3",
|
||||
"typescript": "^4.3.5"
|
||||
}
|
||||
}
|
||||
258
receipeServer/frontend_old/node_modules/@leichtgewicht/ip-codec/test.js
generated
vendored
Normal file
258
receipeServer/frontend_old/node_modules/@leichtgewicht/ip-codec/test.js
generated
vendored
Normal file
@@ -0,0 +1,258 @@
|
||||
const test = require('fresh-tape')
|
||||
const Buffer = require('buffer').Buffer
|
||||
const { encode, decode, sizeOf, familyOf, v4, v6 } = require('.')
|
||||
const crypto = require('crypto')
|
||||
|
||||
test('IPv4 addresses tests', t => {
|
||||
t.ok(v4.isFormat('0.0.0.0'))
|
||||
t.ok(v4.isFormat('1.1.1.1'))
|
||||
t.ok(v4.isFormat('1.1.1.1'))
|
||||
t.ok(v4.isFormat('11.11.11.11'))
|
||||
t.ok(v4.isFormat('111.111.111.111'))
|
||||
t.ok(v4.isFormat('255.255.255.255'))
|
||||
t.notOk(v4.isFormat(''))
|
||||
t.notOk(v4.isFormat('1'))
|
||||
t.notOk(v4.isFormat('1.1.1'))
|
||||
t.notOk(v4.isFormat(' 1.1.1.1 '))
|
||||
t.notOk(v4.isFormat('1.1.1.1 '))
|
||||
t.notOk(v4.isFormat(' 1.1.1.1'))
|
||||
t.notOk(v4.isFormat('1000.1.1.1'))
|
||||
t.notOk(v4.isFormat('1.1000.1.1'))
|
||||
t.notOk(v4.isFormat('1.1.1000.1'))
|
||||
t.notOk(v4.isFormat('1.1.1.1000'))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('IPv6 addresses tests', t => {
|
||||
t.ok(v6.isFormat('0:0:0:0:0:0:0:0'), '8 octets')
|
||||
t.ok(v6.isFormat('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'), '8 full octets')
|
||||
t.ok(v6.isFormat('::'), 'expanding ::')
|
||||
t.ok(v6.isFormat('::1'), '0-9')
|
||||
t.ok(v6.isFormat('::f'), 'a-f')
|
||||
t.ok(v6.isFormat('::F'), 'upper characters need to match')
|
||||
t.ok(v6.isFormat('::ff'), '2 chars')
|
||||
t.ok(v6.isFormat('::fff'), '3 chars')
|
||||
t.ok(v6.isFormat('::ffff'), '4 chars')
|
||||
t.ok(v6.isFormat('::0:0:0:0:0:0:0'), 'expanding left')
|
||||
t.ok(v6.isFormat('0:0:0:0:0:0:0::'), 'expanding right')
|
||||
t.ok(v6.isFormat('0:0:0:0::0:0:0'), 'expanding middle')
|
||||
t.ok(v6.isFormat('::ffff:127.0.0.1'), 'ipv4 in v6')
|
||||
t.ok(v6.isFormat('::127.0.0.1')) // TODO: Likely non-standard?!
|
||||
t.notOk(v6.isFormat(' 0:0:0:0:0:0:0:0'), 'spaces')
|
||||
t.notOk(v6.isFormat('0:0:0:0:0:0:0:0 '), 'spaces')
|
||||
t.notOk(v6.isFormat('::g'), 'invalid v6')
|
||||
t.notOk(v6.isFormat('::g0'), 'invalid v6')
|
||||
t.notOk(v6.isFormat('::gg'), 'invalid v6')
|
||||
t.notOk(v6.isFormat('::g'), 'invalid v6')
|
||||
t.notOk(v6.isFormat('::ffff:127.0.0.1.1'), 'too many ipv4 numbers')
|
||||
t.notOk(v6.isFormat('::ffff:127.0.0'), 'incomplete ipv4')
|
||||
t.notOk(v6.isFormat('::ffff:127.0'), 'less complete ipv4')
|
||||
t.notOk(v6.isFormat('0:0:0:0:::0:0:0:0'), 'too much expansion')
|
||||
t.notOk(v6.isFormat('0:0:0:0:0:0:0:0:0'), 'too many octets')
|
||||
t.notOk(v6.isFormat('0:0:0:0:0:0:0:10000'), 'too many digits')
|
||||
t.notOk(v6.isFormat(':0:0:0:0:0:0:0:0'), '8 octets + expanding left')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should convert to buffer IPv4 address', t => {
|
||||
const buf = encode('127.0.0.1')
|
||||
t.equal(Buffer.from(buf).toString('hex'), '7f000001')
|
||||
t.equal(decode(buf), '127.0.0.1')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should convert to buffer IPv4 address in-place', t => {
|
||||
const buf = Buffer.alloc(128)
|
||||
const offset = 64
|
||||
encode('127.0.0.1', buf, offset)
|
||||
t.equal(buf.toString('hex', offset, offset + 4), '7f000001')
|
||||
t.equal(decode(buf, offset, 4), '127.0.0.1')
|
||||
|
||||
// Non-standard encodings that are technically working
|
||||
// Changing these would mean a breaking change...
|
||||
t.equal(decode(encode('256.0.0.0')), '0.0.0.0')
|
||||
t.equal(decode(encode('258.0.0.0')), '2.0.0.0')
|
||||
t.equal(decode(encode('0.534.0.0')), '0.22.0.0')
|
||||
t.equal(decode(encode('0.0.990.0')), '0.0.222.0')
|
||||
t.equal(decode(encode('0.0.0.671')), '0.0.0.159')
|
||||
// Zero prefixing is allowed, as the encoder supports it.
|
||||
// However we need to be aware that
|
||||
// https://datatracker.ietf.org/doc/html/rfc3986#section-7.4
|
||||
// clearly specifies that this is not a valid URI format.
|
||||
t.equal(decode(encode('01.0.0.0')), '1.0.0.0')
|
||||
t.equal(decode(encode('0.01.0.0')), '0.1.0.0')
|
||||
t.equal(decode(encode('0.0.01.0')), '0.0.1.0')
|
||||
t.equal(decode(encode('0.0.0.01')), '0.0.0.1')
|
||||
t.equal(decode(encode('001.0.0.0')), '1.0.0.0')
|
||||
t.equal(decode(encode('0.001.0.0')), '0.1.0.0')
|
||||
t.equal(decode(encode('0.0.001.0')), '0.0.1.0')
|
||||
t.equal(decode(encode('0.0.0.001')), '0.0.0.1')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should convert to buffer IPv6 address', t => {
|
||||
const buf = encode('::1')
|
||||
t.match(Buffer.from(buf).toString('hex'), /(00){15,15}01/)
|
||||
t.equal(decode(buf), '::1')
|
||||
testV6(t, '1::', '1::')
|
||||
testV6(t, 'abcd::dcba', 'abcd::dcba')
|
||||
testV6(t, 'ABCD::DCBA', 'abcd::dcba')
|
||||
testV6(t, '::ffff:c0a8:100', '::ffff:c0a8:100')
|
||||
testV6(t, '::ffff:ff00', '::ffff:ff00')
|
||||
|
||||
// Non-standard encodings that are technically working
|
||||
// Changing these would mean a breaking change...
|
||||
testV6(t, ':', '::', 'dangling colon')
|
||||
testV6(t, ':::', '::', 'colon parade?!')
|
||||
testV6(t, '::::::::::::::::::', '::', 'colon parade++')
|
||||
testV6(t, ':12', '::12', 'dangling colon at start')
|
||||
testV6(t, '12:', '12::', 'dangling colon at end')
|
||||
testV6(t, '1', '1::', '1 octet')
|
||||
testV6(t, '1:2', '1:2::', '2 octets')
|
||||
testV6(t, '1:2:3', '1:2:3::', '3 octets')
|
||||
testV6(t, '1:2:3:4', '1:2:3:4::', '4 octets')
|
||||
testV6(t, '1:2:3:4:5', '1:2:3:4:5::', '5 octets')
|
||||
testV6(t, '1:2:3:4:5:6', '1:2:3:4:5:6::', '6 octets')
|
||||
testV6(t, '1:2:3:4:5:6:7', '1:2:3:4:5:6:7:0', '7 octets')
|
||||
testV6(t, '1:2:3:4::5:6:7:8', '1:2:3:4:0:5:6:7', '8 octets + expanding')
|
||||
testV6(t, '1:2:3:4:5:6:7:8:', '1:2:3:4:5:6:7:8', '8 octets + expanding right')
|
||||
testV6(t, '12345678', '5678::', 'no colon between numbers')
|
||||
testV6(t, '::12345', '::2345', 'too many digits')
|
||||
testV6(t, '0111:0:0:0:0:0:0', '111::', '0 prefixing')
|
||||
testV6(t, '0011:0:0:0:0:0:0', '11::', '0 prefixing')
|
||||
testV6(t, '011:0:0:0:0:0:0', '11::', '0 prefixing')
|
||||
testV6(t, '001:0:0:0:0:0:0', '1::', '0 prefixing')
|
||||
testV6(t, '01:0:0:0:0:0:0', '1::', '0 prefixing')
|
||||
testV6(t, '0:01:0:0:0:0:0', '0:1::', '0 prefixing')
|
||||
testV6(t, '0:0:01:0:0:0:0', '::1:0:0:0:0:0', '0 prefixing')
|
||||
testV6(t, '0:0:0:01:0:0:0', '::1:0:0:0:0', '0 prefixing')
|
||||
testV6(t, '0:0:0:0:01:0:0', '::1:0:0:0', '0 prefixing')
|
||||
testV6(t, '0:0:0:0:0:01:0', '::1:0:0', '0 prefixing')
|
||||
testV6(t, '0:0:0:0:0:0:01', '::1:0', '0 prefixing')
|
||||
testV6(t, '0:0:0:0:0:0:001', '::1:0', '0 prefixing')
|
||||
testV6(t, '0:0:0:0:0:0:011', '::11:0', '0 prefixing')
|
||||
testV6(t, '0:0:0:0:0:0:0011', '::11:0', '0 prefixing')
|
||||
testV6(t, '0:0:0:0:0:0:0111', '::111:0', '0 prefixing')
|
||||
testV6(t, '::abcd::', '::abcd:0:0', ':: at end and start')
|
||||
testV6(t, '::abcd::9876', '::abcd:0:9876', ':: at middle and start')
|
||||
testV6(t, 'abcd::9876::', 'abcd:0:9876::', ':: at middle and end')
|
||||
testV6(t, '::abcd::9876::', '::abcd:0:9876:0:0', ':: everywhere')
|
||||
testV6(t, 'abcd::9876:123:', 'abcd:0:9876:123::', 'dangling colon + expansion')
|
||||
testV6(t, '123:::789::::456::::::', '123::789:0:0:0:456')
|
||||
testV6(t, 'abcd98764532', '4532::')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should convert to buffer IPv6 address in-place', t => {
|
||||
const buf = Buffer.alloc(128)
|
||||
const offset = 64
|
||||
encode('::1', buf, offset)
|
||||
t.ok(/(00){15,15}01/.test(buf.toString('hex', offset, offset + 16)))
|
||||
t.equal(decode(buf, offset, 16), '::1')
|
||||
t.equal(decode(encode('1::', buf, offset),
|
||||
offset, 16), '1::')
|
||||
t.equal(decode(encode('abcd::dcba', buf, offset),
|
||||
offset, 16), 'abcd::dcba')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should convert to buffer IPv6 mapped IPv4 address', t => {
|
||||
let buf = encode('::ffff:127.0.0.1')
|
||||
t.equal(Buffer.from(buf).toString('hex'), '00000000000000000000ffff7f000001')
|
||||
t.equal(decode(buf), '::ffff:7f00:1')
|
||||
|
||||
buf = encode('ffff::127.0.0.1')
|
||||
t.equal(Buffer.from(buf).toString('hex'), 'ffff000000000000000000007f000001')
|
||||
t.equal(decode(buf), 'ffff::7f00:1')
|
||||
|
||||
buf = encode('0:0:0:0:0:ffff:127.0.0.1')
|
||||
t.equal(Buffer.from(buf).toString('hex'), '00000000000000000000ffff7f000001')
|
||||
t.equal(decode(buf), '::ffff:7f00:1')
|
||||
|
||||
// Non-standard encodings that are technically working
|
||||
// Changing these would mean a breaking change...
|
||||
testV6(t, '127.0.0.1', '7f00:1::', 'ipv4 standalone')
|
||||
testV6(t, '127.0.0.1::', '7f00:1::', 'endling ::')
|
||||
testV6(t, '::127.0.0.1::', '::7f00:1:0:0', ':: start and end ::')
|
||||
testV6(t, ':0:ff::127.0.0.1::', '::ff:0:7f00:1:0:0', 'dangling double colon')
|
||||
testV6(t, ':0:ff::127.0.0.1:', '::ff:0:7f00:1:0', 'dangling colon')
|
||||
testV6(t, '127.0.0.1:::::::::::::', '7f00:1::', 'colon parade')
|
||||
testV6(t, '::ffff:999.0.0.1', '::ffff:e700:1', 'wrong ipv4')
|
||||
testV6(t, '::ffff:1.999.0.1', '::ffff:1e7:1', 'wrong ipv4')
|
||||
testV6(t, '::ffff:1.0.999.1', '::ffff:100:e701', 'wrong ipv4')
|
||||
testV6(t, '::ffff:1.0.0.999', '::ffff:100:e7', 'wrong ipv4')
|
||||
testV6(t, ':0:ff::999.1.1.1:', '::ff:0:e701:101:0', 'alt wrong ipv4')
|
||||
testV6(t, ':0:ff::1.999.1.1:', '::ff:0:1e7:101:0', 'alt wrong ipv4')
|
||||
testV6(t, ':0:ff::1.1.999.1:', '::ff:0:101:e701:0', 'alt wrong ipv4')
|
||||
testV6(t, ':0:ff::1.1.1.999:', '::ff:0:101:1e7:0', 'alt wrong ipv4')
|
||||
testV6(t, '127.0.0.1:0:0', '7f00:1::', 'ipv4 at the start')
|
||||
// the regular encoder would identify the ip as ipv4 here, using ipv6 instead
|
||||
t.equal(decode(v6.encode('127.0.0.1')), '7f00:1::', 'ipv4 as is shouldnt work')
|
||||
t.end()
|
||||
})
|
||||
|
||||
function testV6 (t, input, output, message) {
|
||||
message = `${input} → ${output}${message ? `- ${message}` : ''}`
|
||||
let result = v6.decode(v6.encode(input))
|
||||
// First, lets do a general en- & decode
|
||||
if (result === output) {
|
||||
// Then, use a own input buffer to make sure that all bytes are written
|
||||
result = v6.decode(v6.encode(input, crypto.randomBytes(v6.size), 0), 0)
|
||||
if (result === output) {
|
||||
// Then use a buffer that has random data before & after and write in the
|
||||
// middle to make sure that the implementation doesn't exceed bounds.
|
||||
// (Do this more than once to make sure randomness doesn't hide error
|
||||
let buffSlice, safeSlice
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const buff = crypto.randomBytes(v6.size + 8)
|
||||
const safe = Buffer.from(buff)
|
||||
v6.decode(v6.encode(input, buff, 4), 4)
|
||||
buffSlice = sliceBounds(buff)
|
||||
safeSlice = sliceBounds(safe)
|
||||
if (buffSlice !== safeSlice) {
|
||||
break
|
||||
}
|
||||
}
|
||||
t.equal(buffSlice, safeSlice, `${message} (verified)`)
|
||||
} else {
|
||||
t.equal(result, output, `${message} (0 offset byob)`)
|
||||
}
|
||||
} else {
|
||||
t.equal(result, output, message)
|
||||
}
|
||||
}
|
||||
|
||||
function sliceBounds (buff) {
|
||||
return Buffer.concat([buff.slice(0, 4), buff.slice(buff.length - 4)]).toString('hex')
|
||||
}
|
||||
|
||||
test('error decoding a buffer of unexpected length', t => {
|
||||
t.throws(() => decode(Buffer.alloc(0)))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should use on-demand allocation', t => {
|
||||
let buf = encode('127.0.0.1', Buffer.alloc)
|
||||
t.equal(buf.toString('hex'), '7f000001')
|
||||
buf = encode('127.0.0.1', size => Buffer.alloc(size + 2), 4)
|
||||
t.equal(buf.toString('hex'), '000000007f0000010000')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('dedicated encoding v4/v6', t => {
|
||||
t.deepEqual(encode('127.0.0.1'), v4.encode('127.0.0.1'))
|
||||
t.deepEqual(encode('::'), v6.encode('::'))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('sizeOf/familyOf test', t => {
|
||||
t.equal(sizeOf('127.0.0.1'), 4)
|
||||
t.equal(familyOf('127.0.0.1'), 1)
|
||||
t.equal(sizeOf('::'), 16)
|
||||
t.equal(familyOf('::'), 2)
|
||||
t.throws(() => sizeOf(''))
|
||||
t.throws(() => familyOf(''))
|
||||
t.throws(() => sizeOf('?'))
|
||||
t.throws(() => familyOf('?'))
|
||||
t.end()
|
||||
})
|
||||
26
receipeServer/frontend_old/node_modules/@leichtgewicht/ip-codec/types/index.d.ts
generated
vendored
Normal file
26
receipeServer/frontend_old/node_modules/@leichtgewicht/ip-codec/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
interface Encoder {
|
||||
(ip: string): Uint8Array;
|
||||
<TIn extends Uint8Array = Uint8Array> (ip: string, buff: TIn, offset?: number): TIn;
|
||||
}
|
||||
type Decoder = (ip: Uint8Array, offset?: number) => string;
|
||||
|
||||
interface Codec<TName extends string, TSize extends number> {
|
||||
name: TName;
|
||||
size: TSize;
|
||||
encode: Encoder;
|
||||
decode: Decoder;
|
||||
isFormat(ip: string): boolean;
|
||||
}
|
||||
|
||||
export function sizeOf(ip: string): 4 | 16;
|
||||
export function familyOf(ip: string): 1 | 2;
|
||||
export const v4: Codec<"ipv4", 4>;
|
||||
export const v6: Codec<"ipv6", 16>;
|
||||
export const name: "ip";
|
||||
export const encode: {
|
||||
(ip: string): Uint8Array;
|
||||
<TIn extends Uint8Array = Uint8Array> (ip: string, buff: TIn | ((size: number) => TIn), offset?: number): TIn
|
||||
};
|
||||
export function decode(ip: Uint8Array, offset?: number, length?: number): string;
|
||||
|
||||
export {};
|
||||
Reference in New Issue
Block a user