summaryrefslogtreecommitdiff
path: root/data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js
diff options
context:
space:
mode:
authorClément Lassieur <clement@lassieur.org>2023-11-09 14:15:44 +0100
committerMark H Weaver <mhw@netris.org>2023-12-30 09:24:46 -0500
commitba0d2ab758143b9fe2ca14f6eed07d9a6a350c2b (patch)
tree0ecd8a30389110b49a8a1c1513332dbacfcb46f9 /data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js
parentf889514426e512e5602c71e1b411ae0332a33366 (diff)
Migrate from HTTPS-Everywhere to Icecat's own HTTPS-Only Mode.
See <https://www.eff.org/https-everywhere>. Modified-By: Mark H Weaver <mhw@netris.org>.
Diffstat (limited to 'data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js')
-rw-r--r--data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js71
1 files changed, 0 insertions, 71 deletions
diff --git a/data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js b/data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js
deleted file mode 100644
index 90e0b1a..0000000
--- a/data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js
+++ /dev/null
@@ -1,71 +0,0 @@
-'use strict';
-
-(function (exports) {
-
-/**
- * Parse and convert literal IP address into numerical IP address.
- * @param {string} ip
- * @returns {number}
- */
-const parseIp = ip => {
- if (!/^[0-9.]+$/.test(ip)) {
- return -1;
- }
-
- /** @type {string[]} */
- const octets = ip.split('.');
-
- if (octets.length !== 4) {
- return -1;
- }
-
- let ipN = 0;
-
- for (const octet of octets) {
- if (octet === '') {
- return -1;
- }
-
- const octetN = parseInt(octet);
-
- if (octetN < 0 || octetN > 255) {
- return -1;
- }
-
- ipN = (ipN << 8) | octetN;
- }
-
- return ipN >>> 0;
-};
-
-/**
- * Check if the numeric IP address is within a certain range.
- * @param {number} ip
- * @param {number[]} range
- * @returns {boolean}
- */
-const isIpInRange = (ip, [rangeIp, mask]) => (ip & mask) >>> 0 === rangeIp;
-
-// A list of local IP address ranges
-const localRanges = [
- [/* 0.0.0.0 */ 0x00000000, /* 255.255.255.255 */ 0xffffffff],
- [/* 127.0.0.0 */ 0x7f000000, /* 255.0.0.0 */ 0xff000000],
- [/* 10.0.0.0 */ 0x0a000000, /* 255.0.0.0 */ 0xff000000],
- [/* 172.16.0.0 */ 0xac100000, /* 255.240.0.0 */ 0xfff00000],
- [/* 192.168.0.0 */ 0xc0a80000, /* 255.255.0.0 */ 0xffff0000],
-];
-
-/**
- * Check if the numeric IP address is inside the local IP address ranges.
- * @param {number} ip
- * @returns {boolean}
- */
-const isLocalIp = ip => localRanges.some(range => isIpInRange(ip, range));
-
-Object.assign(exports, {
- parseIp,
- isIpInRange,
- isLocalIp
-});
-
-})(typeof exports !== 'undefined' ? exports : require.scopes.ip_utils = {});