From 9308061a52d5063fce01dab9e2fdc9970ece03b8 Mon Sep 17 00:00:00 2001 From: EntropyFBC49934 Date: Mon, 20 Aug 2018 00:41:45 +0200 Subject: [PATCH 1/9] update buffer, change outdated dependency, add typescript declaration file --- .gitignore | 1 + index.d.ts | 413 ++++++ lib/Agents.js | 3 +- lib/auth/UserPassword.js | 10 +- lib/client.js | 6 +- lib/client.parser.js | 76 +- lib/server.js | 14 +- lib/server.parser.js | 8 +- lib/utils.js | 20 +- node_modules/ipv6/.npmignore | 3 - node_modules/ipv6/.travis.yml | 6 - node_modules/ipv6/LICENSE | 19 - node_modules/ipv6/README.md | 89 -- node_modules/ipv6/bin/ipv6.js | 39 - node_modules/ipv6/bin/ipv6grep.js | 74 - .../ipv6/examples/browser/simple.html | 29 - node_modules/ipv6/examples/node/simple.js | 5 - node_modules/ipv6/index.js | 1 - node_modules/ipv6/ipv6.js | 1314 ----------------- .../ipv6/lib/browser/jsbn-combined.js | 1211 --------------- node_modules/ipv6/lib/browser/jsbn.js | 559 ------- node_modules/ipv6/lib/browser/jsbn2.js | 648 -------- node_modules/ipv6/lib/browser/sprintf.js | 183 --- node_modules/ipv6/lib/node/bigint.js | 1255 ---------------- .../ipv6/node_modules/sprintf/.npmignore | 1 - .../ipv6/node_modules/sprintf/README.md | 23 - .../ipv6/node_modules/sprintf/lib/sprintf.js | 251 ---- .../ipv6/node_modules/sprintf/package.json | 48 - .../sprintf/test/function-export.js | 9 - node_modules/ipv6/package.json | 68 - node_modules/ipv6/test/address-test.js | 164 -- .../test/data/invalid-ipv4-addresses.json | 46 - .../test/data/invalid-ipv6-addresses.json | 1282 ---------------- .../ipv6/test/data/valid-ipv4-addresses.json | 22 - .../ipv6/test/data/valid-ipv6-addresses.json | 766 ---------- .../ipv6/test/functionality-v4-test.js | 175 --- .../ipv6/test/functionality-v6-test.js | 257 ---- node_modules/ipv6/test/unused/grep-test.txt | 17 - node_modules/ipv6/test/unused/regex-test.js | 21 - package-lock.json | 14 + package.json | 37 +- test/test-client-parser.js | 38 +- test/test-server-parser.js | 48 +- test/test-server.js | 2 +- 44 files changed, 568 insertions(+), 8707 deletions(-) create mode 100644 .gitignore create mode 100644 index.d.ts delete mode 100644 node_modules/ipv6/.npmignore delete mode 100644 node_modules/ipv6/.travis.yml delete mode 100644 node_modules/ipv6/LICENSE delete mode 100644 node_modules/ipv6/README.md delete mode 100644 node_modules/ipv6/bin/ipv6.js delete mode 100644 node_modules/ipv6/bin/ipv6grep.js delete mode 100644 node_modules/ipv6/examples/browser/simple.html delete mode 100644 node_modules/ipv6/examples/node/simple.js delete mode 100644 node_modules/ipv6/index.js delete mode 100644 node_modules/ipv6/ipv6.js delete mode 100644 node_modules/ipv6/lib/browser/jsbn-combined.js delete mode 100644 node_modules/ipv6/lib/browser/jsbn.js delete mode 100644 node_modules/ipv6/lib/browser/jsbn2.js delete mode 100644 node_modules/ipv6/lib/browser/sprintf.js delete mode 100644 node_modules/ipv6/lib/node/bigint.js delete mode 100644 node_modules/ipv6/node_modules/sprintf/.npmignore delete mode 100644 node_modules/ipv6/node_modules/sprintf/README.md delete mode 100644 node_modules/ipv6/node_modules/sprintf/lib/sprintf.js delete mode 100644 node_modules/ipv6/node_modules/sprintf/package.json delete mode 100644 node_modules/ipv6/node_modules/sprintf/test/function-export.js delete mode 100644 node_modules/ipv6/package.json delete mode 100644 node_modules/ipv6/test/address-test.js delete mode 100644 node_modules/ipv6/test/data/invalid-ipv4-addresses.json delete mode 100644 node_modules/ipv6/test/data/invalid-ipv6-addresses.json delete mode 100644 node_modules/ipv6/test/data/valid-ipv4-addresses.json delete mode 100644 node_modules/ipv6/test/data/valid-ipv6-addresses.json delete mode 100644 node_modules/ipv6/test/functionality-v4-test.js delete mode 100644 node_modules/ipv6/test/functionality-v6-test.js delete mode 100644 node_modules/ipv6/test/unused/grep-test.txt delete mode 100644 node_modules/ipv6/test/unused/regex-test.js create mode 100644 package-lock.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..5d719d4 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,413 @@ + +declare module "socksv5/lib/Agents" { + import { EventEmitter } from "events"; + import { Client, createConnection } from "socksv5/lib/client"; + + export interface SocksAgentOptions { + /** + * Keep sockets around in a pool to be used by other requests in the future. Default = false + */ + keepAlive?: boolean; + /** + * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000. + * Only relevant if keepAlive is set to true. + */ + keepAliveMsecs?: number; + /** + * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity + */ + maxSockets?: number; + /** + * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256. + */ + maxFreeSockets?: number; + } + + export interface SocksAgentNameOptions { + host?: string; + port?: number | string; + localAddress?: string; + } + + export interface SocksHttpsAgentNameOptions extends SocksAgentNameOptions { + ca?: string; + cert?: string; + ciphers?: string; + key?: string; + pfx?: string; + rejectUnauthorized?: string | undefined; + } + + export interface SocksNamedSocketList { + [key: string]: Client[]; + } + + export class Agent extends EventEmitter { + defaultPort: number; + protocol: string; + + keepAliveMsecs: number; + keepAlive: boolean; + maxSockets: number; + maxFreeSockets: number; + sockets: SocksNamedSocketList; + freeSockets: SocksNamedSocketList; + requests: any; + + constructor(options?: SocksAgentOptions); + + createConnection(port: number, host?: string, listener?: () => void): Client; + createConnection(path: string, listener?: () => void): Client; + + getName(options?: SocksAgentNameOptions): string; + + addRequest(req, options?: SocksAgentNameOptions): void; + createSocket(req, options): Client; + removeSocket(socket, options): void; + + destroy(): void; + } + + export class HttpsAgent extends Agent { } +} + +declare module "socksv5/lib/auth" { + import { Socket } from "net"; + + export interface AuthCallback { + (done: boolean): void; + (error: Error): void; + } + + export interface Auth { + client(stream: Socket, callback: AuthCallback): void; + server(stream: Socket, callback: AuthCallback): void; + } +} + +declare module "socksv5/lib/auth/None" { + import { Auth } from "socksv5/lib/auth"; + export default function None(): Auth; +} + +declare module "socksv5/lib/auth/UserPassword" { + import { Auth } from "socksv5/lib/auth"; + + export interface DoneCallback { + (success: boolean): void; + } + + export interface AuthCallback { + (username: string, password: string, callback: DoneCallback): void; + } + + export default function UserPassword(username: string, password: string): Auth; + export default function UserPassword(authCallback: AuthCallback): Auth; +} + +declare module "socksv5/lib/client" { + import { EventEmitter } from "events"; + + export interface SocksClientOptions { + host?: string; + port?: number; + localAddress?: string; + proxyHost?: string; + proxyPort?: number; + localDNS?: string; + strictLocalDNS?: string; + auths?: any[]; + } + + export class Client extends EventEmitter { + constructor(options?: SocksClientOptions); + + useAuth(auth: any): this; + + connect(options: SocksClientOptions, listener?: () => void): this; + connect(port: number, host?: string, listener?: () => void): this; + connect(path: string, listener?: () => void): this; + + addListener(event: string, listener: (...args: any[]) => void): this; + addListener(event: "close", listener: (had_error: boolean) => void): this; + addListener(event: "connect", listener: () => void): this; + addListener(event: "data", listener: (data: Buffer) => void): this; + addListener(event: "drain", listener: () => void): this; + addListener(event: "end", listener: () => void): this; + addListener(event: "error", listener: (err: Error) => void): this; + addListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; + addListener(event: "timeout", listener: () => void): this; + + emit(event: string | symbol, ...args: any[]): boolean; + emit(event: "close", had_error: boolean): boolean; + emit(event: "connect"): boolean; + emit(event: "data", data: Buffer): boolean; + emit(event: "drain"): boolean; + emit(event: "end"): boolean; + emit(event: "error", err: Error): boolean; + emit(event: "lookup", err: Error, address: string, family: string | number, host: string): boolean; + emit(event: "timeout"): boolean; + + on(event: string, listener: (...args: any[]) => void): this; + on(event: "close", listener: (had_error: boolean) => void): this; + on(event: "connect", listener: () => void): this; + on(event: "data", listener: (data: Buffer) => void): this; + on(event: "drain", listener: () => void): this; + on(event: "end", listener: () => void): this; + on(event: "error", listener: (err: Error) => void): this; + on(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; + on(event: "timeout", listener: () => void): this; + + once(event: string, listener: (...args: any[]) => void): this; + once(event: "close", listener: (had_error: boolean) => void): this; + once(event: "connect", listener: () => void): this; + once(event: "data", listener: (data: Buffer) => void): this; + once(event: "drain", listener: () => void): this; + once(event: "end", listener: () => void): this; + once(event: "error", listener: (err: Error) => void): this; + once(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; + once(event: "timeout", listener: () => void): this; + + prependListener(event: string, listener: (...args: any[]) => void): this; + prependListener(event: "close", listener: (had_error: boolean) => void): this; + prependListener(event: "connect", listener: () => void): this; + prependListener(event: "data", listener: (data: Buffer) => void): this; + prependListener(event: "drain", listener: () => void): this; + prependListener(event: "end", listener: () => void): this; + prependListener(event: "error", listener: (err: Error) => void): this; + prependListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; + prependListener(event: "timeout", listener: () => void): this; + + prependOnceListener(event: string, listener: (...args: any[]) => void): this; + prependOnceListener(event: "close", listener: (had_error: boolean) => void): this; + prependOnceListener(event: "connect", listener: () => void): this; + prependOnceListener(event: "data", listener: (data: Buffer) => void): this; + prependOnceListener(event: "drain", listener: () => void): this; + prependOnceListener(event: "end", listener: () => void): this; + prependOnceListener(event: "error", listener: (err: Error) => void): this; + prependOnceListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; + prependOnceListener(event: "timeout", listener: () => void): this; + } + + export function connect(port: number, host?: string, listener?: () => void): Client; + export function connect(path: string, listener?: () => void): Client; + export function createConnection(port: number, host?: string, listener?: () => void): Client; + export function createConnection(path: string, listener?: () => void): Client; +} + +declare module "socksv5/lib/client.parser" { + import { Socket } from "net"; + import { EventEmitter } from "events"; + import { SocksBoundAddress, SocksProxyInfo } from "socksv5"; + + export default class Parser extends EventEmitter { + constructor(stream: Socket); + start(): void; + stop(): void; + + addListener(event: string, listener: (...args: any[]) => void): this; + addListener(event: "method", listener: (method: number) => void); + addListener(event: "reply", listener: (info: SocksBoundAddress) => void); + addListener(event: "error", listener: (err: Error) => void); + + emit(event: string | symbol, ...args: any[]): boolean; + emit(event: "method", method: number): boolean; + emit(event: "request", info: SocksProxyInfo): boolean; + emit(event: "error", err: Error): boolean; + + on(event: string, listener: (...args: any[]) => void): this; + on(event: "method", listener: (method: number) => void); + on(event: "reply", listener: (info: SocksBoundAddress) => void); + on(event: "error", listener: (err: Error) => void); + + once(event: string, listener: (...args: any[]) => void): this; + once(event: "method", listener: (method: number) => void); + once(event: "reply", listener: (info: SocksBoundAddress) => void); + once(event: "error", listener: (err: Error) => void); + + prependListener(event: string, listener: (...args: any[]) => void): this; + prependListener(event: "method", listener: (method: number) => void); + prependListener(event: "reply", listener: (info: SocksBoundAddress) => void); + prependListener(event: "error", listener: (err: Error) => void); + + prependOnceListener(event: string, listener: (...args: any[]) => void): this; + prependOnceListener(event: "method", listener: (method: number) => void); + prependOnceListener(event: "reply", listener: (info: SocksBoundAddress) => void); + prependOnceListener(event: "error", listener: (err: Error) => void); + } +} + +declare module "socksv5/lib/constants" { + + interface SocksCMD { + CONNECT: number; + BIND: number; + UDP: number; + } + + interface SocksATYP { + IPv4: number; + NAME: number; + IPv6: number; + } + + interface SocksREP { + SUCCESS: number; + GENFAIL: number; + DISALLOW: number; + NETUNREACH: number; + HOSTUNREACH: number; + CONNREFUSED: number; + TTLEXPIRED: number; + CMDUNSUPP: number; + ATYPUNSUPP: number; + } + + export const CMD: SocksCMD; + export const ATYP: SocksATYP; + export const REP: SocksREP; +} + +declare module "socksv5/lib/server" { + import { EventEmitter } from "events"; + import { Auth } from "socksv5/lib/auth"; + import { Socket, AddressInfo } from "net"; + import { SocksProxyInfo } from "socksv5"; + + export interface SocksAcceptCallback { + (intercept?: false): void; + (intercept: true): Socket; + } + + export interface SocksConnectionCallback { + (info: SocksProxyInfo, accept: SocksAcceptCallback, deny: () => void); + } + + export interface SocksServerOptions { + allowHalfOpen?: boolean; + pauseOnConnect?: boolean; + auths?: Auth[]; + debug?: boolean; + } + + export class Server extends EventEmitter { + constructor(connectionCallback: SocksConnectionCallback); + constructor(options?: SocksServerOptions, connectionCallback?: SocksConnectionCallback); + + useAuth(auth: Auth): this; + + address(): AddressInfo | string; + close(callback?: Function): this; + getConnections(cb: (error: Error | null, count: number) => void): void; + + listen(port: number, host?: string, listeningCallback?: () => void): this; + listen(path: string, listeningCallback?: () => void): this; + + ref(): this; + unref(): this; + + addListener(event: string, listener: (...args: any[]) => void): this; + addListener(event: "close", listener: () => void): this; + addListener(event: "connection", listener: (socket: Socket) => void): this; + addListener(event: "error", listener: (err: Error) => void): this; + addListener(event: "listening", listener: () => void): this; + + emit(event: string | symbol, ...args: any[]): boolean; + emit(event: "close"): boolean; + emit(event: "connection", socket: Socket): boolean; + emit(event: "error", err: Error): boolean; + emit(event: "listening"): boolean; + + on(event: string, listener: (...args: any[]) => void): this; + on(event: "close", listener: () => void): this; + on(event: "connection", listener: (socket: Socket) => void): this; + on(event: "error", listener: (err: Error) => void): this; + on(event: "listening", listener: () => void): this; + + once(event: string, listener: (...args: any[]) => void): this; + once(event: "close", listener: () => void): this; + once(event: "connection", listener: (socket: Socket) => void): this; + once(event: "error", listener: (err: Error) => void): this; + once(event: "listening", listener: () => void): this; + + prependListener(event: string, listener: (...args: any[]) => void): this; + prependListener(event: "close", listener: () => void): this; + prependListener(event: "connection", listener: (socket: Socket) => void): this; + prependListener(event: "error", listener: (err: Error) => void): this; + prependListener(event: "listening", listener: () => void): this; + + prependOnceListener(event: string, listener: (...args: any[]) => void): this; + prependOnceListener(event: "close", listener: () => void): this; + prependOnceListener(event: "connection", listener: (socket: Socket) => void): this; + prependOnceListener(event: "error", listener: (err: Error) => void): this; + prependOnceListener(event: "listening", listener: () => void): this; + } + + export function createServer(): Server; + export function createServer(connectionListener: SocksConnectionCallback): Server; + export function createServer(options: SocksServerOptions, connectionListener: SocksConnectionCallback): Server; +} + +declare module "socksv5/lib/server.parser" { + import { Socket } from "net"; + import { SocksProxyInfo, SocksBoundAddress } from "socksv5"; + export default class Parser { + constructor(stream: Socket); + start(): void; + stop(): void; + + addListener(event: string, listener: (...args: any[]) => void): this; + addListener(event: "methods", listener: (methods: Buffer) => void); + addListener(event: "request", listener: (info: SocksProxyInfo) => void); + addListener(event: "error", listener: (err: Error) => void); + + emit(event: string | symbol, ...args: any[]): boolean; + emit(event: "methods", methods: Buffer): boolean; + emit(event: "request", info: SocksProxyInfo): boolean; + emit(event: "error", err: Error): boolean; + + on(event: string, listener: (...args: any[]) => void): this; + on(event: "methods", listener: (methods: Buffer) => void); + on(event: "request", listener: (info: SocksProxyInfo) => void); + on(event: "error", listener: (err: Error) => void); + + once(event: string, listener: (...args: any[]) => void): this; + once(event: "methods", listener: (methods: Buffer) => void); + once(event: "request", listener: (info: SocksProxyInfo) => void); + once(event: "error", listener: (err: Error) => void); + + prependListener(event: string, listener: (...args: any[]) => void): this; + prependListener(event: "methods", listener: (methods: Buffer) => void); + prependListener(event: "request", listener: (info: SocksProxyInfo) => void); + prependListener(event: "error", listener: (err: Error) => void); + + prependOnceListener(event: string, listener: (...args: any[]) => void): this; + prependOnceListener(event: "methods", listener: (methods: Buffer) => void); + prependOnceListener(event: "request", listener: (info: SocksProxyInfo) => void); + prependOnceListener(event: "error", listener: (err: Error) => void); + } +} + +declare module "socksv5" { + import None from "socksv5/lib/auth/None"; + import UserPassword from "socksv5/lib/auth/UserPassword"; + + export interface SocksBoundAddress { + bndAddr: string; + bndPort: number; + } + + export interface SocksProxyInfo { + cmd: string; + srcAddr?: string | undefined; + srcPort?: number | undefined; + dstAddr: string; + dstPort: number; + } + + export * from "socksv5/lib/Agents"; + export * from "socksv5/lib/client"; + export * from "socksv5/lib/server"; + + export const auth: { None, UserPassword }; +} \ No newline at end of file diff --git a/lib/Agents.js b/lib/Agents.js index 6d79453..ed772ed 100644 --- a/lib/Agents.js +++ b/lib/Agents.js @@ -23,7 +23,6 @@ var socks = require('../index'); -var net = require('net'); var tls = require('tls'); var util = require('util'); var EventEmitter = require('events').EventEmitter; @@ -315,6 +314,8 @@ function HttpsAgent(options) { } util.inherits(HttpsAgent, Agent); exports.HttpsAgent = HttpsAgent; + +// TODO: probably an artifact. Should be deleted. HttpsAgent.prototype.createConnection = function(port, host, options) { if (typeof port === 'object' && port !== null) { options = port; diff --git a/lib/auth/UserPassword.js b/lib/auth/UserPassword.js index 0f17eb9..5feb972 100644 --- a/lib/auth/UserPassword.js +++ b/lib/auth/UserPassword.js @@ -8,8 +8,8 @@ var STATE_VERSION = 0, STATE_STATUS = 5; // server -var BUF_SUCCESS = new Buffer([0x01, 0x00]), - BUF_FAILURE = new Buffer([0x01, 0x01]); +var BUF_SUCCESS = Buffer.from([0x01, 0x00]), + BUF_FAILURE = Buffer.from([0x01, 0x01]); module.exports = function UserPasswordAuthHandlers() { var authcb, @@ -75,7 +75,7 @@ module.exports = function UserPasswordAuthHandlers() { } ++i; ++state; - user = new Buffer(ulen); + user = Buffer.alloc(ulen); userp = 0; break; case STATE_UNAME: @@ -102,7 +102,7 @@ module.exports = function UserPasswordAuthHandlers() { } ++i; ++state; - pass = new Buffer(plen); + pass = Buffer.alloc(plen); passp = 0; break; case STATE_PASSWD: @@ -178,7 +178,7 @@ module.exports = function UserPasswordAuthHandlers() { } stream.on('data', onData); - var buf = new Buffer(3 + userlen + passlen); + var buf = Buffer.alloc(3 + userlen + passlen); buf[0] = 0x01; buf[1] = userlen; buf.write(user, 2, userlen); diff --git a/lib/client.js b/lib/client.js index ff212e5..3e0ccb6 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,5 +1,5 @@ var net = require('net'), - normalizeConnectArgs = net._normalizeConnectArgs, + normalizeConnectArgs = net._normalizeArgs, dns = require('dns'), util = require('util'), inherits = util.inherits, @@ -66,7 +66,7 @@ Client.prototype._onConnect = function() { var auths = self._auths, alen = auths.length, - authsbuf = new Buffer(2 + alen); + authsbuf = Buffer.alloc(2 + alen); authsbuf[0] = 0x05; authsbuf[1] = alen; for (var a = 0, p = 2; a < alen; ++a, ++p) @@ -123,7 +123,7 @@ Client.prototype._sendRequest = function() { var addrlen = (iptype === 0 ? Buffer.byteLength(self._dstaddr) : (iptype === 4 ? 4 : 16)), - reqbuf = new Buffer(6 + (iptype === 0 ? 1 : 0) + addrlen), + reqbuf = Buffer.alloc(6 + (iptype === 0 ? 1 : 0) + addrlen), p; reqbuf[0] = 0x05; reqbuf[1] = CMD.CONNECT; diff --git a/lib/client.parser.js b/lib/client.parser.js index 7763b4f..45538ac 100644 --- a/lib/client.parser.js +++ b/lib/client.parser.js @@ -1,20 +1,20 @@ var inherits = require('util').inherits, - EventEmitter = require('events').EventEmitter; + EventEmitter = require('events').EventEmitter; var ATYP = require('./constants').ATYP, - REP = require('./constants').REP; + REP = require('./constants').REP; var STATE_VERSION = 0, - STATE_METHOD = 1, - STATE_REP_STATUS = 2, - STATE_REP_RSV = 3, - STATE_REP_ATYP = 4, - STATE_REP_BNDADDR = 5, - STATE_REP_BNDADDR_VARLEN = 6, - STATE_REP_BNDPORT = 7; + STATE_METHOD = 1, + STATE_REP_STATUS = 2, + STATE_REP_RSV = 3, + STATE_REP_ATYP = 4, + STATE_REP_BNDADDR = 5, + STATE_REP_BNDADDR_VARLEN = 6, + STATE_REP_BNDPORT = 7; var ERRORS = {}, - ERROR_UNKNOWN = ['unknown error', 'EUNKNOWN']; + ERROR_UNKNOWN = ['unknown error', 'EUNKNOWN']; ERRORS[REP.GENFAIL] = ['general SOCKS server failure', 'EGENFAIL']; ERRORS[REP.DISALLOW] = ['connection not allowed by ruleset', 'EACCES']; ERRORS[REP.NETUNREACH] = ['network is unreachable', 'ENETUNREACH']; @@ -29,7 +29,7 @@ function Parser(stream) { this._stream = stream; this._listening = false; - this.__onData = function(chunk) { + this.__onData = function (chunk) { self._onData(chunk); }; @@ -45,13 +45,13 @@ function Parser(stream) { } inherits(Parser, EventEmitter); -Parser.prototype._onData = function(chunk) { +Parser.prototype._onData = function (chunk) { var state = this._state, - i = 0, - len = chunk.length, - left, - chunkLeft, - minLen; + i = 0, + len = chunk.length, + left, + chunkLeft, + minLen; while (i < len) { switch (state) { @@ -65,8 +65,8 @@ Parser.prototype._onData = function(chunk) { case STATE_VERSION: if (chunk[i] !== 0x05) { this.emit('error', - new Error('Incompatible SOCKS protocol version: ' - + chunk[i])); + new Error('Incompatible SOCKS protocol version: ' + + chunk[i])); return; } ++i; @@ -74,7 +74,7 @@ Parser.prototype._onData = function(chunk) { state = STATE_REP_STATUS; else ++state; - break; + break; case STATE_METHOD: var method = chunk[i]; ++i; @@ -84,7 +84,7 @@ Parser.prototype._onData = function(chunk) { this._stream.unshift(chunk.slice(i)); this.emit('method', method); return; - break; + break; // ======================================================================= /* +----+-----+-------+------+----------+----------+ @@ -119,7 +119,7 @@ Parser.prototype._onData = function(chunk) { var status = chunk[i]; if (status !== REP.SUCCESS) { var errinfo = ERRORS[status] || ERROR_UNKNOWN, - err = new Error(errinfo[0]); + err = new Error(errinfo[0]); err.code = errinfo[1]; this.stop(); @@ -128,47 +128,47 @@ Parser.prototype._onData = function(chunk) { } ++i; ++state; - break; + break; case STATE_REP_RSV: ++i; ++state; - break; + break; case STATE_REP_ATYP: var atyp = chunk[i]; state = STATE_REP_BNDADDR; if (atyp === ATYP.IPv4) - this._bndaddr = new Buffer(4); + this._bndaddr = Buffer.alloc(4); else if (atyp === ATYP.IPv6) - this._bndaddr = new Buffer(16); + this._bndaddr = Buffer.alloc(16); else if (atyp === ATYP.NAME) state = STATE_REP_BNDADDR_VARLEN; else { this.stop(); this.emit('error', - new Error('Invalid request address type: ' + atyp)); + new Error('Invalid request address type: ' + atyp)); return; } this._atyp = atyp; ++i; - break; + break; case STATE_REP_BNDADDR: left = this._bndaddr.length - this._bndaddrp; chunkLeft = len - i; minLen = (left < chunkLeft ? left : chunkLeft); chunk.copy(this._bndaddr, - this._bndaddrp, - i, - i + minLen); + this._bndaddrp, + i, + i + minLen); this._bndaddrp += minLen; i += minLen; if (this._bndaddrp === this._bndaddr.length) state = STATE_REP_BNDPORT; - break; + break; case STATE_REP_BNDADDR_VARLEN: - this._bndaddr = new Buffer(chunk[i]); + this._bndaddr = Buffer.alloc(chunk[i]); state = STATE_REP_BNDADDR; ++i; - break; + break; case STATE_REP_BNDPORT: if (this._bndport === undefined) this._bndport = chunk[i]; @@ -185,7 +185,7 @@ Parser.prototype._onData = function(chunk) { this._bndaddr = Array.prototype.join.call(this._bndaddr, '.'); else if (this._atyp === ATYP.IPv6) { var ipv6str = '', - addr = this._bndaddr; + addr = this._bndaddr; for (var b = 0; b < 16; ++b) { if (b % 2 === 0 && b > 0) ipv6str += ':'; @@ -202,7 +202,7 @@ Parser.prototype._onData = function(chunk) { return; } ++i; - break; + break; // =================================================================== } } @@ -210,7 +210,7 @@ Parser.prototype._onData = function(chunk) { this._state = state; }; -Parser.prototype.start = function() { +Parser.prototype.start = function () { if (this._listening) return; this._listening = true; @@ -218,7 +218,7 @@ Parser.prototype.start = function() { this._stream.resume(); }; -Parser.prototype.stop = function() { +Parser.prototype.stop = function () { if (!this._listening) return; this._listening = false; diff --git a/lib/server.js b/lib/server.js index bcac647..cc75a80 100644 --- a/lib/server.js +++ b/lib/server.js @@ -10,15 +10,15 @@ var Parser = require('./server.parser'), var ATYP = require('./constants').ATYP, REP = require('./constants').REP; -var BUF_AUTH_NO_ACCEPT = new Buffer([0x05, 0xFF]), - BUF_REP_INTR_SUCCESS = new Buffer([0x05, +var BUF_AUTH_NO_ACCEPT = Buffer.from([0x05, 0xFF]), + BUF_REP_INTR_SUCCESS = Buffer.from([0x05, REP.SUCCESS, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), - BUF_REP_DISALLOW = new Buffer([0x05, REP.DISALLOW]), - BUF_REP_CMDUNSUPP = new Buffer([0x05, REP.CMDUNSUPP]); + BUF_REP_DISALLOW = Buffer.from([0x05, REP.DISALLOW]), + BUF_REP_CMDUNSUPP = Buffer.from([0x05, REP.CMDUNSUPP]); function Server(options, listener) { if (!(this instanceof Server)) @@ -86,7 +86,7 @@ Server.prototype._onConnection = function(socket) { socket.end(); } }); - socket.write(new Buffer([0x05, auths[a].METHOD])); + socket.write(Buffer.from([0x05, auths[a].METHOD])); socket.resume(); return; } @@ -215,7 +215,7 @@ function proxySocket(socket, req) { if (socket.writable) { var localbytes = ipbytes(dstSock.localAddress || '127.0.0.1'), len = localbytes.length, - bufrep = new Buffer(6 + len), + bufrep = Buffer.alloc(6 + len), p = 4; bufrep[0] = 0x05; bufrep[1] = REP.SUCCESS; @@ -238,7 +238,7 @@ function proxySocket(socket, req) { function handleProxyError(socket, err) { if (socket.writable) { - var errbuf = new Buffer([0x05, REP.GENFAIL]); + var errbuf = Buffer.from([0x05, REP.GENFAIL]); if (err.code) { switch (err.code) { case 'ENOENT': diff --git a/lib/server.parser.js b/lib/server.parser.js index 025d6b8..2c235e4 100644 --- a/lib/server.parser.js +++ b/lib/server.parser.js @@ -76,7 +76,7 @@ Parser.prototype._onData = function(chunk) { } ++i; ++state; - this._methods = new Buffer(nmethods); + this._methods = Buffer.alloc(nmethods); this._methodsp = 0; break; case STATE_METHODS: @@ -148,9 +148,9 @@ Parser.prototype._onData = function(chunk) { var atyp = chunk[i]; state = STATE_REQ_DSTADDR; if (atyp === ATYP.IPv4) - this._dstaddr = new Buffer(4); + this._dstaddr = Buffer.alloc(4); else if (atyp === ATYP.IPv6) - this._dstaddr = new Buffer(16); + this._dstaddr = Buffer.alloc(16); else if (atyp === ATYP.NAME) state = STATE_REQ_DSTADDR_VARLEN; else { @@ -176,7 +176,7 @@ Parser.prototype._onData = function(chunk) { state = STATE_REQ_DSTPORT; break; case STATE_REQ_DSTADDR_VARLEN: - this._dstaddr = new Buffer(chunk[i]); + this._dstaddr = Buffer.alloc(chunk[i]); state = STATE_REQ_DSTADDR; ++i; break; diff --git a/lib/utils.js b/lib/utils.js index b5c2457..cf840d1 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,11 +1,11 @@ -var net = require('net'), - ipv6 = require('ipv6').v6; +const net = require('net'); +const { Address6 } = require('ip-address'); -exports.ipbytes = function(str) { - var type = net.isIP(str), - nums, - bytes, - i; +exports.ipbytes = function (str) { + const type = net.isIP(str); + let nums; + let bytes; + let i; if (type === 4) { nums = str.split('.', 4); @@ -15,9 +15,9 @@ exports.ipbytes = function(str) { throw new Error('Error parsing IP: ' + str); } } else if (type === 6) { - var addr = new ipv6.Address(str), - b = 0, - group; + var addr = new Address6(str), + b = 0, + group; if (!addr.valid) throw new Error('Error parsing IP: ' + str); nums = addr.parsedAddress; diff --git a/node_modules/ipv6/.npmignore b/node_modules/ipv6/.npmignore deleted file mode 100644 index c79b932..0000000 --- a/node_modules/ipv6/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -*/*.swp -node_modules -npm-debug.log diff --git a/node_modules/ipv6/.travis.yml b/node_modules/ipv6/.travis.yml deleted file mode 100644 index 4ad4411..0000000 --- a/node_modules/ipv6/.travis.yml +++ /dev/null @@ -1,6 +0,0 @@ -language: node_js -node_js: - - 0.6 - - 0.8 - - 0.10 - - 0.11 diff --git a/node_modules/ipv6/LICENSE b/node_modules/ipv6/LICENSE deleted file mode 100644 index ec79adb..0000000 --- a/node_modules/ipv6/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (C) 2011 by Beau Gunderson - -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. diff --git a/node_modules/ipv6/README.md b/node_modules/ipv6/README.md deleted file mode 100644 index 355dba6..0000000 --- a/node_modules/ipv6/README.md +++ /dev/null @@ -1,89 +0,0 @@ -javascript-ipv6 [![Build Status](https://secure.travis-ci.org/beaugunderson/javascript-ipv6.png?branch=master)](http://travis-ci.org/beaugunderson/javascript-ipv6) -=============== - -javascript-ipv6 is a library for manipulating IPv6 addresses in JavaScript. - -Examples --------- - -For node: - -```js -var v6 = require('ipv6').v6; - -var address = new v6.Address('2001:0:ce49:7601:e866:efff:62c3:fffe'); - -console.log(address.isValid()); // Prints "true" - -var teredo = address.teredo(); - -console.log(teredo.client4); // Prints "157.60.0.1" -``` - -For a browser: - -```html - - - - Simple IPv6 test - - - - - - - - - - - - - - - The canonical form of a::b is: - - -``` - -Current functionality ---------------------- - -- Parsing of most IPv6 notations -- Parsing of IPv6 Addresses and Ports from URLs with `v6.Address.fromURL(url)` -- Validity checking -- Decoding of the [Teredo information](http://en.wikipedia.org/wiki/Teredo_tunneling#IPv6_addressing) in an address -- Whether one address is a valid subnet of another -- What special properties a given address has (multicast prefix, unique local address prefix, etc.) -- Number of subnets of a certain size in a given address -- Display methods - - Hex, binary, and decimal - - Canonical form - - Correct form - - IPv4-compatible (i.e. `::ffff:192.168.0.1`) -- Works in [node.js](http://nodejs.org/) and the browser -- Unit tests with [node.js](http://nodejs.org/) and [Mocha](http://visionmedia.github.com/mocha/) - -Used by -------- - -- [Rackspace](http://www.rackspace.com/) in [node-swiz](https://github.com/racker/node-swiz) -- [node-socksified](https://github.com/vially/node-socksified) - -Future functionality --------------------- - -- Investigate `procstreams` for the CLI tool -- Base 64/85 encoding? -- Reverse lookups? (Whether a domain name has IPv6 glue) - -TODO ----- - -- Documentation diff --git a/node_modules/ipv6/bin/ipv6.js b/node_modules/ipv6/bin/ipv6.js deleted file mode 100644 index 8385465..0000000 --- a/node_modules/ipv6/bin/ipv6.js +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env node - -var v6 = require('../ipv6.js').v6; -var v4 = require('../ipv6.js').v4; - -var sprintf = require('sprintf').sprintf; -var cli = require('cli'); -var cliff = require('cliff'); - -var options = cli.parse(); - -var rows = [['Address', 'Valid', 'Correct Form', 'Canonical Form']]; - -cli.withStdinLines(function(lines, newline) { - for (var i = 0; i < lines.length; i++) { - if (lines[i] == '') { - continue; - } - - var address = new v6.Address(lines[i]); - - if (options.v) { - this.output(sprintf('%s = %s\n', lines[i], cliff.inspect(address))); - } else if (options.c) { - rows.push([ - lines[i], - address.isValid() ? 'Yes' : 'No'.red, - address.isValid() ? address.correctForm() : '', - address.isValid() ? address.canonicalForm() : '' - ]); - } else { - this.output(sprintf('%s,%s\n', lines[i], address.isValid() ? 'valid' : 'invalid')); - } - } - - if (options.c) { - console.log(cliff.stringifyRows(rows, ['green', 'green', 'green', 'green'])); - } -}); diff --git a/node_modules/ipv6/bin/ipv6grep.js b/node_modules/ipv6/bin/ipv6grep.js deleted file mode 100644 index 3586e05..0000000 --- a/node_modules/ipv6/bin/ipv6grep.js +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env node - -var v6 = require('../ipv6.js').v6; -var v4 = require('../ipv6.js').v4; - -var sprintf = require('sprintf').sprintf; -var cli = require('cli'); -var cliff = require('cliff'); - -var util = require('util'); -var spawn = require('child_process').spawn; - -cli.enable('version', 'status', 'glob'); - -cli.parse({ - all: ['a', 'Find all addresses'], - validate: ['v', 'Validate found addresses'], - substring: ['s', 'Substring match'] -}); - -cli.debug('script: ' + process.ARGV[1]); - -cli.main(function(args, options) { - cli.debug('args: ' + util.inspect(args)); - cli.debug('options: ' + util.inspect(options)); - - var grepArguments = ['-E', '-n', '--color=always']; - var stdin = false; - - if (args.length == 0 && options.all) { - // STDIN with all addresses - grepArguments.push('ADDRESS'); - stdin = true; - } else if (args.length == 1) { - // STDIN - var address = new v6.Address(new v6.Address(args[0]).correctForm()); - var regex = address.regularExpressionString(options.substring); - - cli.debug('address: ' + util.inspect(address.regularExpression())); - - grepArguments.push(regex); - stdin = true; - } else if (args.length > 1) { - // filename - var address = new v6.Address(new v6.Address(args[0]).correctForm()); - var regex = address.regularExpressionString(options.substring); - - var files = args.slice(1, args.length); - - cli.debug('address: ' + util.inspect(address.regularExpression())); - cli.debug('files: ' + util.inspect(files)); - - grepArguments = grepArguments.concat(regex, files) - } - - cli.debug('grep arguments: ' + util.inspect(grepArguments)); - - if (!stdin) { - var grep = spawn('grep', grepArguments); - - grep.stdout.on('data', function (data) { - console.log(String(data).trim()); - }); - - grep.on('exit', function (code) { - cli.debug('grep exited: ' + code); - }); - - //grep.stdin.end(); - } - - //cli.withStdinLines(function(lines, newline) { - //}); -}); diff --git a/node_modules/ipv6/examples/browser/simple.html b/node_modules/ipv6/examples/browser/simple.html deleted file mode 100644 index 39406fa..0000000 --- a/node_modules/ipv6/examples/browser/simple.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - Simple IPv6 test - - - - - - - - - - - - - - - The canonical form of a::b is: - - diff --git a/node_modules/ipv6/examples/node/simple.js b/node_modules/ipv6/examples/node/simple.js deleted file mode 100644 index 082ff80..0000000 --- a/node_modules/ipv6/examples/node/simple.js +++ /dev/null @@ -1,5 +0,0 @@ -var v6 = require('ipv6').v6; - -var address = new v6.Address('a::b'); - -console.log(address.canonicalForm()); diff --git a/node_modules/ipv6/index.js b/node_modules/ipv6/index.js deleted file mode 100644 index c7929b9..0000000 --- a/node_modules/ipv6/index.js +++ /dev/null @@ -1 +0,0 @@ -exports = module.exports = require('./ipv6.js'); \ No newline at end of file diff --git a/node_modules/ipv6/ipv6.js b/node_modules/ipv6/ipv6.js deleted file mode 100644 index 7e3c4cd..0000000 --- a/node_modules/ipv6/ipv6.js +++ /dev/null @@ -1,1314 +0,0 @@ -if (typeof exports !== 'undefined') { - var sprintf = require('sprintf').sprintf; - var BigInteger = require('./lib/node/bigint').BigInteger; -} - -var v4 = this.v4 = {}; -var v6 = this.v6 = {}; - -v4.GROUPS = 4; -v6.GROUPS = 8; - -v4.BITS = 32; -v6.BITS = 128; - -v6.SCOPES = { - 0: 'Reserved', - 1: 'Interface local', - 2: 'Link local', - 4: 'Admin local', - 5: 'Site local', - 8: 'Organization local', - 15: 'Global', - 16: 'Reserved' -}; - -v4.RE_ADDRESS = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/g; -v4.RE_SUBNET_STRING = /\/\d{1,2}$/; - -v6.RE_BAD_CHARACTERS = /([^0-9a-f:\/%])/ig; -v6.RE_BAD_ADDRESS = /([0-9a-f]{5,}|:{3,}|[^:]:$|^:[^:]|\/$)/ig; - -v6.RE_SUBNET_STRING = /\/\d{1,3}(?=%|$)/; -v6.RE_ZONE_STRING = /%.*$/; - -v6.RE_URL = new RegExp(/([0-9a-f:]+)/); -v6.RE_URL_WITH_PORT = new RegExp(/\[([0-9a-f:]+)\]:([0-9]{1,5})/); - -// Convenience functions -function map(array, fn) { - var results = []; - var i; - - for (i = 0; i < array.length; i++) { - results.push(fn(array[i], i)); - } - - return results; -} - -function repeatString(s, n) { - var result = ''; - var i; - - for (i = 0; i < n; i++) { - result += s; - } - - return result; -} - -function addCommas(number) { - var r = /(\d+)(\d{3})/; - - while (r.test(number)) { - number = number.replace(r, '$1,$2'); - } - - return number; -} - -function spanLeadingZeroesSimple(group) { - return group.replace(/^(0+)/, '$1'); -} - -function spanLeadingZeroes4(n) { - n = n.replace(/^(0{1,})([1-9]+)$/, '$1$2'); - n = n.replace(/^(0{1,})(0)$/, '$1$2'); - - return n; -} - -function simpleRegularExpression(addressArray) { - var output = []; - var i; - - for (i = 0; i < addressArray.length; i++) { - var segment = addressArray[i]; - - if (segment.length < 4) { - output.push(sprintf('0{0,%d}%s', 4 - segment.length, segment)); - } else { - output.push(segment); - } - } - - return output.join(':'); -} - -function zeroPad(s, n) { - return String(repeatString(0, n) + s).slice(n * -1); -} - -function isInSubnet(address) { - // XXX: This is a hunch - if (this.subnetMask < address.subnetMask) { - return false; - } - - if (this.mask(address.subnetMask) === address.mask()) { - return true; - } - - return false; -} - -/* - * Instantiates an IPv4 address - */ -v4.Address = function (address) { - this.valid = false; - this.address = address; - this.groups = v4.GROUPS; - - this.v4 = true; - - this.subnet = '/32'; - this.subnetMask = 32; - - var subnet = v4.RE_SUBNET_STRING.exec(address); - - if (subnet) { - this.parsedSubnet = subnet[0].replace('/', ''); - this.subnetMask = parseInt(this.parsedSubnet, 10); - this.subnet = '/' + this.subnetMask; - - if (this.subnetMask < 0 || this.subnetMask > v4.BITS) { - this.valid = false; - this.error = "Invalid subnet mask."; - - return; - } - - address = address.replace(v4.RE_SUBNET_STRING, ''); - } - - this.addressMinusSuffix = address; - - this.parsedAddress = this.parse(address); -}; - -/* - * Parses a v4 address - */ -v4.Address.prototype.parse = function (address) { - var groups = address.split('.'); - - if (address.match(v4.RE_ADDRESS)) { - this.valid = true; - } else { - this.error = 'Invalid IPv4 address.'; - } - - return groups; -}; - -/* - * Returns true if the address is valid - */ -v4.Address.prototype.isValid = function () { - return this.valid; -}; - -/* - * Returns the correct form of an address - */ -v4.Address.prototype.correctForm = function () { - return this.parsedAddress.map(function (part) { - return parseInt(part, 10); - }).join('.'); -}; - -/* - * Returns true if the address is correct, false otherwise - */ -v4.Address.prototype.isCorrect = function () { - return this.addressMinusSuffix === this.correctForm() && - (this.subnetMask === 32 || - this.parsedSubnet === String(this.subnet.replace('/'))); -}; - -/* - * Converts a hex string to an IPv4 address object - */ -v4.Address.fromHex = function (hex) { - var padded = zeroPad(hex.replace(/:/g, ''), 8); - var groups = []; - var i; - - for (i = 0; i < 8; i += 2) { - var h = padded.slice(i, i + 2); - - groups.push(parseInt(h, 16)); - } - - return new v4.Address(groups.join('.')); -}; - -/* - * Converts an integer into a IPv4 address object - */ -v4.Address.fromInteger = function (integer) { - return v4.Address.fromHex(integer.toString(16)); -}; - -/* - * Converts an IPv4 address object to a hex string - */ -v4.Address.prototype.toHex = function () { - return this.parsedAddress.map(function (part) { - return sprintf('%02x', parseInt(part, 10)); - }).join(':'); -}; - -/* - * Converts an IPv4 address object to an array of bytes - */ -v4.Address.prototype.toArray = function () { - return this.parsedAddress.map(function (part) { - return parseInt(part, 10); - }); -}; - -/* - * Converts an IPv4 address object to an IPv6 address group - */ -v4.Address.prototype.toV6Group = function () { - var output = []; - var i; - - for (i = 0; i < v4.GROUPS; i += 2) { - var hex = sprintf('%02x%02x', - parseInt(this.parsedAddress[i], 10), - parseInt(this.parsedAddress[i + 1], 10)); - - output.push(sprintf('%x', parseInt(hex, 16))); - } - - return output.join(':'); -}; - -/* - * Returns the address as a BigInteger - */ -v4.Address.prototype.bigInteger = function () { - if (!this.valid) { - return; - } - - return new BigInteger(map(this.parsedAddress, function (n) { - return sprintf("%02x", parseInt(n, 10)); - }).join(''), 16); -}; - -/* - * The first address in the range given by this address' subnet. - * Often referred to as the Network Address. - */ -v4.Address.prototype.startAddress = function () { - var startAddress = new BigInteger(this.mask() + repeatString(0, - v4.BITS - this.subnetMask), 2); - - return v4.Address.fromBigInteger(startAddress); -}; - -/* - * The last address in the range given by this address' subnet - * Often referred to as the Broadcast - */ -v4.Address.prototype.endAddress = function () { - var endAddress = new BigInteger(this.mask() + repeatString(1, - v4.BITS - this.subnetMask), 2); - - return v4.Address.fromBigInteger(endAddress); -}; - -/* - * Converts a BigInteger to a v4 address object - */ -v4.Address.fromBigInteger = function (bigInteger) { - return v4.Address.fromInteger(parseInt(bigInteger.toString(), 10)); -}; - -/* - * Returns the first n bits of the address, defaulting to the - * subnet mask - */ -v4.Address.prototype.mask = function (opt_mask) { - if (opt_mask === undefined) { - opt_mask = this.subnetMask; - } - - return this.getBitsBase2(0, opt_mask); -}; - -/* - * Returns the bits in the given range as a base-2 string - */ -v4.Address.prototype.getBitsBase2 = function (start, end) { - return this.binaryZeroPad().slice(start, end); -}; - -/* - * Returns true if the given address is in the subnet of the current address - */ -v4.Address.prototype.isInSubnet = isInSubnet; - -/* - * Returns a zero-padded base-2 string representation of the address - */ -v4.Address.prototype.binaryZeroPad = function () { - return zeroPad(this.bigInteger().toString(2), v4.BITS); -}; - -/* - * Instantiates an IPv6 address - */ -v6.Address = function (address, opt_groups) { - if (opt_groups === undefined) { - this.groups = v6.GROUPS; - } else { - this.groups = opt_groups; - } - - this.v4 = false; - - this.subnet = '/128'; - this.subnetMask = 128; - - this.zone = ''; - - this.address = address; - - var subnet = v6.RE_SUBNET_STRING.exec(address); - - if (subnet) { - this.parsedSubnet = subnet[0].replace('/', ''); - this.subnetMask = parseInt(this.parsedSubnet, 10); - this.subnet = '/' + this.subnetMask; - - if (isNaN(this.subnetMask) || - this.subnetMask < 0 || - this.subnetMask > v6.BITS) { - this.valid = false; - this.error = "Invalid subnet mask."; - - return; - } - - address = address.replace(v6.RE_SUBNET_STRING, ''); - } else if (/\//.test(address)) { - this.valid = false; - this.error = "Invalid subnet mask."; - - return; - } - - var zone = v6.RE_ZONE_STRING.exec(address); - - if (zone) { - this.zone = zone[0]; - - address = address.replace(v6.RE_ZONE_STRING, ''); - } - - this.addressMinusSuffix = address; - - this.parsedAddress = this.parse(this.addressMinusSuffix); -}; - -/* - * Converts a BigInteger to a v6 address object - */ -v6.Address.fromBigInteger = function (bigInteger) { - var hex = zeroPad(bigInteger.toString(16), 32); - var groups = []; - var i; - - for (i = 0; i < 8; i++) { - groups.push(hex.slice(i * 4, (i + 1) * 4)); - } - - return new v6.Address(groups.join(':')); -}; - -/* - * Converts a URL (optional port number) to an address object - */ -v6.Address.fromURL = function (url) { - var host; - var port; - var result; - - // If we have brackets parse them and find a port - if (url.indexOf('[') !== -1 && url.indexOf(']') !== -1) { - result = v6.RE_URL_WITH_PORT.exec(url); - - if (result === null) { - return { - error: 'failed to parse address with port', - address: null, - port: null - }; - } - - host = result[1]; - port = result[2]; - // If there's a URL extract the address - } else if (url.indexOf('/') !== -1) { - // Remove the protocol prefix - url = url.replace(/^[a-z0-9]+:\/\//, ''); - - // Parse the address - result = v6.RE_URL.exec(url); - - if (result === null) { - return { - error: 'failed to parse address from URL', - address: null, - port: null - }; - } - - host = result[1]; - // Otherwise just assign the URL to the host and let the library parse it - } else { - host = url; - } - - // If there's a port convert it to an integer - if (port) { - port = parseInt(port, 10); - - //squelch out of range ports - if (port < 0 || port > 65536) { - port = null; - } - } else { - // Standardize `undefined` to `null` - port = null; - } - - return { - address: new v6.Address(host), - port: port - }; -}; - -/* - * A helper function to compact an array - */ -v6.Address.compact = function (address, slice) { - var s1 = []; - var s2 = []; - var i; - - for (i = 0; i < address.length; i++) { - if (i < slice[0]) { - s1.push(address[i]); - } else if (i > slice[1]) { - s2.push(address[i]); - } - } - - return s1.concat(['compact']).concat(s2); -}; - -/* - * Returns true if the address is valid, false otherwise - */ -v6.Address.prototype.isValid = function () { - return this.valid; -}; - -/* - * Returns true if the address is correct, false otherwise - */ -v6.Address.prototype.isCorrect = function () { - return this.addressMinusSuffix === this.correctForm() && - (this.subnetMask === 128 || - this.parsedSubnet === String(this.subnet.replace('/'))); -}; - -/* - * Returns true if the address is a link local address, false otherwise - */ -v6.Address.prototype.isLinkLocal = function () { - // Zeroes are required, i.e. we can't check isInSubnet with 'fe80::/10' - if (this.getBitsBase2(0, 64) === - "1111111010000000000000000000000000000000000000000000000000000000") { - return true; - } - - return false; -}; - -/* - * Returns true if the address is in the canonical form, false otherwise - */ -v6.Address.prototype.isCanonical = function () { - return this.addressMinusSuffix === this.canonicalForm(); -}; - -/* - * Returns true if the address is a multicast address, false otherwise - */ -v6.Address.prototype.isMulticast = function () { - return this.getType() === 'Multicast'; -}; - -/* - * Returns true if the address is a v4-in-v6 address, false otherwise - */ -v6.Address.prototype.is4 = function () { - return this.v4; -}; - -/* - * Returns true if the address is a Teredo address, false otherwise - */ -v6.Address.prototype.isTeredo = function () { - if (this.isInSubnet(new v6.Address('2001::/32'))) { - return true; - } - - return false; -}; - -/* - * Returns true if the address is a 6to4 address, false otherwise - */ -v6.Address.prototype.is6to4 = function () { - if (this.isInSubnet(new v6.Address('2002::/16'))) { - return true; - } - - return false; -}; - -/* - * Returns true if the address is a loopback address, false otherwise - */ -v6.Address.prototype.isLoopback = function () { - return this.getType() === 'Loopback'; -}; - -/* - * Returns the Microsoft UNC transcription of the address - */ -v6.Address.prototype.microsoftTranscription = function () { - return sprintf('%s.ipv6-literal.net', - this.correctForm().replace(/:/g, '-')); -}; - -/* - * Returns the address in link form with a default port of 80 - */ -v6.Address.prototype.href = function (opt_port) { - if (opt_port === undefined) { - opt_port = ''; - } else { - opt_port = sprintf(':%s', opt_port); - } - - return sprintf('http://[%s]%s/', this.correctForm(), opt_port); -}; - -/* - * Returns the first n bits of the address, defaulting to the - * subnet mask - */ -v6.Address.prototype.mask = function (opt_mask) { - if (opt_mask === undefined) { - opt_mask = this.subnetMask; - } - - return this.getBitsBase2(0, opt_mask); -}; - -/* - * Returns a link suitable for conveying the address via a URL hash - */ -v6.Address.prototype.link = function (options) { - if (!options) { - options = {}; - } - - if (options.className === undefined) { - options.className = ''; - } - - if (options.prefix === undefined) { - options.prefix = '/#address='; - } - - if (options.v4 === undefined) { - options.v4 = false; - } - - var formFunction = this.correctForm; - - if (options.v4) { - formFunction = this.v4inv6; - } - - if (options.className) { - return sprintf('%2$s', - options.prefix, formFunction.call(this), options.className); - } - - return sprintf('%2$s', options.prefix, - formFunction.call(this)); -}; - -/* - * Returns the number of possible subnets of a given size in the address - */ -v6.Address.prototype.possibleAddresses = function (opt_subnetSize) { - if (opt_subnetSize === undefined) { - opt_subnetSize = 0; - } - - return addCommas(new BigInteger('2', 10).pow((v6.BITS - this.subnetMask) - - (v6.BITS - opt_subnetSize)).toString(10)); -}; - -/* - * Returns true if the given address is in the subnet of the current address - */ -v6.Address.prototype.isInSubnet = isInSubnet; - -/* - * Create an IPv6-mapped address given an IPv4 address - */ -v6.Address.fromAddress4 = function (address4) { - return new v6.Address('::ffff:' + address4); -}; - -/* - * The first address in the range given by this address' subnet - */ -v6.Address.prototype.startAddress = function () { - var startAddress = new BigInteger(this.mask() + repeatString(0, - v6.BITS - this.subnetMask), 2); - - return v6.Address.fromBigInteger(startAddress); -}; - -/* - * The last address in the range given by this address' subnet - */ -v6.Address.prototype.endAddress = function () { - var endAddress = new BigInteger(this.mask() + repeatString(1, - v6.BITS - this.subnetMask), 2); - - return v6.Address.fromBigInteger(endAddress); -}; - -/* - * Returns the scope of the address - */ -v6.Address.prototype.getScope = function () { - var scope = v6.SCOPES[this.getBits(12, 16)]; - - if (this.getType() === "Global unicast") { - if (scope !== "Link local") { - scope = "Global"; - } - } - - return scope; -}; - -/* - * Returns the type of the address - */ -v6.Address.prototype.getType = function () { - // TODO: Refactor this - // TODO: Add ff0x::fb, etc. for multicast DNS - var TYPES = { - 'ff01::1/128': 'Multicast (All nodes on this interface)', - 'ff01::2/128': 'Multicast (All routers on this interface)', - 'ff02::1/128': 'Multicast (All nodes on this link)', - 'ff02::2/128': 'Multicast (All routers on this link)', - 'ff05::2/128': 'Multicast (All routers in this site)', - 'ff02::5/128': 'Multicast (OSPFv3 AllSPF routers)', - 'ff02::6/128': 'Multicast (OSPFv3 AllDR routers)', - 'ff02::9/128': 'Multicast (RIP routers)', - 'ff02::a/128': 'Multicast (EIGRP routers)', - 'ff02::d/128': 'Multicast (PIM routers)', - 'ff02::16/128': 'Multicast (MLDv2 reports)', - 'ff01::fb/128': 'Multicast (mDNSv6)', - 'ff02::fb/128': 'Multicast (mDNSv6)', - 'ff05::fb/128': 'Multicast (mDNSv6)', - 'ff02::1:2/128': 'Multicast (All DHCP servers and relay agents on this link)', - 'ff05::1:2/128': 'Multicast (All DHCP servers and relay agents in this site)', - 'ff02::1:3/128': 'Multicast (All DHCP servers on this link)', - 'ff05::1:3/128': 'Multicast (All DHCP servers in this site)', - '::/128': 'Unspecified', - '::1/128': 'Loopback', - 'ff00::/8': 'Multicast', - 'fe80::/10': 'Link-local unicast' - }; - - var type = 'Global unicast'; - var p; - - for (p in TYPES) { - if (TYPES.hasOwnProperty(p)) { - if (this.isInSubnet(new v6.Address(p))) { - type = TYPES[p]; - - break; - } - } - } - - return type; -}; - -/* - * Returns the bits in the given range as a BigInteger - */ -v6.Address.prototype.getBits = function (start, end) { - return new BigInteger(this.getBitsBase2(start, end), 2); -}; - -/* - * Returns the bits in the given range as a base-2 string - */ -v6.Address.prototype.getBitsBase2 = function (start, end) { - return this.binaryZeroPad().slice(start, end); -}; - -/* - * Returns the bits in the given range as a base-16 string - */ -v6.Address.prototype.getBitsBase16 = function (start, end) { - var length = end - start; - - if (length % 4 !== 0) { - return; - } - - return zeroPad(this.getBits(start, end).toString(16), length / 4); -}; - -/* - * Returns the bits that are set past the subnet mask length - */ -v6.Address.prototype.getBitsPastSubnet = function () { - return this.getBitsBase2(this.subnetMask, v6.BITS); -}; - -/* - * Returns the string with each character contained in a - */ -v6.Address.spanAll = function (s, opt_offset) { - if (opt_offset === undefined) { - opt_offset = 0; - } - - var letters = s.split(''); - - return map(letters, function (n, i) { - return sprintf('%s', n, - i + opt_offset, - v6.Address.spanAllZeroes(n)); // XXX Use #base-2 .value-0 instead? - }).join(''); -}; - -/* - * Returns the string with all zeroes contained in a - */ -v6.Address.spanAllZeroes = function (s) { - return s.replace(/(0+)/g, '$1'); -}; - -/* - * Returns the string with leading zeroes contained in a - */ -v6.Address.spanLeadingZeroes = function (address) { - var groups = address.split(':'); - - groups = map(groups, function (g) { - return spanLeadingZeroesSimple(g); - }); - - return groups.join(':'); -}; - -/* - * Groups an address - */ -v6.Address.simpleGroup = function (addressString, offset) { - var groups = addressString.split(':'); - - if (!offset) { - offset = 0; - } - - groups = map(groups, function (g, i) { - if (/group-v4/.test(g)) { - return g; - } - - return sprintf('%s', - i + offset, - spanLeadingZeroesSimple(g)); - }); - - return groups.join(':'); -}; - -/* - * Groups an address - */ -v6.Address.group = function (addressString) { - var address6 = new v6.Address(addressString); - var address4 = address6.address.match(v4.RE_ADDRESS); - var i; - - if (address4) { - // The IPv4 case - var segments = address4[0].split('.'); - - address6.address = address6.address.replace(v4.RE_ADDRESS, - sprintf('%s' + - '.' + - '%s', - segments.slice(0, 2).join('.'), - segments.slice(2, 4).join('.'))); - } - - if (address6.elidedGroups === 0) { - // The simple case - return v6.Address.simpleGroup(address6.address); - } - - // The elided case - var output = []; - - var halves = address6.address.split('::'); - - if (halves[0].length) { - output.push(v6.Address.simpleGroup(halves[0])); - } else { - output.push(''); - } - - var classes = ['hover-group']; - - for (i = address6.elisionBegin; i < address6.elisionBegin + - address6.elidedGroups; i++) { - classes.push(sprintf('group-%d', i)); - } - - output.push(sprintf('', classes.join(' '))); - - if (halves[1].length) { - output.push(v6.Address.simpleGroup(halves[1], address6.elisionEnd)); - } else { - output.push(''); - } - - return output.join(':'); -}; - -/* - * Returns the reversed ip6.arpa form of the address - */ -v6.Address.prototype.reverseForm = function () { - var characters = Math.floor(this.subnetMask / 4); - - var reversed = this.canonicalForm() - .replace(/:/g, '') - .split('') - .slice(0, characters) - .reverse() - .join('.'); - - if (characters > 0) { - return sprintf("%s.ip6.arpa.", reversed); - } - - return 'ip6.arpa.'; -}; - -/* - * Returns the correct form of the address - */ -v6.Address.prototype.correctForm = function () { - if (!this.parsedAddress) { - return; - } - - var i; - var groups = []; - - var zeroCounter = 0; - var zeroes = []; - - for (i = 0; i < this.parsedAddress.length; i++) { - var value = parseInt(this.parsedAddress[i], 16); - - if (value === 0) { - zeroCounter++; - } - - if (value !== 0 && zeroCounter > 0) { - if (zeroCounter > 1) { - zeroes.push([i - zeroCounter, i - 1]); - } - - zeroCounter = 0; - } - } - - // Do we end with a string of zeroes? - if (zeroCounter > 1) { - zeroes.push([this.parsedAddress.length - zeroCounter, - this.parsedAddress.length - 1]); - } - - var zeroLengths = map(zeroes, function (n) { - return (n[1] - n[0]) + 1; - }); - - if (zeroes.length > 0) { - var max = Math.max.apply(Math, zeroLengths); - var index = zeroLengths.indexOf(max); - - groups = v6.Address.compact(this.parsedAddress, zeroes[index]); - } else { - groups = this.parsedAddress; - } - - for (i = 0; i < groups.length; i++) { - if (groups[i] !== 'compact') { - groups[i] = parseInt(groups[i], 16).toString(16); - } - } - - var correct = groups.join(':'); - - correct = correct.replace(/^compact$/, '::'); - correct = correct.replace(/^compact|compact$/, ':'); - correct = correct.replace(/compact/, ''); - - return correct; -}; - -/* - * Returns a zero-padded base-2 string representation of the address - */ -v6.Address.prototype.binaryZeroPad = function () { - return zeroPad(this.bigInteger().toString(2), v6.BITS); -}; - -// TODO: Improve the semantics of this helper function -v6.Address.prototype.parse4in6 = function (address) { - var groups = address.split(':'); - var lastGroup = groups.slice(-1)[0]; - - var address4 = lastGroup.match(v4.RE_ADDRESS); - - if (address4) { - var temp4 = new v4.Address(address4[0]); - - for (var i = 0; i < temp4.groups; i++) { - if (/^0[0-9]+/.test(temp4.parsedAddress[i])) { - this.valid = false; - this.error = 'IPv4 addresses can not have leading zeroes.'; - - this.parseError = address.replace(v4.RE_ADDRESS, - map(temp4.parsedAddress, spanLeadingZeroes4).join('.')); - - return; - } - } - - this.v4 = true; - - groups[groups.length - 1] = temp4.toV6Group(); - - address = groups.join(':'); - } - - return address; -}; - -// TODO: Make private? -v6.Address.prototype.parse = function (address) { - address = this.parse4in6(address); - - if (this.error) { - return; - } - - var badCharacters = address.match(v6.RE_BAD_CHARACTERS); - - if (badCharacters) { - this.valid = false; - this.error = sprintf("Bad character%s detected in address: %s", - badCharacters.length > 1 ? 's' : '', badCharacters.join('')); - - this.parseError = address.replace(v6.RE_BAD_CHARACTERS, - '$1'); - - return; - } - - var badAddress = address.match(v6.RE_BAD_ADDRESS); - - if (badAddress) { - this.valid = false; - this.error = sprintf("Address failed regex: %s", badAddress.join('')); - - this.parseError = address.replace(v6.RE_BAD_ADDRESS, - '$1'); - - return; - } - - var groups = []; - - var halves = address.split('::'); - - if (halves.length === 2) { - var first = halves[0].split(':'); - var last = halves[1].split(':'); - - if (first.length === 1 && - first[0] === '') { - first = []; - } - - if (last.length === 1 && - last[0] === '') { - last = []; - } - - var remaining = this.groups - (first.length + last.length); - - if (!remaining) { - this.valid = false; - this.error = "Error parsing groups"; - - return; - } - - this.elidedGroups = remaining; - - this.elisionBegin = first.length; - this.elisionEnd = first.length + this.elidedGroups; - - first.forEach(function (group) { - groups.push(group); - }); - - for (var i = 0; i < remaining; i++) { - groups.push(0); - } - - last.forEach(function (group) { - groups.push(group); - }); - } else if (halves.length === 1) { - groups = address.split(':'); - - this.elidedGroups = 0; - } else { - this.valid = false; - this.error = "Too many :: groups found"; - - return; - } - - groups = map(groups, function (g) { - return sprintf('%x', parseInt(g, 16)); - }); - - if (groups.length !== this.groups) { - this.valid = false; - this.error = "Incorrect number of groups found"; - - return; - } - - groups.forEach(function (group, i) { - if (groups.length > 4 && !this.v4) { - this.valid = false; - this.error = sprintf("Group %d is too long", i + 1); - - return; - } - }); - - this.valid = true; - - return groups; -}; - -/* - * Generate a regular expression string that can be used to find or validate all - * variations of this address. - */ -v6.Address.prototype.regularExpressionString = function (opt_subString) { - if (opt_subString === undefined) { - opt_subString = false; - } - - var i; - var output = []; - - var address6 = new v6.Address(this.correctForm()); - - if (address6.elidedGroups === 0) { - // The simple case - output = simpleRegularExpression(address6.parsedAddress); - } else if (address6.elidedGroups === 8) { - output.push('::|'); - - // TODO: Validate this - for (i = 0; i < address6.elidedGroups; i++) { - var pipe = '|'; - - if (i === address6.elidedGroups - 1) { - pipe = ''; - } - - output.push(sprintf('(0{1,4}:){%d}:%s', address6.elidedGroups, pipe)); - } - } else { - // The elided case - - // TODO: Allow sloppy elision - // TODO: Compute all possible elisions - var halves = address6.address.split('::'); - - if (halves[0].length) { - output = output.concat(simpleRegularExpression(halves[0].split(':'))); - output.push(':'); - } - - output.push(sprintf('((0{1,4}:){%d}|:)', address6.elidedGroups)); - - if (halves[1].length) { - output = output.concat(simpleRegularExpression(halves[1].split(':'))); - } - } - - if (!opt_subString) { - output = [].concat('\\b', output, '\\b'); - } - - return output.join(''); -}; - -/* - * Generate a regular expression that can be used to find or validate all - * variations of this address. - */ -v6.Address.prototype.regularExpression = function () { - return new RegExp(this.regularExpressionString(), 'i'); -}; - -/* - * Returns the canonical form of the address - */ -v6.Address.prototype.canonicalForm = function () { - if (!this.valid) { - return; - } - - return map(this.parsedAddress, function (n) { - return sprintf("%04x", parseInt(n, 16)); - }).join(':'); -}; - -/* - * Returns the decimal form of the address - */ -v6.Address.prototype.decimal = function () { - if (!this.valid) { - return; - } - - return map(this.parsedAddress, function (n) { - return sprintf("%05d", parseInt(n, 16)); - }).join(':'); -}; - -/* - * Returns the address as a BigInteger - */ -v6.Address.prototype.bigInteger = function () { - if (!this.valid) { - return; - } - - return new BigInteger(map(this.parsedAddress, function (n) { - return sprintf("%04x", parseInt(n, 16)); - }).join(''), 16); -}; - -/* - * Returns the v4-in-v6 form of the address - */ -v6.Address.prototype.v4inv6 = function () { - var binary = this.binaryZeroPad().split(''); - - var address4 = v4.Address.fromHex(new BigInteger(binary.slice(96, 128) - .join(''), 2).toString(16)); - var address6 = new v6.Address(this.parsedAddress.slice(0, 6).join(':'), 6); - - var correct = address6.correctForm(); - - var infix = ''; - - if (!/:$/.test(correct)) { - infix = ':'; - } - - return address6.correctForm() + infix + address4.address; -}; - -/* - * Returns an object containing the Teredo properties of the address - */ -v6.Address.prototype.teredo = function () { - /* - - Bits 0 to 31 are set to the Teredo prefix (normally 2001:0000::/32). - - Bits 32 to 63 embed the primary IPv4 address of the Teredo server that - is used. - - Bits 64 to 79 can be used to define some flags. Currently only the - higher order bit is used; it is set to 1 if the Teredo client is - located behind a cone NAT, 0 otherwise. For Microsoft's Windows Vista - and Windows Server 2008 implementations, more bits are used. In those - implementations, the format for these 16 bits is "CRAAAAUG AAAAAAAA", - where "C" remains the "Cone" flag. The "R" bit is reserved for future - use. The "U" bit is for the Universal/Local flag (set to 0). The "G" bit - is Individual/Group flag (set to 0). The A bits are set to a 12-bit - randomly generated number chosen by the Teredo client to introduce - additional protection for the Teredo node against IPv6-based scanning - attacks. - - Bits 80 to 95 contains the obfuscated UDP port number. This is the - port number that is mapped by the NAT to the Teredo client with all - bits inverted. - - Bits 96 to 127 contains the obfuscated IPv4 address. This is the - public IPv4 address of the NAT with all bits inverted. - */ - - var prefix = this.getBitsBase16(0, 32); - - var udpPort = this.getBits(80, 96).xor(new BigInteger('ffff', 16)).toString(); - - var server4 = v4.Address.fromHex(this.getBitsBase16(32, 64)); - var client4 = v4.Address.fromHex(this.getBits(96, 128) - .xor(new BigInteger('ffffffff', 16)).toString(16)); - - var flags = this.getBits(64, 80); - var flagsBase2 = this.getBitsBase2(64, 80); - - var coneNat = flags.testBit(15); - var reserved = flags.testBit(14); - var groupIndividual = flags.testBit(8); - var universalLocal = flags.testBit(9); - var nonce = new BigInteger(flagsBase2.slice(2, 6) + - flagsBase2.slice(8, 16), 2).toString(10); - - return { - prefix: sprintf('%s:%s', prefix.slice(0, 4), prefix.slice(4, 8)), - server4: server4.address, - client4: client4.address, - flags: flagsBase2, - coneNat: coneNat, - microsoft: { - reserved: reserved, - universalLocal: universalLocal, - groupIndividual: groupIndividual, - nonce: nonce - }, - udpPort: udpPort - }; -}; - -/* - * Returns an object containing the 6to4 properties of the address - */ -v6.Address.prototype.six2four = function () { - /* - - Bits 0 to 15 are set to the 6to4 prefix (2002::/16). - - Bits 16 to 48 embed the IPv4 address of the 6to4 gateway that is used. - */ - - var prefix = this.getBitsBase16(0, 16); - - var gateway = v4.Address.fromHex(this.getBitsBase16(16, 48)); - - return { - prefix: sprintf('%s', prefix.slice(0, 4)), - gateway: gateway.address - }; -}; diff --git a/node_modules/ipv6/lib/browser/jsbn-combined.js b/node_modules/ipv6/lib/browser/jsbn-combined.js deleted file mode 100644 index ff89bdd..0000000 --- a/node_modules/ipv6/lib/browser/jsbn-combined.js +++ /dev/null @@ -1,1211 +0,0 @@ -// Copyright (c) 2005 Tom Wu -// All Rights Reserved. -// See "LICENSE" for details. - -// Basic JavaScript BN library - subset useful for RSA encryption. - -// Bits per digit -var dbits; - -// JavaScript engine analysis -var canary = 0xdeadbeefcafe; -var j_lm = ((canary&0xffffff)==0xefcafe); - -// (public) Constructor -function BigInteger(a,b,c) { - if(a != null) - if("number" == typeof a) this.fromNumber(a,b,c); - else if(b == null && "string" != typeof a) this.fromString(a,256); - else this.fromString(a,b); -} - -// return new, unset BigInteger -function nbi() { return new BigInteger(null); } - -// am: Compute w_j += (x*this_i), propagate carries, -// c is initial carry, returns final carry. -// c < 3*dvalue, x < 2*dvalue, this_i < dvalue -// We need to select the fastest one that works in this environment. - -// am1: use a single mult and divide to get the high bits, -// max digit bits should be 26 because -// max internal value = 2*dvalue^2-2*dvalue (< 2^53) -function am1(i,x,w,j,c,n) { - while(--n >= 0) { - var v = x*this[i++]+w[j]+c; - c = Math.floor(v/0x4000000); - w[j++] = v&0x3ffffff; - } - return c; -} -// am2 avoids a big mult-and-extract completely. -// Max digit bits should be <= 30 because we do bitwise ops -// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31) -function am2(i,x,w,j,c,n) { - var xl = x&0x7fff, xh = x>>15; - while(--n >= 0) { - var l = this[i]&0x7fff; - var h = this[i++]>>15; - var m = xh*l+h*xl; - l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff); - c = (l>>>30)+(m>>>15)+xh*h+(c>>>30); - w[j++] = l&0x3fffffff; - } - return c; -} -// Alternately, set max digit bits to 28 since some -// browsers slow down when dealing with 32-bit numbers. -function am3(i,x,w,j,c,n) { - var xl = x&0x3fff, xh = x>>14; - while(--n >= 0) { - var l = this[i]&0x3fff; - var h = this[i++]>>14; - var m = xh*l+h*xl; - l = xl*l+((m&0x3fff)<<14)+w[j]+c; - c = (l>>28)+(m>>14)+xh*h; - w[j++] = l&0xfffffff; - } - return c; -} -if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) { - BigInteger.prototype.am = am2; - dbits = 30; -} -else if(j_lm && (navigator.appName != "Netscape")) { - BigInteger.prototype.am = am1; - dbits = 26; -} -else { // Mozilla/Netscape seems to prefer am3 - BigInteger.prototype.am = am3; - dbits = 28; -} - -BigInteger.prototype.DB = dbits; -BigInteger.prototype.DM = ((1<= 0; --i) r[i] = this[i]; - r.t = this.t; - r.s = this.s; -} - -// (protected) set from integer value x, -DV <= x < DV -function bnpFromInt(x) { - this.t = 1; - this.s = (x<0)?-1:0; - if(x > 0) this[0] = x; - else if(x < -1) this[0] = x+DV; - else this.t = 0; -} - -// return bigint initialized to value -function nbv(i) { var r = nbi(); r.fromInt(i); return r; } - -// (protected) set from string and radix -function bnpFromString(s,b) { - var k; - if(b == 16) k = 4; - else if(b == 8) k = 3; - else if(b == 256) k = 8; // byte array - else if(b == 2) k = 1; - else if(b == 32) k = 5; - else if(b == 4) k = 2; - else { this.fromRadix(s,b); return; } - this.t = 0; - this.s = 0; - var i = s.length, mi = false, sh = 0; - while(--i >= 0) { - var x = (k==8)?s[i]&0xff:intAt(s,i); - if(x < 0) { - if(s.charAt(i) == "-") mi = true; - continue; - } - mi = false; - if(sh == 0) - this[this.t++] = x; - else if(sh+k > this.DB) { - this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<>(this.DB-sh)); - } - else - this[this.t-1] |= x<= this.DB) sh -= this.DB; - } - if(k == 8 && (s[0]&0x80) != 0) { - this.s = -1; - if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)< 0 && this[this.t-1] == c) --this.t; -} - -// (public) return string representation in given radix -function bnToString(b) { - if(this.s < 0) return "-"+this.negate().toString(b); - var k; - if(b == 16) k = 4; - else if(b == 8) k = 3; - else if(b == 2) k = 1; - else if(b == 32) k = 5; - else if(b == 4) k = 2; - else return this.toRadix(b); - var km = (1< 0) { - if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); } - while(i >= 0) { - if(p < k) { - d = (this[i]&((1<>(p+=this.DB-k); - } - else { - d = (this[i]>>(p-=k))&km; - if(p <= 0) { p += this.DB; --i; } - } - if(d > 0) m = true; - if(m) r += int2char(d); - } - } - return m?r:"0"; -} - -// (public) -this -function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; } - -// (public) |this| -function bnAbs() { return (this.s<0)?this.negate():this; } - -// (public) return + if this > a, - if this < a, 0 if equal -function bnCompareTo(a) { - var r = this.s-a.s; - if(r != 0) return r; - var i = this.t; - r = i-a.t; - if(r != 0) return r; - while(--i >= 0) if((r=this[i]-a[i]) != 0) return r; - return 0; -} - -// returns bit length of the integer x -function nbits(x) { - var r = 1, t; - if((t=x>>>16) != 0) { x = t; r += 16; } - if((t=x>>8) != 0) { x = t; r += 8; } - if((t=x>>4) != 0) { x = t; r += 4; } - if((t=x>>2) != 0) { x = t; r += 2; } - if((t=x>>1) != 0) { x = t; r += 1; } - return r; -} - -// (public) return the number of bits in "this" -function bnBitLength() { - if(this.t <= 0) return 0; - return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM)); -} - -// (protected) r = this << n*DB -function bnpDLShiftTo(n,r) { - var i; - for(i = this.t-1; i >= 0; --i) r[i+n] = this[i]; - for(i = n-1; i >= 0; --i) r[i] = 0; - r.t = this.t+n; - r.s = this.s; -} - -// (protected) r = this >> n*DB -function bnpDRShiftTo(n,r) { - for(var i = n; i < this.t; ++i) r[i-n] = this[i]; - r.t = Math.max(this.t-n,0); - r.s = this.s; -} - -// (protected) r = this << n -function bnpLShiftTo(n,r) { - var bs = n%this.DB; - var cbs = this.DB-bs; - var bm = (1<= 0; --i) { - r[i+ds+1] = (this[i]>>cbs)|c; - c = (this[i]&bm)<= 0; --i) r[i] = 0; - r[ds] = c; - r.t = this.t+ds+1; - r.s = this.s; - r.clamp(); -} - -// (protected) r = this >> n -function bnpRShiftTo(n,r) { - r.s = this.s; - var ds = Math.floor(n/this.DB); - if(ds >= this.t) { r.t = 0; return; } - var bs = n%this.DB; - var cbs = this.DB-bs; - var bm = (1<>bs; - for(var i = ds+1; i < this.t; ++i) { - r[i-ds-1] |= (this[i]&bm)<>bs; - } - if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<>= this.DB; - } - if(a.t < this.t) { - c -= a.s; - while(i < this.t) { - c += this[i]; - r[i++] = c&this.DM; - c >>= this.DB; - } - c += this.s; - } - else { - c += this.s; - while(i < a.t) { - c -= a[i]; - r[i++] = c&this.DM; - c >>= this.DB; - } - c -= a.s; - } - r.s = (c<0)?-1:0; - if(c < -1) r[i++] = this.DV+c; - else if(c > 0) r[i++] = c; - r.t = i; - r.clamp(); -} - -// (protected) r = this * a, r != this,a (HAC 14.12) -// "this" should be the larger one if appropriate. -function bnpMultiplyTo(a,r) { - var x = this.abs(), y = a.abs(); - var i = x.t; - r.t = i+y.t; - while(--i >= 0) r[i] = 0; - for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t); - r.s = 0; - r.clamp(); - if(this.s != a.s) BigInteger.ZERO.subTo(r,r); -} - -// (protected) r = this^2, r != this (HAC 14.16) -function bnpSquareTo(r) { - var x = this.abs(); - var i = r.t = 2*x.t; - while(--i >= 0) r[i] = 0; - for(i = 0; i < x.t-1; ++i) { - var c = x.am(i,x[i],r,2*i,0,1); - if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) { - r[i+x.t] -= x.DV; - r[i+x.t+1] = 1; - } - } - if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1); - r.s = 0; - r.clamp(); -} - -// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20) -// r != q, this != m. q or r may be null. -function bnpDivRemTo(m,q,r) { - var pm = m.abs(); - if(pm.t <= 0) return; - var pt = this.abs(); - if(pt.t < pm.t) { - if(q != null) q.fromInt(0); - if(r != null) this.copyTo(r); - return; - } - if(r == null) r = nbi(); - var y = nbi(), ts = this.s, ms = m.s; - var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus - if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); } - else { pm.copyTo(y); pt.copyTo(r); } - var ys = y.t; - var y0 = y[ys-1]; - if(y0 == 0) return; - var yt = y0*(1<1)?y[ys-2]>>this.F2:0); - var d1 = this.FV/yt, d2 = (1<= 0) { - r[r.t++] = 1; - r.subTo(t,r); - } - BigInteger.ONE.dlShiftTo(ys,t); - t.subTo(y,y); // "negative" y so we can replace sub with am later - while(y.t < ys) y[y.t++] = 0; - while(--j >= 0) { - // Estimate quotient digit - var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2); - if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out - y.dlShiftTo(j,t); - r.subTo(t,r); - while(r[i] < --qd) r.subTo(t,r); - } - } - if(q != null) { - r.drShiftTo(ys,q); - if(ts != ms) BigInteger.ZERO.subTo(q,q); - } - r.t = ys; - r.clamp(); - if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder - if(ts < 0) BigInteger.ZERO.subTo(r,r); -} - -// (public) this mod a -function bnMod(a) { - var r = nbi(); - this.abs().divRemTo(a,null,r); - if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r); - return r; -} - -// Modular reduction using "classic" algorithm -function Classic(m) { this.m = m; } -function cConvert(x) { - if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m); - else return x; -} -function cRevert(x) { return x; } -function cReduce(x) { x.divRemTo(this.m,null,x); } -function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } -function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); } - -Classic.prototype.convert = cConvert; -Classic.prototype.revert = cRevert; -Classic.prototype.reduce = cReduce; -Classic.prototype.mulTo = cMulTo; -Classic.prototype.sqrTo = cSqrTo; - -// (protected) return "-1/this % 2^DB"; useful for Mont. reduction -// justification: -// xy == 1 (mod m) -// xy = 1+km -// xy(2-xy) = (1+km)(1-km) -// x[y(2-xy)] = 1-k^2m^2 -// x[y(2-xy)] == 1 (mod m^2) -// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2 -// should reduce x and y(2-xy) by m^2 at each step to keep size bounded. -// JS multiply "overflows" differently from C/C++, so care is needed here. -function bnpInvDigit() { - if(this.t < 1) return 0; - var x = this[0]; - if((x&1) == 0) return 0; - var y = x&3; // y == 1/x mod 2^2 - y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4 - y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8 - y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16 - // last step - calculate inverse mod DV directly; - // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints - y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits - // we really want the negative inverse, and -DV < y < DV - return (y>0)?this.DV-y:-y; -} - -// Montgomery reduction -function Montgomery(m) { - this.m = m; - this.mp = m.invDigit(); - this.mpl = this.mp&0x7fff; - this.mph = this.mp>>15; - this.um = (1<<(m.DB-15))-1; - this.mt2 = 2*m.t; -} - -// xR mod m -function montConvert(x) { - var r = nbi(); - x.abs().dlShiftTo(this.m.t,r); - r.divRemTo(this.m,null,r); - if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r); - return r; -} - -// x/R mod m -function montRevert(x) { - var r = nbi(); - x.copyTo(r); - this.reduce(r); - return r; -} - -// x = x/R mod m (HAC 14.32) -function montReduce(x) { - while(x.t <= this.mt2) // pad x so am has enough room later - x[x.t++] = 0; - for(var i = 0; i < this.m.t; ++i) { - // faster way of calculating u0 = x[i]*mp mod DV - var j = x[i]&0x7fff; - var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM; - // use am to combine the multiply-shift-add into one call - j = i+this.m.t; - x[j] += this.m.am(0,u0,x,i,0,this.m.t); - // propagate carry - while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; } - } - x.clamp(); - x.drShiftTo(this.m.t,x); - if(x.compareTo(this.m) >= 0) x.subTo(this.m,x); -} - -// r = "x^2/R mod m"; x != r -function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); } - -// r = "xy/R mod m"; x,y != r -function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } - -Montgomery.prototype.convert = montConvert; -Montgomery.prototype.revert = montRevert; -Montgomery.prototype.reduce = montReduce; -Montgomery.prototype.mulTo = montMulTo; -Montgomery.prototype.sqrTo = montSqrTo; - -// (protected) true iff this is even -function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; } - -// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79) -function bnpExp(e,z) { - if(e > 0xffffffff || e < 1) return BigInteger.ONE; - var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1; - g.copyTo(r); - while(--i >= 0) { - z.sqrTo(r,r2); - if((e&(1< 0) z.mulTo(r2,g,r); - else { var t = r; r = r2; r2 = t; } - } - return z.revert(r); -} - -// (public) this^e % m, 0 <= e < 2^32 -function bnModPowInt(e,m) { - var z; - if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m); - return this.exp(e,z); -} - -// protected -BigInteger.prototype.copyTo = bnpCopyTo; -BigInteger.prototype.fromInt = bnpFromInt; -BigInteger.prototype.fromString = bnpFromString; -BigInteger.prototype.clamp = bnpClamp; -BigInteger.prototype.dlShiftTo = bnpDLShiftTo; -BigInteger.prototype.drShiftTo = bnpDRShiftTo; -BigInteger.prototype.lShiftTo = bnpLShiftTo; -BigInteger.prototype.rShiftTo = bnpRShiftTo; -BigInteger.prototype.subTo = bnpSubTo; -BigInteger.prototype.multiplyTo = bnpMultiplyTo; -BigInteger.prototype.squareTo = bnpSquareTo; -BigInteger.prototype.divRemTo = bnpDivRemTo; -BigInteger.prototype.invDigit = bnpInvDigit; -BigInteger.prototype.isEven = bnpIsEven; -BigInteger.prototype.exp = bnpExp; - -// public -BigInteger.prototype.toString = bnToString; -BigInteger.prototype.negate = bnNegate; -BigInteger.prototype.abs = bnAbs; -BigInteger.prototype.compareTo = bnCompareTo; -BigInteger.prototype.bitLength = bnBitLength; -BigInteger.prototype.mod = bnMod; -BigInteger.prototype.modPowInt = bnModPowInt; - -// "constants" -BigInteger.ZERO = nbv(0); -BigInteger.ONE = nbv(1); - -this.BigInteger = BigInteger; -// Copyright (c) 2005-2009 Tom Wu -// All Rights Reserved. -// See "LICENSE" for details. - -// Extended JavaScript BN functions, required for RSA private ops. - -// Version 1.1: new BigInteger("0", 10) returns "proper" zero - -// (public) -function bnClone() { var r = nbi(); this.copyTo(r); return r; } - -// (public) return value as integer -function bnIntValue() { - if(this.s < 0) { - if(this.t == 1) return this[0]-this.DV; - else if(this.t == 0) return -1; - } - else if(this.t == 1) return this[0]; - else if(this.t == 0) return 0; - // assumes 16 < DB < 32 - return ((this[1]&((1<<(32-this.DB))-1))<>24; } - -// (public) return value as short (assumes DB>=16) -function bnShortValue() { return (this.t==0)?this.s:(this[0]<<16)>>16; } - -// (protected) return x s.t. r^x < DV -function bnpChunkSize(r) { return Math.floor(Math.LN2*this.DB/Math.log(r)); } - -// (public) 0 if this == 0, 1 if this > 0 -function bnSigNum() { - if(this.s < 0) return -1; - else if(this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0; - else return 1; -} - -// (protected) convert to radix string -function bnpToRadix(b) { - if(b == null) b = 10; - if(this.signum() == 0 || b < 2 || b > 36) return "0"; - var cs = this.chunkSize(b); - var a = Math.pow(b,cs); - var d = nbv(a), y = nbi(), z = nbi(), r = ""; - this.divRemTo(d,y,z); - while(y.signum() > 0) { - r = (a+z.intValue()).toString(b).substr(1) + r; - y.divRemTo(d,y,z); - } - return z.intValue().toString(b) + r; -} - -// (protected) convert from radix string -function bnpFromRadix(s,b) { - this.fromInt(0); - if(b == null) b = 10; - var cs = this.chunkSize(b); - var d = Math.pow(b,cs), mi = false, j = 0, w = 0; - for(var i = 0; i < s.length; ++i) { - var x = intAt(s,i); - if(x < 0) { - if(s.charAt(i) == "-" && this.signum() == 0) mi = true; - continue; - } - w = b*w+x; - if(++j >= cs) { - this.dMultiply(d); - this.dAddOffset(w,0); - j = 0; - w = 0; - } - } - if(j > 0) { - this.dMultiply(Math.pow(b,j)); - this.dAddOffset(w,0); - } - if(mi) BigInteger.ZERO.subTo(this,this); -} - -// (protected) alternate constructor -function bnpFromNumber(a,b,c) { - if("number" == typeof b) { - // new BigInteger(int,int,RNG) - if(a < 2) this.fromInt(1); - else { - this.fromNumber(a,c); - if(!this.testBit(a-1)) // force MSB set - this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this); - if(this.isEven()) this.dAddOffset(1,0); // force odd - while(!this.isProbablePrime(b)) { - this.dAddOffset(2,0); - if(this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a-1),this); - } - } - } - else { - // new BigInteger(int,RNG) - var x = new Array(), t = a&7; - x.length = (a>>3)+1; - b.nextBytes(x); - if(t > 0) x[0] &= ((1< 0) { - if(p < this.DB && (d = this[i]>>p) != (this.s&this.DM)>>p) - r[k++] = d|(this.s<<(this.DB-p)); - while(i >= 0) { - if(p < 8) { - d = (this[i]&((1<>(p+=this.DB-8); - } - else { - d = (this[i]>>(p-=8))&0xff; - if(p <= 0) { p += this.DB; --i; } - } - if((d&0x80) != 0) d |= -256; - if(k == 0 && (this.s&0x80) != (d&0x80)) ++k; - if(k > 0 || d != this.s) r[k++] = d; - } - } - return r; -} - -function bnEquals(a) { return(this.compareTo(a)==0); } -function bnMin(a) { return(this.compareTo(a)<0)?this:a; } -function bnMax(a) { return(this.compareTo(a)>0)?this:a; } - -// (protected) r = this op a (bitwise) -function bnpBitwiseTo(a,op,r) { - var i, f, m = Math.min(a.t,this.t); - for(i = 0; i < m; ++i) r[i] = op(this[i],a[i]); - if(a.t < this.t) { - f = a.s&this.DM; - for(i = m; i < this.t; ++i) r[i] = op(this[i],f); - r.t = this.t; - } - else { - f = this.s&this.DM; - for(i = m; i < a.t; ++i) r[i] = op(f,a[i]); - r.t = a.t; - } - r.s = op(this.s,a.s); - r.clamp(); -} - -// (public) this & a -function op_and(x,y) { return x&y; } -function bnAnd(a) { var r = nbi(); this.bitwiseTo(a,op_and,r); return r; } - -// (public) this | a -function op_or(x,y) { return x|y; } -function bnOr(a) { var r = nbi(); this.bitwiseTo(a,op_or,r); return r; } - -// (public) this ^ a -function op_xor(x,y) { return x^y; } -function bnXor(a) { var r = nbi(); this.bitwiseTo(a,op_xor,r); return r; } - -// (public) this & ~a -function op_andnot(x,y) { return x&~y; } -function bnAndNot(a) { var r = nbi(); this.bitwiseTo(a,op_andnot,r); return r; } - -// (public) ~this -function bnNot() { - var r = nbi(); - for(var i = 0; i < this.t; ++i) r[i] = this.DM&~this[i]; - r.t = this.t; - r.s = ~this.s; - return r; -} - -// (public) this << n -function bnShiftLeft(n) { - var r = nbi(); - if(n < 0) this.rShiftTo(-n,r); else this.lShiftTo(n,r); - return r; -} - -// (public) this >> n -function bnShiftRight(n) { - var r = nbi(); - if(n < 0) this.lShiftTo(-n,r); else this.rShiftTo(n,r); - return r; -} - -// return index of lowest 1-bit in x, x < 2^31 -function lbit(x) { - if(x == 0) return -1; - var r = 0; - if((x&0xffff) == 0) { x >>= 16; r += 16; } - if((x&0xff) == 0) { x >>= 8; r += 8; } - if((x&0xf) == 0) { x >>= 4; r += 4; } - if((x&3) == 0) { x >>= 2; r += 2; } - if((x&1) == 0) ++r; - return r; -} - -// (public) returns index of lowest 1-bit (or -1 if none) -function bnGetLowestSetBit() { - for(var i = 0; i < this.t; ++i) - if(this[i] != 0) return i*this.DB+lbit(this[i]); - if(this.s < 0) return this.t*this.DB; - return -1; -} - -// return number of 1 bits in x -function cbit(x) { - var r = 0; - while(x != 0) { x &= x-1; ++r; } - return r; -} - -// (public) return number of set bits -function bnBitCount() { - var r = 0, x = this.s&this.DM; - for(var i = 0; i < this.t; ++i) r += cbit(this[i]^x); - return r; -} - -// (public) true iff nth bit is set -function bnTestBit(n) { - var j = Math.floor(n/this.DB); - if(j >= this.t) return(this.s!=0); - return((this[j]&(1<<(n%this.DB)))!=0); -} - -// (protected) this op (1<>= this.DB; - } - if(a.t < this.t) { - c += a.s; - while(i < this.t) { - c += this[i]; - r[i++] = c&this.DM; - c >>= this.DB; - } - c += this.s; - } - else { - c += this.s; - while(i < a.t) { - c += a[i]; - r[i++] = c&this.DM; - c >>= this.DB; - } - c += a.s; - } - r.s = (c<0)?-1:0; - if(c > 0) r[i++] = c; - else if(c < -1) r[i++] = this.DV+c; - r.t = i; - r.clamp(); -} - -// (public) this + a -function bnAdd(a) { var r = nbi(); this.addTo(a,r); return r; } - -// (public) this - a -function bnSubtract(a) { var r = nbi(); this.subTo(a,r); return r; } - -// (public) this * a -function bnMultiply(a) { var r = nbi(); this.multiplyTo(a,r); return r; } - -// (public) this / a -function bnDivide(a) { var r = nbi(); this.divRemTo(a,r,null); return r; } - -// (public) this % a -function bnRemainder(a) { var r = nbi(); this.divRemTo(a,null,r); return r; } - -// (public) [this/a,this%a] -function bnDivideAndRemainder(a) { - var q = nbi(), r = nbi(); - this.divRemTo(a,q,r); - return new Array(q,r); -} - -// (protected) this *= n, this >= 0, 1 < n < DV -function bnpDMultiply(n) { - this[this.t] = this.am(0,n-1,this,0,0,this.t); - ++this.t; - this.clamp(); -} - -// (protected) this += n << w words, this >= 0 -function bnpDAddOffset(n,w) { - if(n == 0) return; - while(this.t <= w) this[this.t++] = 0; - this[w] += n; - while(this[w] >= this.DV) { - this[w] -= this.DV; - if(++w >= this.t) this[this.t++] = 0; - ++this[w]; - } -} - -// A "null" reducer -function NullExp() {} -function nNop(x) { return x; } -function nMulTo(x,y,r) { x.multiplyTo(y,r); } -function nSqrTo(x,r) { x.squareTo(r); } - -NullExp.prototype.convert = nNop; -NullExp.prototype.revert = nNop; -NullExp.prototype.mulTo = nMulTo; -NullExp.prototype.sqrTo = nSqrTo; - -// (public) this^e -function bnPow(e) { return this.exp(e,new NullExp()); } - -// (protected) r = lower n words of "this * a", a.t <= n -// "this" should be the larger one if appropriate. -function bnpMultiplyLowerTo(a,n,r) { - var i = Math.min(this.t+a.t,n); - r.s = 0; // assumes a,this >= 0 - r.t = i; - while(i > 0) r[--i] = 0; - var j; - for(j = r.t-this.t; i < j; ++i) r[i+this.t] = this.am(0,a[i],r,i,0,this.t); - for(j = Math.min(a.t,n); i < j; ++i) this.am(0,a[i],r,i,0,n-i); - r.clamp(); -} - -// (protected) r = "this * a" without lower n words, n > 0 -// "this" should be the larger one if appropriate. -function bnpMultiplyUpperTo(a,n,r) { - --n; - var i = r.t = this.t+a.t-n; - r.s = 0; // assumes a,this >= 0 - while(--i >= 0) r[i] = 0; - for(i = Math.max(n-this.t,0); i < a.t; ++i) - r[this.t+i-n] = this.am(n-i,a[i],r,0,0,this.t+i-n); - r.clamp(); - r.drShiftTo(1,r); -} - -// Barrett modular reduction -function Barrett(m) { - // setup Barrett - this.r2 = nbi(); - this.q3 = nbi(); - BigInteger.ONE.dlShiftTo(2*m.t,this.r2); - this.mu = this.r2.divide(m); - this.m = m; -} - -function barrettConvert(x) { - if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m); - else if(x.compareTo(this.m) < 0) return x; - else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; } -} - -function barrettRevert(x) { return x; } - -// x = x mod m (HAC 14.42) -function barrettReduce(x) { - x.drShiftTo(this.m.t-1,this.r2); - if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); } - this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3); - this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2); - while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1); - x.subTo(this.r2,x); - while(x.compareTo(this.m) >= 0) x.subTo(this.m,x); -} - -// r = x^2 mod m; x != r -function barrettSqrTo(x,r) { x.squareTo(r); this.reduce(r); } - -// r = x*y mod m; x,y != r -function barrettMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } - -Barrett.prototype.convert = barrettConvert; -Barrett.prototype.revert = barrettRevert; -Barrett.prototype.reduce = barrettReduce; -Barrett.prototype.mulTo = barrettMulTo; -Barrett.prototype.sqrTo = barrettSqrTo; - -// (public) this^e % m (HAC 14.85) -function bnModPow(e,m) { - var i = e.bitLength(), k, r = nbv(1), z; - if(i <= 0) return r; - else if(i < 18) k = 1; - else if(i < 48) k = 3; - else if(i < 144) k = 4; - else if(i < 768) k = 5; - else k = 6; - if(i < 8) - z = new Classic(m); - else if(m.isEven()) - z = new Barrett(m); - else - z = new Montgomery(m); - - // precomputation - var g = new Array(), n = 3, k1 = k-1, km = (1< 1) { - var g2 = nbi(); - z.sqrTo(g[1],g2); - while(n <= km) { - g[n] = nbi(); - z.mulTo(g2,g[n-2],g[n]); - n += 2; - } - } - - var j = e.t-1, w, is1 = true, r2 = nbi(), t; - i = nbits(e[j])-1; - while(j >= 0) { - if(i >= k1) w = (e[j]>>(i-k1))&km; - else { - w = (e[j]&((1<<(i+1))-1))<<(k1-i); - if(j > 0) w |= e[j-1]>>(this.DB+i-k1); - } - - n = k; - while((w&1) == 0) { w >>= 1; --n; } - if((i -= n) < 0) { i += this.DB; --j; } - if(is1) { // ret == 1, don't bother squaring or multiplying it - g[w].copyTo(r); - is1 = false; - } - else { - while(n > 1) { z.sqrTo(r,r2); z.sqrTo(r2,r); n -= 2; } - if(n > 0) z.sqrTo(r,r2); else { t = r; r = r2; r2 = t; } - z.mulTo(r2,g[w],r); - } - - while(j >= 0 && (e[j]&(1< 0) { - x.rShiftTo(g,x); - y.rShiftTo(g,y); - } - while(x.signum() > 0) { - if((i = x.getLowestSetBit()) > 0) x.rShiftTo(i,x); - if((i = y.getLowestSetBit()) > 0) y.rShiftTo(i,y); - if(x.compareTo(y) >= 0) { - x.subTo(y,x); - x.rShiftTo(1,x); - } - else { - y.subTo(x,y); - y.rShiftTo(1,y); - } - } - if(g > 0) y.lShiftTo(g,y); - return y; -} - -// (protected) this % n, n < 2^26 -function bnpModInt(n) { - if(n <= 0) return 0; - var d = this.DV%n, r = (this.s<0)?n-1:0; - if(this.t > 0) - if(d == 0) r = this[0]%n; - else for(var i = this.t-1; i >= 0; --i) r = (d*r+this[i])%n; - return r; -} - -// (public) 1/this % m (HAC 14.61) -function bnModInverse(m) { - var ac = m.isEven(); - if((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO; - var u = m.clone(), v = this.clone(); - var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1); - while(u.signum() != 0) { - while(u.isEven()) { - u.rShiftTo(1,u); - if(ac) { - if(!a.isEven() || !b.isEven()) { a.addTo(this,a); b.subTo(m,b); } - a.rShiftTo(1,a); - } - else if(!b.isEven()) b.subTo(m,b); - b.rShiftTo(1,b); - } - while(v.isEven()) { - v.rShiftTo(1,v); - if(ac) { - if(!c.isEven() || !d.isEven()) { c.addTo(this,c); d.subTo(m,d); } - c.rShiftTo(1,c); - } - else if(!d.isEven()) d.subTo(m,d); - d.rShiftTo(1,d); - } - if(u.compareTo(v) >= 0) { - u.subTo(v,u); - if(ac) a.subTo(c,a); - b.subTo(d,b); - } - else { - v.subTo(u,v); - if(ac) c.subTo(a,c); - d.subTo(b,d); - } - } - if(v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO; - if(d.compareTo(m) >= 0) return d.subtract(m); - if(d.signum() < 0) d.addTo(m,d); else return d; - if(d.signum() < 0) return d.add(m); else return d; -} - -var lowprimes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509]; -var lplim = (1<<26)/lowprimes[lowprimes.length-1]; - -// (public) test primality with certainty >= 1-.5^t -function bnIsProbablePrime(t) { - var i, x = this.abs(); - if(x.t == 1 && x[0] <= lowprimes[lowprimes.length-1]) { - for(i = 0; i < lowprimes.length; ++i) - if(x[0] == lowprimes[i]) return true; - return false; - } - if(x.isEven()) return false; - i = 1; - while(i < lowprimes.length) { - var m = lowprimes[i], j = i+1; - while(j < lowprimes.length && m < lplim) m *= lowprimes[j++]; - m = x.modInt(m); - while(i < j) if(m%lowprimes[i++] == 0) return false; - } - return x.millerRabin(t); -} - -// (protected) true if probably prime (HAC 4.24, Miller-Rabin) -function bnpMillerRabin(t) { - var n1 = this.subtract(BigInteger.ONE); - var k = n1.getLowestSetBit(); - if(k <= 0) return false; - var r = n1.shiftRight(k); - t = (t+1)>>1; - if(t > lowprimes.length) t = lowprimes.length; - var a = nbi(); - for(var i = 0; i < t; ++i) { - a.fromInt(lowprimes[i]); - var y = a.modPow(r,this); - if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { - var j = 1; - while(j++ < k && y.compareTo(n1) != 0) { - y = y.modPowInt(2,this); - if(y.compareTo(BigInteger.ONE) == 0) return false; - } - if(y.compareTo(n1) != 0) return false; - } - } - return true; -} - -// protected -BigInteger.prototype.chunkSize = bnpChunkSize; -BigInteger.prototype.toRadix = bnpToRadix; -BigInteger.prototype.fromRadix = bnpFromRadix; -BigInteger.prototype.fromNumber = bnpFromNumber; -BigInteger.prototype.bitwiseTo = bnpBitwiseTo; -BigInteger.prototype.changeBit = bnpChangeBit; -BigInteger.prototype.addTo = bnpAddTo; -BigInteger.prototype.dMultiply = bnpDMultiply; -BigInteger.prototype.dAddOffset = bnpDAddOffset; -BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo; -BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo; -BigInteger.prototype.modInt = bnpModInt; -BigInteger.prototype.millerRabin = bnpMillerRabin; - -// public -BigInteger.prototype.clone = bnClone; -BigInteger.prototype.intValue = bnIntValue; -BigInteger.prototype.byteValue = bnByteValue; -BigInteger.prototype.shortValue = bnShortValue; -BigInteger.prototype.signum = bnSigNum; -BigInteger.prototype.toByteArray = bnToByteArray; -BigInteger.prototype.equals = bnEquals; -BigInteger.prototype.min = bnMin; -BigInteger.prototype.max = bnMax; -BigInteger.prototype.and = bnAnd; -BigInteger.prototype.or = bnOr; -BigInteger.prototype.xor = bnXor; -BigInteger.prototype.andNot = bnAndNot; -BigInteger.prototype.not = bnNot; -BigInteger.prototype.shiftLeft = bnShiftLeft; -BigInteger.prototype.shiftRight = bnShiftRight; -BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit; -BigInteger.prototype.bitCount = bnBitCount; -BigInteger.prototype.testBit = bnTestBit; -BigInteger.prototype.setBit = bnSetBit; -BigInteger.prototype.clearBit = bnClearBit; -BigInteger.prototype.flipBit = bnFlipBit; -BigInteger.prototype.add = bnAdd; -BigInteger.prototype.subtract = bnSubtract; -BigInteger.prototype.multiply = bnMultiply; -BigInteger.prototype.divide = bnDivide; -BigInteger.prototype.remainder = bnRemainder; -BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder; -BigInteger.prototype.modPow = bnModPow; -BigInteger.prototype.modInverse = bnModInverse; -BigInteger.prototype.pow = bnPow; -BigInteger.prototype.gcd = bnGCD; -BigInteger.prototype.isProbablePrime = bnIsProbablePrime; - -// BigInteger interfaces not implemented in jsbn: - -// BigInteger(int signum, byte[] magnitude) -// double doubleValue() -// float floatValue() -// int hashCode() -// long longValue() -// static BigInteger valueOf(long val) - -this.BigInteger = BigInteger; diff --git a/node_modules/ipv6/lib/browser/jsbn.js b/node_modules/ipv6/lib/browser/jsbn.js deleted file mode 100644 index 928cc4f..0000000 --- a/node_modules/ipv6/lib/browser/jsbn.js +++ /dev/null @@ -1,559 +0,0 @@ -// Copyright (c) 2005 Tom Wu -// All Rights Reserved. -// See "LICENSE" for details. - -// Basic JavaScript BN library - subset useful for RSA encryption. - -// Bits per digit -var dbits; - -// JavaScript engine analysis -var canary = 0xdeadbeefcafe; -var j_lm = ((canary&0xffffff)==0xefcafe); - -// (public) Constructor -function BigInteger(a,b,c) { - if(a != null) - if("number" == typeof a) this.fromNumber(a,b,c); - else if(b == null && "string" != typeof a) this.fromString(a,256); - else this.fromString(a,b); -} - -// return new, unset BigInteger -function nbi() { return new BigInteger(null); } - -// am: Compute w_j += (x*this_i), propagate carries, -// c is initial carry, returns final carry. -// c < 3*dvalue, x < 2*dvalue, this_i < dvalue -// We need to select the fastest one that works in this environment. - -// am1: use a single mult and divide to get the high bits, -// max digit bits should be 26 because -// max internal value = 2*dvalue^2-2*dvalue (< 2^53) -function am1(i,x,w,j,c,n) { - while(--n >= 0) { - var v = x*this[i++]+w[j]+c; - c = Math.floor(v/0x4000000); - w[j++] = v&0x3ffffff; - } - return c; -} -// am2 avoids a big mult-and-extract completely. -// Max digit bits should be <= 30 because we do bitwise ops -// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31) -function am2(i,x,w,j,c,n) { - var xl = x&0x7fff, xh = x>>15; - while(--n >= 0) { - var l = this[i]&0x7fff; - var h = this[i++]>>15; - var m = xh*l+h*xl; - l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff); - c = (l>>>30)+(m>>>15)+xh*h+(c>>>30); - w[j++] = l&0x3fffffff; - } - return c; -} -// Alternately, set max digit bits to 28 since some -// browsers slow down when dealing with 32-bit numbers. -function am3(i,x,w,j,c,n) { - var xl = x&0x3fff, xh = x>>14; - while(--n >= 0) { - var l = this[i]&0x3fff; - var h = this[i++]>>14; - var m = xh*l+h*xl; - l = xl*l+((m&0x3fff)<<14)+w[j]+c; - c = (l>>28)+(m>>14)+xh*h; - w[j++] = l&0xfffffff; - } - return c; -} -if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) { - BigInteger.prototype.am = am2; - dbits = 30; -} -else if(j_lm && (navigator.appName != "Netscape")) { - BigInteger.prototype.am = am1; - dbits = 26; -} -else { // Mozilla/Netscape seems to prefer am3 - BigInteger.prototype.am = am3; - dbits = 28; -} - -BigInteger.prototype.DB = dbits; -BigInteger.prototype.DM = ((1<= 0; --i) r[i] = this[i]; - r.t = this.t; - r.s = this.s; -} - -// (protected) set from integer value x, -DV <= x < DV -function bnpFromInt(x) { - this.t = 1; - this.s = (x<0)?-1:0; - if(x > 0) this[0] = x; - else if(x < -1) this[0] = x+DV; - else this.t = 0; -} - -// return bigint initialized to value -function nbv(i) { var r = nbi(); r.fromInt(i); return r; } - -// (protected) set from string and radix -function bnpFromString(s,b) { - var k; - if(b == 16) k = 4; - else if(b == 8) k = 3; - else if(b == 256) k = 8; // byte array - else if(b == 2) k = 1; - else if(b == 32) k = 5; - else if(b == 4) k = 2; - else { this.fromRadix(s,b); return; } - this.t = 0; - this.s = 0; - var i = s.length, mi = false, sh = 0; - while(--i >= 0) { - var x = (k==8)?s[i]&0xff:intAt(s,i); - if(x < 0) { - if(s.charAt(i) == "-") mi = true; - continue; - } - mi = false; - if(sh == 0) - this[this.t++] = x; - else if(sh+k > this.DB) { - this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<>(this.DB-sh)); - } - else - this[this.t-1] |= x<= this.DB) sh -= this.DB; - } - if(k == 8 && (s[0]&0x80) != 0) { - this.s = -1; - if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)< 0 && this[this.t-1] == c) --this.t; -} - -// (public) return string representation in given radix -function bnToString(b) { - if(this.s < 0) return "-"+this.negate().toString(b); - var k; - if(b == 16) k = 4; - else if(b == 8) k = 3; - else if(b == 2) k = 1; - else if(b == 32) k = 5; - else if(b == 4) k = 2; - else return this.toRadix(b); - var km = (1< 0) { - if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); } - while(i >= 0) { - if(p < k) { - d = (this[i]&((1<>(p+=this.DB-k); - } - else { - d = (this[i]>>(p-=k))&km; - if(p <= 0) { p += this.DB; --i; } - } - if(d > 0) m = true; - if(m) r += int2char(d); - } - } - return m?r:"0"; -} - -// (public) -this -function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; } - -// (public) |this| -function bnAbs() { return (this.s<0)?this.negate():this; } - -// (public) return + if this > a, - if this < a, 0 if equal -function bnCompareTo(a) { - var r = this.s-a.s; - if(r != 0) return r; - var i = this.t; - r = i-a.t; - if(r != 0) return r; - while(--i >= 0) if((r=this[i]-a[i]) != 0) return r; - return 0; -} - -// returns bit length of the integer x -function nbits(x) { - var r = 1, t; - if((t=x>>>16) != 0) { x = t; r += 16; } - if((t=x>>8) != 0) { x = t; r += 8; } - if((t=x>>4) != 0) { x = t; r += 4; } - if((t=x>>2) != 0) { x = t; r += 2; } - if((t=x>>1) != 0) { x = t; r += 1; } - return r; -} - -// (public) return the number of bits in "this" -function bnBitLength() { - if(this.t <= 0) return 0; - return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM)); -} - -// (protected) r = this << n*DB -function bnpDLShiftTo(n,r) { - var i; - for(i = this.t-1; i >= 0; --i) r[i+n] = this[i]; - for(i = n-1; i >= 0; --i) r[i] = 0; - r.t = this.t+n; - r.s = this.s; -} - -// (protected) r = this >> n*DB -function bnpDRShiftTo(n,r) { - for(var i = n; i < this.t; ++i) r[i-n] = this[i]; - r.t = Math.max(this.t-n,0); - r.s = this.s; -} - -// (protected) r = this << n -function bnpLShiftTo(n,r) { - var bs = n%this.DB; - var cbs = this.DB-bs; - var bm = (1<= 0; --i) { - r[i+ds+1] = (this[i]>>cbs)|c; - c = (this[i]&bm)<= 0; --i) r[i] = 0; - r[ds] = c; - r.t = this.t+ds+1; - r.s = this.s; - r.clamp(); -} - -// (protected) r = this >> n -function bnpRShiftTo(n,r) { - r.s = this.s; - var ds = Math.floor(n/this.DB); - if(ds >= this.t) { r.t = 0; return; } - var bs = n%this.DB; - var cbs = this.DB-bs; - var bm = (1<>bs; - for(var i = ds+1; i < this.t; ++i) { - r[i-ds-1] |= (this[i]&bm)<>bs; - } - if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<>= this.DB; - } - if(a.t < this.t) { - c -= a.s; - while(i < this.t) { - c += this[i]; - r[i++] = c&this.DM; - c >>= this.DB; - } - c += this.s; - } - else { - c += this.s; - while(i < a.t) { - c -= a[i]; - r[i++] = c&this.DM; - c >>= this.DB; - } - c -= a.s; - } - r.s = (c<0)?-1:0; - if(c < -1) r[i++] = this.DV+c; - else if(c > 0) r[i++] = c; - r.t = i; - r.clamp(); -} - -// (protected) r = this * a, r != this,a (HAC 14.12) -// "this" should be the larger one if appropriate. -function bnpMultiplyTo(a,r) { - var x = this.abs(), y = a.abs(); - var i = x.t; - r.t = i+y.t; - while(--i >= 0) r[i] = 0; - for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t); - r.s = 0; - r.clamp(); - if(this.s != a.s) BigInteger.ZERO.subTo(r,r); -} - -// (protected) r = this^2, r != this (HAC 14.16) -function bnpSquareTo(r) { - var x = this.abs(); - var i = r.t = 2*x.t; - while(--i >= 0) r[i] = 0; - for(i = 0; i < x.t-1; ++i) { - var c = x.am(i,x[i],r,2*i,0,1); - if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) { - r[i+x.t] -= x.DV; - r[i+x.t+1] = 1; - } - } - if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1); - r.s = 0; - r.clamp(); -} - -// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20) -// r != q, this != m. q or r may be null. -function bnpDivRemTo(m,q,r) { - var pm = m.abs(); - if(pm.t <= 0) return; - var pt = this.abs(); - if(pt.t < pm.t) { - if(q != null) q.fromInt(0); - if(r != null) this.copyTo(r); - return; - } - if(r == null) r = nbi(); - var y = nbi(), ts = this.s, ms = m.s; - var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus - if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); } - else { pm.copyTo(y); pt.copyTo(r); } - var ys = y.t; - var y0 = y[ys-1]; - if(y0 == 0) return; - var yt = y0*(1<1)?y[ys-2]>>this.F2:0); - var d1 = this.FV/yt, d2 = (1<= 0) { - r[r.t++] = 1; - r.subTo(t,r); - } - BigInteger.ONE.dlShiftTo(ys,t); - t.subTo(y,y); // "negative" y so we can replace sub with am later - while(y.t < ys) y[y.t++] = 0; - while(--j >= 0) { - // Estimate quotient digit - var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2); - if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out - y.dlShiftTo(j,t); - r.subTo(t,r); - while(r[i] < --qd) r.subTo(t,r); - } - } - if(q != null) { - r.drShiftTo(ys,q); - if(ts != ms) BigInteger.ZERO.subTo(q,q); - } - r.t = ys; - r.clamp(); - if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder - if(ts < 0) BigInteger.ZERO.subTo(r,r); -} - -// (public) this mod a -function bnMod(a) { - var r = nbi(); - this.abs().divRemTo(a,null,r); - if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r); - return r; -} - -// Modular reduction using "classic" algorithm -function Classic(m) { this.m = m; } -function cConvert(x) { - if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m); - else return x; -} -function cRevert(x) { return x; } -function cReduce(x) { x.divRemTo(this.m,null,x); } -function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } -function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); } - -Classic.prototype.convert = cConvert; -Classic.prototype.revert = cRevert; -Classic.prototype.reduce = cReduce; -Classic.prototype.mulTo = cMulTo; -Classic.prototype.sqrTo = cSqrTo; - -// (protected) return "-1/this % 2^DB"; useful for Mont. reduction -// justification: -// xy == 1 (mod m) -// xy = 1+km -// xy(2-xy) = (1+km)(1-km) -// x[y(2-xy)] = 1-k^2m^2 -// x[y(2-xy)] == 1 (mod m^2) -// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2 -// should reduce x and y(2-xy) by m^2 at each step to keep size bounded. -// JS multiply "overflows" differently from C/C++, so care is needed here. -function bnpInvDigit() { - if(this.t < 1) return 0; - var x = this[0]; - if((x&1) == 0) return 0; - var y = x&3; // y == 1/x mod 2^2 - y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4 - y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8 - y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16 - // last step - calculate inverse mod DV directly; - // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints - y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits - // we really want the negative inverse, and -DV < y < DV - return (y>0)?this.DV-y:-y; -} - -// Montgomery reduction -function Montgomery(m) { - this.m = m; - this.mp = m.invDigit(); - this.mpl = this.mp&0x7fff; - this.mph = this.mp>>15; - this.um = (1<<(m.DB-15))-1; - this.mt2 = 2*m.t; -} - -// xR mod m -function montConvert(x) { - var r = nbi(); - x.abs().dlShiftTo(this.m.t,r); - r.divRemTo(this.m,null,r); - if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r); - return r; -} - -// x/R mod m -function montRevert(x) { - var r = nbi(); - x.copyTo(r); - this.reduce(r); - return r; -} - -// x = x/R mod m (HAC 14.32) -function montReduce(x) { - while(x.t <= this.mt2) // pad x so am has enough room later - x[x.t++] = 0; - for(var i = 0; i < this.m.t; ++i) { - // faster way of calculating u0 = x[i]*mp mod DV - var j = x[i]&0x7fff; - var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM; - // use am to combine the multiply-shift-add into one call - j = i+this.m.t; - x[j] += this.m.am(0,u0,x,i,0,this.m.t); - // propagate carry - while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; } - } - x.clamp(); - x.drShiftTo(this.m.t,x); - if(x.compareTo(this.m) >= 0) x.subTo(this.m,x); -} - -// r = "x^2/R mod m"; x != r -function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); } - -// r = "xy/R mod m"; x,y != r -function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } - -Montgomery.prototype.convert = montConvert; -Montgomery.prototype.revert = montRevert; -Montgomery.prototype.reduce = montReduce; -Montgomery.prototype.mulTo = montMulTo; -Montgomery.prototype.sqrTo = montSqrTo; - -// (protected) true iff this is even -function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; } - -// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79) -function bnpExp(e,z) { - if(e > 0xffffffff || e < 1) return BigInteger.ONE; - var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1; - g.copyTo(r); - while(--i >= 0) { - z.sqrTo(r,r2); - if((e&(1< 0) z.mulTo(r2,g,r); - else { var t = r; r = r2; r2 = t; } - } - return z.revert(r); -} - -// (public) this^e % m, 0 <= e < 2^32 -function bnModPowInt(e,m) { - var z; - if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m); - return this.exp(e,z); -} - -// protected -BigInteger.prototype.copyTo = bnpCopyTo; -BigInteger.prototype.fromInt = bnpFromInt; -BigInteger.prototype.fromString = bnpFromString; -BigInteger.prototype.clamp = bnpClamp; -BigInteger.prototype.dlShiftTo = bnpDLShiftTo; -BigInteger.prototype.drShiftTo = bnpDRShiftTo; -BigInteger.prototype.lShiftTo = bnpLShiftTo; -BigInteger.prototype.rShiftTo = bnpRShiftTo; -BigInteger.prototype.subTo = bnpSubTo; -BigInteger.prototype.multiplyTo = bnpMultiplyTo; -BigInteger.prototype.squareTo = bnpSquareTo; -BigInteger.prototype.divRemTo = bnpDivRemTo; -BigInteger.prototype.invDigit = bnpInvDigit; -BigInteger.prototype.isEven = bnpIsEven; -BigInteger.prototype.exp = bnpExp; - -// public -BigInteger.prototype.toString = bnToString; -BigInteger.prototype.negate = bnNegate; -BigInteger.prototype.abs = bnAbs; -BigInteger.prototype.compareTo = bnCompareTo; -BigInteger.prototype.bitLength = bnBitLength; -BigInteger.prototype.mod = bnMod; -BigInteger.prototype.modPowInt = bnModPowInt; - -// "constants" -BigInteger.ZERO = nbv(0); -BigInteger.ONE = nbv(1); diff --git a/node_modules/ipv6/lib/browser/jsbn2.js b/node_modules/ipv6/lib/browser/jsbn2.js deleted file mode 100644 index e53e00b..0000000 --- a/node_modules/ipv6/lib/browser/jsbn2.js +++ /dev/null @@ -1,648 +0,0 @@ -// Copyright (c) 2005-2009 Tom Wu -// All Rights Reserved. -// See "LICENSE" for details. - -// Extended JavaScript BN functions, required for RSA private ops. - -// Version 1.1: new BigInteger("0", 10) returns "proper" zero - -// (public) -function bnClone() { var r = nbi(); this.copyTo(r); return r; } - -// (public) return value as integer -function bnIntValue() { - if(this.s < 0) { - if(this.t == 1) return this[0]-this.DV; - else if(this.t == 0) return -1; - } - else if(this.t == 1) return this[0]; - else if(this.t == 0) return 0; - // assumes 16 < DB < 32 - return ((this[1]&((1<<(32-this.DB))-1))<>24; } - -// (public) return value as short (assumes DB>=16) -function bnShortValue() { return (this.t==0)?this.s:(this[0]<<16)>>16; } - -// (protected) return x s.t. r^x < DV -function bnpChunkSize(r) { return Math.floor(Math.LN2*this.DB/Math.log(r)); } - -// (public) 0 if this == 0, 1 if this > 0 -function bnSigNum() { - if(this.s < 0) return -1; - else if(this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0; - else return 1; -} - -// (protected) convert to radix string -function bnpToRadix(b) { - if(b == null) b = 10; - if(this.signum() == 0 || b < 2 || b > 36) return "0"; - var cs = this.chunkSize(b); - var a = Math.pow(b,cs); - var d = nbv(a), y = nbi(), z = nbi(), r = ""; - this.divRemTo(d,y,z); - while(y.signum() > 0) { - r = (a+z.intValue()).toString(b).substr(1) + r; - y.divRemTo(d,y,z); - } - return z.intValue().toString(b) + r; -} - -// (protected) convert from radix string -function bnpFromRadix(s,b) { - this.fromInt(0); - if(b == null) b = 10; - var cs = this.chunkSize(b); - var d = Math.pow(b,cs), mi = false, j = 0, w = 0; - for(var i = 0; i < s.length; ++i) { - var x = intAt(s,i); - if(x < 0) { - if(s.charAt(i) == "-" && this.signum() == 0) mi = true; - continue; - } - w = b*w+x; - if(++j >= cs) { - this.dMultiply(d); - this.dAddOffset(w,0); - j = 0; - w = 0; - } - } - if(j > 0) { - this.dMultiply(Math.pow(b,j)); - this.dAddOffset(w,0); - } - if(mi) BigInteger.ZERO.subTo(this,this); -} - -// (protected) alternate constructor -function bnpFromNumber(a,b,c) { - if("number" == typeof b) { - // new BigInteger(int,int,RNG) - if(a < 2) this.fromInt(1); - else { - this.fromNumber(a,c); - if(!this.testBit(a-1)) // force MSB set - this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this); - if(this.isEven()) this.dAddOffset(1,0); // force odd - while(!this.isProbablePrime(b)) { - this.dAddOffset(2,0); - if(this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a-1),this); - } - } - } - else { - // new BigInteger(int,RNG) - var x = new Array(), t = a&7; - x.length = (a>>3)+1; - b.nextBytes(x); - if(t > 0) x[0] &= ((1< 0) { - if(p < this.DB && (d = this[i]>>p) != (this.s&this.DM)>>p) - r[k++] = d|(this.s<<(this.DB-p)); - while(i >= 0) { - if(p < 8) { - d = (this[i]&((1<>(p+=this.DB-8); - } - else { - d = (this[i]>>(p-=8))&0xff; - if(p <= 0) { p += this.DB; --i; } - } - if((d&0x80) != 0) d |= -256; - if(k == 0 && (this.s&0x80) != (d&0x80)) ++k; - if(k > 0 || d != this.s) r[k++] = d; - } - } - return r; -} - -function bnEquals(a) { return(this.compareTo(a)==0); } -function bnMin(a) { return(this.compareTo(a)<0)?this:a; } -function bnMax(a) { return(this.compareTo(a)>0)?this:a; } - -// (protected) r = this op a (bitwise) -function bnpBitwiseTo(a,op,r) { - var i, f, m = Math.min(a.t,this.t); - for(i = 0; i < m; ++i) r[i] = op(this[i],a[i]); - if(a.t < this.t) { - f = a.s&this.DM; - for(i = m; i < this.t; ++i) r[i] = op(this[i],f); - r.t = this.t; - } - else { - f = this.s&this.DM; - for(i = m; i < a.t; ++i) r[i] = op(f,a[i]); - r.t = a.t; - } - r.s = op(this.s,a.s); - r.clamp(); -} - -// (public) this & a -function op_and(x,y) { return x&y; } -function bnAnd(a) { var r = nbi(); this.bitwiseTo(a,op_and,r); return r; } - -// (public) this | a -function op_or(x,y) { return x|y; } -function bnOr(a) { var r = nbi(); this.bitwiseTo(a,op_or,r); return r; } - -// (public) this ^ a -function op_xor(x,y) { return x^y; } -function bnXor(a) { var r = nbi(); this.bitwiseTo(a,op_xor,r); return r; } - -// (public) this & ~a -function op_andnot(x,y) { return x&~y; } -function bnAndNot(a) { var r = nbi(); this.bitwiseTo(a,op_andnot,r); return r; } - -// (public) ~this -function bnNot() { - var r = nbi(); - for(var i = 0; i < this.t; ++i) r[i] = this.DM&~this[i]; - r.t = this.t; - r.s = ~this.s; - return r; -} - -// (public) this << n -function bnShiftLeft(n) { - var r = nbi(); - if(n < 0) this.rShiftTo(-n,r); else this.lShiftTo(n,r); - return r; -} - -// (public) this >> n -function bnShiftRight(n) { - var r = nbi(); - if(n < 0) this.lShiftTo(-n,r); else this.rShiftTo(n,r); - return r; -} - -// return index of lowest 1-bit in x, x < 2^31 -function lbit(x) { - if(x == 0) return -1; - var r = 0; - if((x&0xffff) == 0) { x >>= 16; r += 16; } - if((x&0xff) == 0) { x >>= 8; r += 8; } - if((x&0xf) == 0) { x >>= 4; r += 4; } - if((x&3) == 0) { x >>= 2; r += 2; } - if((x&1) == 0) ++r; - return r; -} - -// (public) returns index of lowest 1-bit (or -1 if none) -function bnGetLowestSetBit() { - for(var i = 0; i < this.t; ++i) - if(this[i] != 0) return i*this.DB+lbit(this[i]); - if(this.s < 0) return this.t*this.DB; - return -1; -} - -// return number of 1 bits in x -function cbit(x) { - var r = 0; - while(x != 0) { x &= x-1; ++r; } - return r; -} - -// (public) return number of set bits -function bnBitCount() { - var r = 0, x = this.s&this.DM; - for(var i = 0; i < this.t; ++i) r += cbit(this[i]^x); - return r; -} - -// (public) true iff nth bit is set -function bnTestBit(n) { - var j = Math.floor(n/this.DB); - if(j >= this.t) return(this.s!=0); - return((this[j]&(1<<(n%this.DB)))!=0); -} - -// (protected) this op (1<>= this.DB; - } - if(a.t < this.t) { - c += a.s; - while(i < this.t) { - c += this[i]; - r[i++] = c&this.DM; - c >>= this.DB; - } - c += this.s; - } - else { - c += this.s; - while(i < a.t) { - c += a[i]; - r[i++] = c&this.DM; - c >>= this.DB; - } - c += a.s; - } - r.s = (c<0)?-1:0; - if(c > 0) r[i++] = c; - else if(c < -1) r[i++] = this.DV+c; - r.t = i; - r.clamp(); -} - -// (public) this + a -function bnAdd(a) { var r = nbi(); this.addTo(a,r); return r; } - -// (public) this - a -function bnSubtract(a) { var r = nbi(); this.subTo(a,r); return r; } - -// (public) this * a -function bnMultiply(a) { var r = nbi(); this.multiplyTo(a,r); return r; } - -// (public) this / a -function bnDivide(a) { var r = nbi(); this.divRemTo(a,r,null); return r; } - -// (public) this % a -function bnRemainder(a) { var r = nbi(); this.divRemTo(a,null,r); return r; } - -// (public) [this/a,this%a] -function bnDivideAndRemainder(a) { - var q = nbi(), r = nbi(); - this.divRemTo(a,q,r); - return new Array(q,r); -} - -// (protected) this *= n, this >= 0, 1 < n < DV -function bnpDMultiply(n) { - this[this.t] = this.am(0,n-1,this,0,0,this.t); - ++this.t; - this.clamp(); -} - -// (protected) this += n << w words, this >= 0 -function bnpDAddOffset(n,w) { - if(n == 0) return; - while(this.t <= w) this[this.t++] = 0; - this[w] += n; - while(this[w] >= this.DV) { - this[w] -= this.DV; - if(++w >= this.t) this[this.t++] = 0; - ++this[w]; - } -} - -// A "null" reducer -function NullExp() {} -function nNop(x) { return x; } -function nMulTo(x,y,r) { x.multiplyTo(y,r); } -function nSqrTo(x,r) { x.squareTo(r); } - -NullExp.prototype.convert = nNop; -NullExp.prototype.revert = nNop; -NullExp.prototype.mulTo = nMulTo; -NullExp.prototype.sqrTo = nSqrTo; - -// (public) this^e -function bnPow(e) { return this.exp(e,new NullExp()); } - -// (protected) r = lower n words of "this * a", a.t <= n -// "this" should be the larger one if appropriate. -function bnpMultiplyLowerTo(a,n,r) { - var i = Math.min(this.t+a.t,n); - r.s = 0; // assumes a,this >= 0 - r.t = i; - while(i > 0) r[--i] = 0; - var j; - for(j = r.t-this.t; i < j; ++i) r[i+this.t] = this.am(0,a[i],r,i,0,this.t); - for(j = Math.min(a.t,n); i < j; ++i) this.am(0,a[i],r,i,0,n-i); - r.clamp(); -} - -// (protected) r = "this * a" without lower n words, n > 0 -// "this" should be the larger one if appropriate. -function bnpMultiplyUpperTo(a,n,r) { - --n; - var i = r.t = this.t+a.t-n; - r.s = 0; // assumes a,this >= 0 - while(--i >= 0) r[i] = 0; - for(i = Math.max(n-this.t,0); i < a.t; ++i) - r[this.t+i-n] = this.am(n-i,a[i],r,0,0,this.t+i-n); - r.clamp(); - r.drShiftTo(1,r); -} - -// Barrett modular reduction -function Barrett(m) { - // setup Barrett - this.r2 = nbi(); - this.q3 = nbi(); - BigInteger.ONE.dlShiftTo(2*m.t,this.r2); - this.mu = this.r2.divide(m); - this.m = m; -} - -function barrettConvert(x) { - if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m); - else if(x.compareTo(this.m) < 0) return x; - else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; } -} - -function barrettRevert(x) { return x; } - -// x = x mod m (HAC 14.42) -function barrettReduce(x) { - x.drShiftTo(this.m.t-1,this.r2); - if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); } - this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3); - this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2); - while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1); - x.subTo(this.r2,x); - while(x.compareTo(this.m) >= 0) x.subTo(this.m,x); -} - -// r = x^2 mod m; x != r -function barrettSqrTo(x,r) { x.squareTo(r); this.reduce(r); } - -// r = x*y mod m; x,y != r -function barrettMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } - -Barrett.prototype.convert = barrettConvert; -Barrett.prototype.revert = barrettRevert; -Barrett.prototype.reduce = barrettReduce; -Barrett.prototype.mulTo = barrettMulTo; -Barrett.prototype.sqrTo = barrettSqrTo; - -// (public) this^e % m (HAC 14.85) -function bnModPow(e,m) { - var i = e.bitLength(), k, r = nbv(1), z; - if(i <= 0) return r; - else if(i < 18) k = 1; - else if(i < 48) k = 3; - else if(i < 144) k = 4; - else if(i < 768) k = 5; - else k = 6; - if(i < 8) - z = new Classic(m); - else if(m.isEven()) - z = new Barrett(m); - else - z = new Montgomery(m); - - // precomputation - var g = new Array(), n = 3, k1 = k-1, km = (1< 1) { - var g2 = nbi(); - z.sqrTo(g[1],g2); - while(n <= km) { - g[n] = nbi(); - z.mulTo(g2,g[n-2],g[n]); - n += 2; - } - } - - var j = e.t-1, w, is1 = true, r2 = nbi(), t; - i = nbits(e[j])-1; - while(j >= 0) { - if(i >= k1) w = (e[j]>>(i-k1))&km; - else { - w = (e[j]&((1<<(i+1))-1))<<(k1-i); - if(j > 0) w |= e[j-1]>>(this.DB+i-k1); - } - - n = k; - while((w&1) == 0) { w >>= 1; --n; } - if((i -= n) < 0) { i += this.DB; --j; } - if(is1) { // ret == 1, don't bother squaring or multiplying it - g[w].copyTo(r); - is1 = false; - } - else { - while(n > 1) { z.sqrTo(r,r2); z.sqrTo(r2,r); n -= 2; } - if(n > 0) z.sqrTo(r,r2); else { t = r; r = r2; r2 = t; } - z.mulTo(r2,g[w],r); - } - - while(j >= 0 && (e[j]&(1< 0) { - x.rShiftTo(g,x); - y.rShiftTo(g,y); - } - while(x.signum() > 0) { - if((i = x.getLowestSetBit()) > 0) x.rShiftTo(i,x); - if((i = y.getLowestSetBit()) > 0) y.rShiftTo(i,y); - if(x.compareTo(y) >= 0) { - x.subTo(y,x); - x.rShiftTo(1,x); - } - else { - y.subTo(x,y); - y.rShiftTo(1,y); - } - } - if(g > 0) y.lShiftTo(g,y); - return y; -} - -// (protected) this % n, n < 2^26 -function bnpModInt(n) { - if(n <= 0) return 0; - var d = this.DV%n, r = (this.s<0)?n-1:0; - if(this.t > 0) - if(d == 0) r = this[0]%n; - else for(var i = this.t-1; i >= 0; --i) r = (d*r+this[i])%n; - return r; -} - -// (public) 1/this % m (HAC 14.61) -function bnModInverse(m) { - var ac = m.isEven(); - if((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO; - var u = m.clone(), v = this.clone(); - var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1); - while(u.signum() != 0) { - while(u.isEven()) { - u.rShiftTo(1,u); - if(ac) { - if(!a.isEven() || !b.isEven()) { a.addTo(this,a); b.subTo(m,b); } - a.rShiftTo(1,a); - } - else if(!b.isEven()) b.subTo(m,b); - b.rShiftTo(1,b); - } - while(v.isEven()) { - v.rShiftTo(1,v); - if(ac) { - if(!c.isEven() || !d.isEven()) { c.addTo(this,c); d.subTo(m,d); } - c.rShiftTo(1,c); - } - else if(!d.isEven()) d.subTo(m,d); - d.rShiftTo(1,d); - } - if(u.compareTo(v) >= 0) { - u.subTo(v,u); - if(ac) a.subTo(c,a); - b.subTo(d,b); - } - else { - v.subTo(u,v); - if(ac) c.subTo(a,c); - d.subTo(b,d); - } - } - if(v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO; - if(d.compareTo(m) >= 0) return d.subtract(m); - if(d.signum() < 0) d.addTo(m,d); else return d; - if(d.signum() < 0) return d.add(m); else return d; -} - -var lowprimes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509]; -var lplim = (1<<26)/lowprimes[lowprimes.length-1]; - -// (public) test primality with certainty >= 1-.5^t -function bnIsProbablePrime(t) { - var i, x = this.abs(); - if(x.t == 1 && x[0] <= lowprimes[lowprimes.length-1]) { - for(i = 0; i < lowprimes.length; ++i) - if(x[0] == lowprimes[i]) return true; - return false; - } - if(x.isEven()) return false; - i = 1; - while(i < lowprimes.length) { - var m = lowprimes[i], j = i+1; - while(j < lowprimes.length && m < lplim) m *= lowprimes[j++]; - m = x.modInt(m); - while(i < j) if(m%lowprimes[i++] == 0) return false; - } - return x.millerRabin(t); -} - -// (protected) true if probably prime (HAC 4.24, Miller-Rabin) -function bnpMillerRabin(t) { - var n1 = this.subtract(BigInteger.ONE); - var k = n1.getLowestSetBit(); - if(k <= 0) return false; - var r = n1.shiftRight(k); - t = (t+1)>>1; - if(t > lowprimes.length) t = lowprimes.length; - var a = nbi(); - for(var i = 0; i < t; ++i) { - a.fromInt(lowprimes[i]); - var y = a.modPow(r,this); - if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { - var j = 1; - while(j++ < k && y.compareTo(n1) != 0) { - y = y.modPowInt(2,this); - if(y.compareTo(BigInteger.ONE) == 0) return false; - } - if(y.compareTo(n1) != 0) return false; - } - } - return true; -} - -// protected -BigInteger.prototype.chunkSize = bnpChunkSize; -BigInteger.prototype.toRadix = bnpToRadix; -BigInteger.prototype.fromRadix = bnpFromRadix; -BigInteger.prototype.fromNumber = bnpFromNumber; -BigInteger.prototype.bitwiseTo = bnpBitwiseTo; -BigInteger.prototype.changeBit = bnpChangeBit; -BigInteger.prototype.addTo = bnpAddTo; -BigInteger.prototype.dMultiply = bnpDMultiply; -BigInteger.prototype.dAddOffset = bnpDAddOffset; -BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo; -BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo; -BigInteger.prototype.modInt = bnpModInt; -BigInteger.prototype.millerRabin = bnpMillerRabin; - -// public -BigInteger.prototype.clone = bnClone; -BigInteger.prototype.intValue = bnIntValue; -BigInteger.prototype.byteValue = bnByteValue; -BigInteger.prototype.shortValue = bnShortValue; -BigInteger.prototype.signum = bnSigNum; -BigInteger.prototype.toByteArray = bnToByteArray; -BigInteger.prototype.equals = bnEquals; -BigInteger.prototype.min = bnMin; -BigInteger.prototype.max = bnMax; -BigInteger.prototype.and = bnAnd; -BigInteger.prototype.or = bnOr; -BigInteger.prototype.xor = bnXor; -BigInteger.prototype.andNot = bnAndNot; -BigInteger.prototype.not = bnNot; -BigInteger.prototype.shiftLeft = bnShiftLeft; -BigInteger.prototype.shiftRight = bnShiftRight; -BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit; -BigInteger.prototype.bitCount = bnBitCount; -BigInteger.prototype.testBit = bnTestBit; -BigInteger.prototype.setBit = bnSetBit; -BigInteger.prototype.clearBit = bnClearBit; -BigInteger.prototype.flipBit = bnFlipBit; -BigInteger.prototype.add = bnAdd; -BigInteger.prototype.subtract = bnSubtract; -BigInteger.prototype.multiply = bnMultiply; -BigInteger.prototype.divide = bnDivide; -BigInteger.prototype.remainder = bnRemainder; -BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder; -BigInteger.prototype.modPow = bnModPow; -BigInteger.prototype.modInverse = bnModInverse; -BigInteger.prototype.pow = bnPow; -BigInteger.prototype.gcd = bnGCD; -BigInteger.prototype.isProbablePrime = bnIsProbablePrime; - -// BigInteger interfaces not implemented in jsbn: - -// BigInteger(int signum, byte[] magnitude) -// double doubleValue() -// float floatValue() -// int hashCode() -// long longValue() -// static BigInteger valueOf(long val) diff --git a/node_modules/ipv6/lib/browser/sprintf.js b/node_modules/ipv6/lib/browser/sprintf.js deleted file mode 100644 index 8f7f8ba..0000000 --- a/node_modules/ipv6/lib/browser/sprintf.js +++ /dev/null @@ -1,183 +0,0 @@ -/** -sprintf() for JavaScript 0.7-beta1 -http://www.diveintojavascript.com/projects/javascript-sprintf - -Copyright (c) Alexandru Marasteanu -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of sprintf() for JavaScript nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL Alexandru Marasteanu BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Changelog: -2010.09.06 - 0.7-beta1 - - features: vsprintf, support for named placeholders - - enhancements: format cache, reduced global namespace pollution - -2010.05.22 - 0.6: - - reverted to 0.4 and fixed the bug regarding the sign of the number 0 - Note: - Thanks to Raphael Pigulla (http://www.n3rd.org/) - who warned me about a bug in 0.5, I discovered that the last update was - a regress. I appologize for that. - -2010.05.09 - 0.5: - - bug fix: 0 is now preceeded with a + sign - - bug fix: the sign was not at the right position on padded results (Kamal Abdali) - - switched from GPL to BSD license - -2007.10.21 - 0.4: - - unit test and patch (David Baird) - -2007.09.17 - 0.3: - - bug fix: no longer throws exception on empty paramenters (Hans Pufal) - -2007.09.11 - 0.2: - - feature: added argument swapping - -2007.04.03 - 0.1: - - initial release -**/ - -var sprintf = this.sprintf = (function() { - function get_type(variable) { - return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); - } - function str_repeat(input, multiplier) { - for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} - return output.join(''); - } - - var str_format = function() { - if (!str_format.cache.hasOwnProperty(arguments[0])) { - str_format.cache[arguments[0]] = str_format.parse(arguments[0]); - } - return str_format.format.call(null, str_format.cache[arguments[0]], arguments); - }; - - str_format.format = function(parse_tree, argv) { - var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; - for (i = 0; i < tree_length; i++) { - node_type = get_type(parse_tree[i]); - if (node_type === 'string') { - output.push(parse_tree[i]); - } - else if (node_type === 'array') { - match = parse_tree[i]; // convenience purposes only - if (match[2]) { // keyword argument - arg = argv[cursor]; - for (k = 0; k < match[2].length; k++) { - if (!arg.hasOwnProperty(match[2][k])) { - throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); - } - arg = arg[match[2][k]]; - } - } - else if (match[1]) { // positional argument (explicit) - arg = argv[match[1]]; - } - else { // positional argument (implicit) - arg = argv[cursor++]; - } - - if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { - throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); - } - switch (match[8]) { - case 'b': arg = arg.toString(2); break; - case 'c': arg = String.fromCharCode(arg); break; - case 'd': arg = parseInt(arg, 10); break; - case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; - case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; - case 'o': arg = arg.toString(8); break; - case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; - case 'u': arg = Math.abs(arg); break; - case 'x': arg = arg.toString(16); break; - case 'X': arg = arg.toString(16).toUpperCase(); break; - } - arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); - pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; - pad_length = match[6] - String(arg).length; - pad = match[6] ? str_repeat(pad_character, pad_length) : ''; - output.push(match[5] ? arg + pad : pad + arg); - } - } - return output.join(''); - }; - - str_format.cache = {}; - - str_format.parse = function(fmt) { - var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; - while (_fmt) { - if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { - parse_tree.push(match[0]); - } - else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { - parse_tree.push('%'); - } - else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { - if (match[2]) { - arg_names |= 1; - var field_list = [], replacement_field = match[2], field_match = []; - if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { - field_list.push(field_match[1]); - while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { - if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { - field_list.push(field_match[1]); - } - else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { - field_list.push(field_match[1]); - } - else { - throw('[sprintf] huh?'); - } - } - } - else { - throw('[sprintf] huh?'); - } - match[2] = field_list; - } - else { - arg_names |= 2; - } - if (arg_names === 3) { - throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); - } - parse_tree.push(match); - } - else { - throw('[sprintf] huh?'); - } - _fmt = _fmt.substring(match[0].length); - } - return parse_tree; - }; - - return str_format; -})(); - -var vsprintf = this.vsprintf = function(fmt, argv) { - argv.unshift(fmt); - return sprintf.apply(null, argv); -}; diff --git a/node_modules/ipv6/lib/node/bigint.js b/node_modules/ipv6/lib/node/bigint.js deleted file mode 100644 index 37d51e9..0000000 --- a/node_modules/ipv6/lib/node/bigint.js +++ /dev/null @@ -1,1255 +0,0 @@ -/** - * copped from https://github.com/joyent/node/blob/master/deps/v8/benchmarks/crypto.js (under same license). - * - * Copyright (c) 2003-2005 Tom Wu - * All Rights Reserved. - * - * 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" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF - * THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT - * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * In addition, the following condition applies: - * - * All redistributions must retain an intact copy of this copyright notice - * and disclaimer. - */ - -// V8 optimized constants. -var dbits = 26 -var BI_DB = dbits; -var BI_DM = ((1<>13; - while(--n >= 0) { - var l = this_array[i]&0x1fff; - var h = this_array[i++]>>13; - var m = xh*l+h*xl; - l = xl*l+((m&0x1fff)<<13)+w_array[j]+c; - c = (l>>26)+(m>>13)+xh*h; - w_array[j++] = l&0x3ffffff; - } - return c; -} - -// Digit conversions -var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz"; -var BI_RC = new Array(); -var rr,vv; -rr = "0".charCodeAt(0); -for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv; -rr = "a".charCodeAt(0); -for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv; -rr = "A".charCodeAt(0); -for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv; - -function int2char(n) { return BI_RM.charAt(n); } -function intAt(s,i) { - var c = BI_RC[s.charCodeAt(i)]; - return (c==null)?-1:c; -} - -// (protected) copy this to r -function bnpCopyTo(r) { - var this_array = this.array; - var r_array = r.array; - - for(var i = this.t-1; i >= 0; --i) r_array[i] = this_array[i]; - r.t = this.t; - r.s = this.s; -} - -// (protected) set from integer value x, -DV <= x < DV -function bnpFromInt(x) { - var this_array = this.array; - this.t = 1; - this.s = (x<0)?-1:0; - if(x > 0) this_array[0] = x; - else if(x < -1) this_array[0] = x+DV; // WTH is DV? BI_DV maybe? - else this.t = 0; -} - -// return bigint initialized to value -function nbv(i) { var r = nbi(); r.fromInt(i); return r; } - -// (protected) set from string and radix -function bnpFromString(s,b) { - var this_array = this.array; - var k; - if(b == 16) k = 4; - else if(b == 8) k = 3; - else if(b == 256) k = 8; // byte array - else if(b == 2) k = 1; - else if(b == 32) k = 5; - else if(b == 4) k = 2; - else { this.fromRadix(s,b); return; } - this.t = 0; - this.s = 0; - var i = s.length, mi = false, sh = 0; - while(--i >= 0) { - var x = (k==8)?s[i]&0xff:intAt(s,i); - if(x < 0) { - if(s.charAt(i) == "-") mi = true; - continue; - } - mi = false; - if(sh == 0) - this_array[this.t++] = x; - else if(sh+k > BI_DB) { - this_array[this.t-1] |= (x&((1<<(BI_DB-sh))-1))<>(BI_DB-sh)); - } - else - this_array[this.t-1] |= x<= BI_DB) sh -= BI_DB; - } - if(k == 8 && (s[0]&0x80) != 0) { - this.s = -1; - if(sh > 0) this_array[this.t-1] |= ((1<<(BI_DB-sh))-1)< 0 && this_array[this.t-1] == c) --this.t; -} - -// (public) return string representation in given radix -function bnToString(b) { - var this_array = this.array; - if(this.s < 0) return "-"+this.negate().toString(b); - var k; - if(b == 16) k = 4; - else if(b == 8) k = 3; - else if(b == 2) k = 1; - else if(b == 32) k = 5; - else if(b == 4) k = 2; - else return this.toRadix(b); - var km = (1< 0) { - if(p < BI_DB && (d = this_array[i]>>p) > 0) { m = true; r = int2char(d); } - while(i >= 0) { - if(p < k) { - d = (this_array[i]&((1<>(p+=BI_DB-k); - } - else { - d = (this_array[i]>>(p-=k))&km; - if(p <= 0) { p += BI_DB; --i; } - } - if(d > 0) m = true; - if(m) r += int2char(d); - } - } - return m?r:"0"; -} - -// (public) -this -function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; } - -// (public) |this| -function bnAbs() { return (this.s<0)?this.negate():this; } - -// (public) return + if this > a, - if this < a, 0 if equal -function bnCompareTo(a) { - var this_array = this.array; - var a_array = a.array; - - var r = this.s-a.s; - if(r != 0) return r; - var i = this.t; - r = i-a.t; - if(r != 0) return r; - while(--i >= 0) if((r=this_array[i]-a_array[i]) != 0) return r; - return 0; -} - -// returns bit length of the integer x -function nbits(x) { - var r = 1, t; - if((t=x>>>16) != 0) { x = t; r += 16; } - if((t=x>>8) != 0) { x = t; r += 8; } - if((t=x>>4) != 0) { x = t; r += 4; } - if((t=x>>2) != 0) { x = t; r += 2; } - if((t=x>>1) != 0) { x = t; r += 1; } - return r; -} - -// (public) return the number of bits in "this" -function bnBitLength() { - var this_array = this.array; - if(this.t <= 0) return 0; - return BI_DB*(this.t-1)+nbits(this_array[this.t-1]^(this.s&BI_DM)); -} - -// (protected) r = this << n*DB -function bnpDLShiftTo(n,r) { - var this_array = this.array; - var r_array = r.array; - var i; - for(i = this.t-1; i >= 0; --i) r_array[i+n] = this_array[i]; - for(i = n-1; i >= 0; --i) r_array[i] = 0; - r.t = this.t+n; - r.s = this.s; -} - -// (protected) r = this >> n*DB -function bnpDRShiftTo(n,r) { - var this_array = this.array; - var r_array = r.array; - for(var i = n; i < this.t; ++i) r_array[i-n] = this_array[i]; - r.t = Math.max(this.t-n,0); - r.s = this.s; -} - -// (protected) r = this << n -function bnpLShiftTo(n,r) { - var this_array = this.array; - var r_array = r.array; - var bs = n%BI_DB; - var cbs = BI_DB-bs; - var bm = (1<= 0; --i) { - r_array[i+ds+1] = (this_array[i]>>cbs)|c; - c = (this_array[i]&bm)<= 0; --i) r_array[i] = 0; - r_array[ds] = c; - r.t = this.t+ds+1; - r.s = this.s; - r.clamp(); -} - -// (protected) r = this >> n -function bnpRShiftTo(n,r) { - var this_array = this.array; - var r_array = r.array; - r.s = this.s; - var ds = Math.floor(n/BI_DB); - if(ds >= this.t) { r.t = 0; return; } - var bs = n%BI_DB; - var cbs = BI_DB-bs; - var bm = (1<>bs; - for(var i = ds+1; i < this.t; ++i) { - r_array[i-ds-1] |= (this_array[i]&bm)<>bs; - } - if(bs > 0) r_array[this.t-ds-1] |= (this.s&bm)<>= BI_DB; - } - if(a.t < this.t) { - c -= a.s; - while(i < this.t) { - c += this_array[i]; - r_array[i++] = c&BI_DM; - c >>= BI_DB; - } - c += this.s; - } - else { - c += this.s; - while(i < a.t) { - c -= a_array[i]; - r_array[i++] = c&BI_DM; - c >>= BI_DB; - } - c -= a.s; - } - r.s = (c<0)?-1:0; - if(c < -1) r_array[i++] = BI_DV+c; - else if(c > 0) r_array[i++] = c; - r.t = i; - r.clamp(); -} - -// (protected) r = this * a, r != this,a (HAC 14.12) -// "this" should be the larger one if appropriate. -function bnpMultiplyTo(a,r) { - var this_array = this.array; // Unused local var? - var r_array = r.array; - var x = this.abs(), y = a.abs(); - var y_array = y.array; - - var i = x.t; - r.t = i+y.t; - while(--i >= 0) r_array[i] = 0; - for(i = 0; i < y.t; ++i) r_array[i+x.t] = x.am(0,y_array[i],r,i,0,x.t); - r.s = 0; - r.clamp(); - if(this.s != a.s) BigInteger.ZERO.subTo(r,r); -} - -// (protected) r = this^2, r != this (HAC 14.16) -function bnpSquareTo(r) { - var x = this.abs(); - var x_array = x.array; - var r_array = r.array; - - var i = r.t = 2*x.t; - while(--i >= 0) r_array[i] = 0; - for(i = 0; i < x.t-1; ++i) { - var c = x.am(i,x_array[i],r,2*i,0,1); - if((r_array[i+x.t]+=x.am(i+1,2*x_array[i],r,2*i+1,c,x.t-i-1)) >= BI_DV) { - r_array[i+x.t] -= BI_DV; - r_array[i+x.t+1] = 1; - } - } - if(r.t > 0) r_array[r.t-1] += x.am(i,x_array[i],r,2*i,0,1); - r.s = 0; - r.clamp(); -} - -// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20) -// r != q, this != m. q or r may be null. -function bnpDivRemTo(m,q,r) { - var pm = m.abs(); - if(pm.t <= 0) return; - var pt = this.abs(); - if(pt.t < pm.t) { - if(q != null) q.fromInt(0); - if(r != null) this.copyTo(r); - return; - } - if(r == null) r = nbi(); - var y = nbi(), ts = this.s, ms = m.s; - var pm_array = pm.array; - var nsh = BI_DB-nbits(pm_array[pm.t-1]); // normalize modulus - if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); } - else { pm.copyTo(y); pt.copyTo(r); } - var ys = y.t; - - var y_array = y.array; - var y0 = y_array[ys-1]; - if(y0 == 0) return; - var yt = y0*(1<1)?y_array[ys-2]>>BI_F2:0); - var d1 = BI_FV/yt, d2 = (1<= 0) { - r_array[r.t++] = 1; - r.subTo(t,r); - } - BigInteger.ONE.dlShiftTo(ys,t); - t.subTo(y,y); // "negative" y so we can replace sub with am later - while(y.t < ys) y_array[y.t++] = 0; - while(--j >= 0) { - // Estimate quotient digit - var qd = (r_array[--i]==y0)?BI_DM:Math.floor(r_array[i]*d1+(r_array[i-1]+e)*d2); - if((r_array[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out - y.dlShiftTo(j,t); - r.subTo(t,r); - while(r_array[i] < --qd) r.subTo(t,r); - } - } - if(q != null) { - r.drShiftTo(ys,q); - if(ts != ms) BigInteger.ZERO.subTo(q,q); - } - r.t = ys; - r.clamp(); - if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder - if(ts < 0) BigInteger.ZERO.subTo(r,r); -} - -// (public) this mod a -function bnMod(a) { - var r = nbi(); - this.abs().divRemTo(a,null,r); - if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r); - return r; -} - -// Modular reduction using "classic" algorithm -function Classic(m) { this.m = m; } -function cConvert(x) { - if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m); - else return x; -} -function cRevert(x) { return x; } -function cReduce(x) { x.divRemTo(this.m,null,x); } -function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } -function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); } - -Classic.prototype.convert = cConvert; -Classic.prototype.revert = cRevert; -Classic.prototype.reduce = cReduce; -Classic.prototype.mulTo = cMulTo; -Classic.prototype.sqrTo = cSqrTo; - -// (protected) return "-1/this % 2^DB"; useful for Mont. reduction -// justification: -// xy == 1 (mod m) -// xy = 1+km -// xy(2-xy) = (1+km)(1-km) -// x[y(2-xy)] = 1-k^2m^2 -// x[y(2-xy)] == 1 (mod m^2) -// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2 -// should reduce x and y(2-xy) by m^2 at each step to keep size bounded. -// JS multiply "overflows" differently from C/C++, so care is needed here. -function bnpInvDigit() { - var this_array = this.array; - if(this.t < 1) return 0; - var x = this_array[0]; - if((x&1) == 0) return 0; - var y = x&3; // y == 1/x mod 2^2 - y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4 - y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8 - y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16 - // last step - calculate inverse mod DV directly; - // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints - y = (y*(2-x*y%BI_DV))%BI_DV; // y == 1/x mod 2^dbits - // we really want the negative inverse, and -DV < y < DV - return (y>0)?BI_DV-y:-y; -} - -// Montgomery reduction -function Montgomery(m) { - this.m = m; - this.mp = m.invDigit(); - this.mpl = this.mp&0x7fff; - this.mph = this.mp>>15; - this.um = (1<<(BI_DB-15))-1; - this.mt2 = 2*m.t; -} - -// xR mod m -function montConvert(x) { - var r = nbi(); - x.abs().dlShiftTo(this.m.t,r); - r.divRemTo(this.m,null,r); - if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r); - return r; -} - -// x/R mod m -function montRevert(x) { - var r = nbi(); - x.copyTo(r); - this.reduce(r); - return r; -} - -// x = x/R mod m (HAC 14.32) -function montReduce(x) { - var x_array = x.array; - while(x.t <= this.mt2) // pad x so am has enough room later - x_array[x.t++] = 0; - for(var i = 0; i < this.m.t; ++i) { - // faster way of calculating u0 = x[i]*mp mod DV - var j = x_array[i]&0x7fff; - var u0 = (j*this.mpl+(((j*this.mph+(x_array[i]>>15)*this.mpl)&this.um)<<15))&BI_DM; - // use am to combine the multiply-shift-add into one call - j = i+this.m.t; - x_array[j] += this.m.am(0,u0,x,i,0,this.m.t); - // propagate carry - while(x_array[j] >= BI_DV) { x_array[j] -= BI_DV; x_array[++j]++; } - } - x.clamp(); - x.drShiftTo(this.m.t,x); - if(x.compareTo(this.m) >= 0) x.subTo(this.m,x); -} - -// r = "x^2/R mod m"; x != r -function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); } - -// r = "xy/R mod m"; x,y != r -function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } - -Montgomery.prototype.convert = montConvert; -Montgomery.prototype.revert = montRevert; -Montgomery.prototype.reduce = montReduce; -Montgomery.prototype.mulTo = montMulTo; -Montgomery.prototype.sqrTo = montSqrTo; - -// (protected) true iff this is even -function bnpIsEven() { - var this_array = this.array; - return ((this.t>0)?(this_array[0]&1):this.s) == 0; -} - -// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79) -function bnpExp(e,z) { - if(e > 0xffffffff || e < 1) return BigInteger.ONE; - var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1; - g.copyTo(r); - while(--i >= 0) { - z.sqrTo(r,r2); - if((e&(1< 0) z.mulTo(r2,g,r); - else { var t = r; r = r2; r2 = t; } - } - return z.revert(r); -} - -// (public) this^e % m, 0 <= e < 2^32 -function bnModPowInt(e,m) { - var z; - if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m); - return this.exp(e,z); -} - -// protected -BigInteger.prototype.copyTo = bnpCopyTo; -BigInteger.prototype.fromInt = bnpFromInt; -BigInteger.prototype.fromString = bnpFromString; -BigInteger.prototype.clamp = bnpClamp; -BigInteger.prototype.dlShiftTo = bnpDLShiftTo; -BigInteger.prototype.drShiftTo = bnpDRShiftTo; -BigInteger.prototype.lShiftTo = bnpLShiftTo; -BigInteger.prototype.rShiftTo = bnpRShiftTo; -BigInteger.prototype.subTo = bnpSubTo; -BigInteger.prototype.multiplyTo = bnpMultiplyTo; -BigInteger.prototype.squareTo = bnpSquareTo; -BigInteger.prototype.divRemTo = bnpDivRemTo; -BigInteger.prototype.invDigit = bnpInvDigit; -BigInteger.prototype.isEven = bnpIsEven; -BigInteger.prototype.exp = bnpExp; - -// public -BigInteger.prototype.toString = bnToString; -BigInteger.prototype.negate = bnNegate; -BigInteger.prototype.abs = bnAbs; -BigInteger.prototype.compareTo = bnCompareTo; -BigInteger.prototype.bitLength = bnBitLength; -BigInteger.prototype.mod = bnMod; -BigInteger.prototype.modPowInt = bnModPowInt; - -// "constants" -BigInteger.ZERO = nbv(0); -BigInteger.ONE = nbv(1); -// Copyright (c) 2005 Tom Wu -// All Rights Reserved. -// See "LICENSE" for details. - -// Extended JavaScript BN functions, required for RSA private ops. - -// (public) -function bnClone() { var r = nbi(); this.copyTo(r); return r; } - -// (public) return value as integer -function bnIntValue() { - var this_array = this.array; - if(this.s < 0) { - if(this.t == 1) return this_array[0]-BI_DV; - else if(this.t == 0) return -1; - } - else if(this.t == 1) return this_array[0]; - else if(this.t == 0) return 0; - // assumes 16 < DB < 32 - return ((this_array[1]&((1<<(32-BI_DB))-1))<>24; -} - -// (public) return value as short (assumes DB>=16) -function bnShortValue() { - var this_array = this.array; - return (this.t==0)?this.s:(this_array[0]<<16)>>16; -} - -// (protected) return x s.t. r^x < DV -function bnpChunkSize(r) { return Math.floor(Math.LN2*BI_DB/Math.log(r)); } - -// (public) 0 if this == 0, 1 if this > 0 -function bnSigNum() { - var this_array = this.array; - if(this.s < 0) return -1; - else if(this.t <= 0 || (this.t == 1 && this_array[0] <= 0)) return 0; - else return 1; -} - -// (protected) convert to radix string -function bnpToRadix(b) { - if(b == null) b = 10; - if(this.signum() == 0 || b < 2 || b > 36) return "0"; - var cs = this.chunkSize(b); - var a = Math.pow(b,cs); - var d = nbv(a), y = nbi(), z = nbi(), r = ""; - this.divRemTo(d,y,z); - while(y.signum() > 0) { - r = (a+z.intValue()).toString(b).substr(1) + r; - y.divRemTo(d,y,z); - } - return z.intValue().toString(b) + r; -} - -// (protected) convert from radix string -function bnpFromRadix(s,b) { - this.fromInt(0); - if(b == null) b = 10; - var cs = this.chunkSize(b); - var d = Math.pow(b,cs), mi = false, j = 0, w = 0; - for(var i = 0; i < s.length; ++i) { - var x = intAt(s,i); - if(x < 0) { - if(s.charAt(i) == "-" && this.signum() == 0) mi = true; - continue; - } - w = b*w+x; - if(++j >= cs) { - this.dMultiply(d); - this.dAddOffset(w,0); - j = 0; - w = 0; - } - } - if(j > 0) { - this.dMultiply(Math.pow(b,j)); - this.dAddOffset(w,0); - } - if(mi) BigInteger.ZERO.subTo(this,this); -} - -// (protected) alternate constructor -function bnpFromNumber(a,b,c) { - if("number" == typeof b) { - // new BigInteger(int,int,RNG) - if(a < 2) this.fromInt(1); - else { - this.fromNumber(a,c); - if(!this.testBit(a-1)) // force MSB set - this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this); - if(this.isEven()) this.dAddOffset(1,0); // force odd - while(!this.isProbablePrime(b)) { - this.dAddOffset(2,0); - if(this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a-1),this); - } - } - } - else { - // todo: we don't need this. - // new BigInteger(int,RNG) - var x = new Array(), t = a&7; - x.length = (a>>3)+1; - b.nextBytes(x); - if(t > 0) x[0] &= ((1< 0) { - if(p < BI_DB && (d = this_array[i]>>p) != (this.s&BI_DM)>>p) - r[k++] = d|(this.s<<(BI_DB-p)); - while(i >= 0) { - if(p < 8) { - d = (this_array[i]&((1<>(p+=BI_DB-8); - } - else { - d = (this_array[i]>>(p-=8))&0xff; - if(p <= 0) { p += BI_DB; --i; } - } - if((d&0x80) != 0) d |= -256; - if(k == 0 && (this.s&0x80) != (d&0x80)) ++k; - if(k > 0 || d != this.s) r[k++] = d; - } - } - return r; -} - -function bnEquals(a) { return(this.compareTo(a)==0); } -function bnMin(a) { return(this.compareTo(a)<0)?this:a; } -function bnMax(a) { return(this.compareTo(a)>0)?this:a; } - -// (protected) r = this op a (bitwise) -function bnpBitwiseTo(a,op,r) { - var this_array = this.array; - var a_array = a.array; - var r_array = r.array; - var i, f, m = Math.min(a.t,this.t); - for(i = 0; i < m; ++i) r_array[i] = op(this_array[i],a_array[i]); - if(a.t < this.t) { - f = a.s&BI_DM; - for(i = m; i < this.t; ++i) r_array[i] = op(this_array[i],f); - r.t = this.t; - } - else { - f = this.s&BI_DM; - for(i = m; i < a.t; ++i) r_array[i] = op(f,a_array[i]); - r.t = a.t; - } - r.s = op(this.s,a.s); - r.clamp(); -} - -// (public) this & a -function op_and(x,y) { return x&y; } -function bnAnd(a) { var r = nbi(); this.bitwiseTo(a,op_and,r); return r; } - -// (public) this | a -function op_or(x,y) { return x|y; } -function bnOr(a) { var r = nbi(); this.bitwiseTo(a,op_or,r); return r; } - -// (public) this ^ a -function op_xor(x,y) { return x^y; } -function bnXor(a) { var r = nbi(); this.bitwiseTo(a,op_xor,r); return r; } - -// (public) this & ~a -function op_andnot(x,y) { return x&~y; } -function bnAndNot(a) { var r = nbi(); this.bitwiseTo(a,op_andnot,r); return r; } - -// (public) ~this -function bnNot() { - var this_array = this.array; - var r = nbi(); - var r_array = r.array; - - for(var i = 0; i < this.t; ++i) r_array[i] = BI_DM&~this_array[i]; - r.t = this.t; - r.s = ~this.s; - return r; -} - -// (public) this << n -function bnShiftLeft(n) { - var r = nbi(); - if(n < 0) this.rShiftTo(-n,r); else this.lShiftTo(n,r); - return r; -} - -// (public) this >> n -function bnShiftRight(n) { - var r = nbi(); - if(n < 0) this.lShiftTo(-n,r); else this.rShiftTo(n,r); - return r; -} - -// return index of lowest 1-bit in x, x < 2^31 -function lbit(x) { - if(x == 0) return -1; - var r = 0; - if((x&0xffff) == 0) { x >>= 16; r += 16; } - if((x&0xff) == 0) { x >>= 8; r += 8; } - if((x&0xf) == 0) { x >>= 4; r += 4; } - if((x&3) == 0) { x >>= 2; r += 2; } - if((x&1) == 0) ++r; - return r; -} - -// (public) returns index of lowest 1-bit (or -1 if none) -function bnGetLowestSetBit() { - var this_array = this.array; - for(var i = 0; i < this.t; ++i) - if(this_array[i] != 0) return i*BI_DB+lbit(this_array[i]); - if(this.s < 0) return this.t*BI_DB; - return -1; -} - -// return number of 1 bits in x -function cbit(x) { - var r = 0; - while(x != 0) { x &= x-1; ++r; } - return r; -} - -// (public) return number of set bits -function bnBitCount() { - var this_array = this.array; - var r = 0, x = this.s&BI_DM; - for(var i = 0; i < this.t; ++i) r += cbit(this_array[i]^x); - return r; -} - -// (public) true iff nth bit is set -function bnTestBit(n) { - var this_array = this.array; - var j = Math.floor(n/BI_DB); - if(j >= this.t) return(this.s!=0); - return((this_array[j]&(1<<(n%BI_DB)))!=0); -} - -// (protected) this op (1<>= BI_DB; - } - if(a.t < this.t) { - c += a.s; - while(i < this.t) { - c += this_array[i]; - r_array[i++] = c&BI_DM; - c >>= BI_DB; - } - c += this.s; - } - else { - c += this.s; - while(i < a.t) { - c += a_array[i]; - r_array[i++] = c&BI_DM; - c >>= BI_DB; - } - c += a.s; - } - r.s = (c<0)?-1:0; - if(c > 0) r_array[i++] = c; - else if(c < -1) r_array[i++] = BI_DV+c; - r.t = i; - r.clamp(); -} - -// (public) this + a -function bnAdd(a) { var r = nbi(); this.addTo(a,r); return r; } - -// (public) this - a -function bnSubtract(a) { var r = nbi(); this.subTo(a,r); return r; } - -// (public) this * a -function bnMultiply(a) { var r = nbi(); this.multiplyTo(a,r); return r; } - -// (public) this / a -function bnDivide(a) { var r = nbi(); this.divRemTo(a,r,null); return r; } - -// (public) this % a -function bnRemainder(a) { var r = nbi(); this.divRemTo(a,null,r); return r; } - -// (public) [this/a,this%a] -function bnDivideAndRemainder(a) { - var q = nbi(), r = nbi(); - this.divRemTo(a,q,r); - return new Array(q,r); -} - -// (protected) this *= n, this >= 0, 1 < n < DV -function bnpDMultiply(n) { - var this_array = this.array; - this_array[this.t] = this.am(0,n-1,this,0,0,this.t); - ++this.t; - this.clamp(); -} - -// (protected) this += n << w words, this >= 0 -function bnpDAddOffset(n,w) { - var this_array = this.array; - while(this.t <= w) this_array[this.t++] = 0; - this_array[w] += n; - while(this_array[w] >= BI_DV) { - this_array[w] -= BI_DV; - if(++w >= this.t) this_array[this.t++] = 0; - ++this_array[w]; - } -} - -// A "null" reducer -function NullExp() {} -function nNop(x) { return x; } -function nMulTo(x,y,r) { x.multiplyTo(y,r); } -function nSqrTo(x,r) { x.squareTo(r); } - -NullExp.prototype.convert = nNop; -NullExp.prototype.revert = nNop; -NullExp.prototype.mulTo = nMulTo; -NullExp.prototype.sqrTo = nSqrTo; - -// (public) this^e -function bnPow(e) { return this.exp(e,new NullExp()); } - -// (protected) r = lower n words of "this * a", a.t <= n -// "this" should be the larger one if appropriate. -function bnpMultiplyLowerTo(a,n,r) { - var r_array = r.array; - var a_array = a.array; - var i = Math.min(this.t+a.t,n); - r.s = 0; // assumes a,this >= 0 - r.t = i; - while(i > 0) r_array[--i] = 0; - var j; - for(j = r.t-this.t; i < j; ++i) r_array[i+this.t] = this.am(0,a_array[i],r,i,0,this.t); - for(j = Math.min(a.t,n); i < j; ++i) this.am(0,a_array[i],r,i,0,n-i); - r.clamp(); -} - -// (protected) r = "this * a" without lower n words, n > 0 -// "this" should be the larger one if appropriate. -function bnpMultiplyUpperTo(a,n,r) { - var r_array = r.array; - var a_array = a.array; - --n; - var i = r.t = this.t+a.t-n; - r.s = 0; // assumes a,this >= 0 - while(--i >= 0) r_array[i] = 0; - for(i = Math.max(n-this.t,0); i < a.t; ++i) - r_array[this.t+i-n] = this.am(n-i,a_array[i],r,0,0,this.t+i-n); - r.clamp(); - r.drShiftTo(1,r); -} - -// Barrett modular reduction -function Barrett(m) { - // setup Barrett - this.r2 = nbi(); - this.q3 = nbi(); - BigInteger.ONE.dlShiftTo(2*m.t,this.r2); - this.mu = this.r2.divide(m); - this.m = m; -} - -function barrettConvert(x) { - if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m); - else if(x.compareTo(this.m) < 0) return x; - else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; } -} - -function barrettRevert(x) { return x; } - -// x = x mod m (HAC 14.42) -function barrettReduce(x) { - x.drShiftTo(this.m.t-1,this.r2); - if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); } - this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3); - this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2); - while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1); - x.subTo(this.r2,x); - while(x.compareTo(this.m) >= 0) x.subTo(this.m,x); -} - -// r = x^2 mod m; x != r -function barrettSqrTo(x,r) { x.squareTo(r); this.reduce(r); } - -// r = x*y mod m; x,y != r -function barrettMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } - -Barrett.prototype.convert = barrettConvert; -Barrett.prototype.revert = barrettRevert; -Barrett.prototype.reduce = barrettReduce; -Barrett.prototype.mulTo = barrettMulTo; -Barrett.prototype.sqrTo = barrettSqrTo; - -// (public) this^e % m (HAC 14.85) -function bnModPow(e,m) { - var e_array = e.array; - var i = e.bitLength(), k, r = nbv(1), z; - if(i <= 0) return r; - else if(i < 18) k = 1; - else if(i < 48) k = 3; - else if(i < 144) k = 4; - else if(i < 768) k = 5; - else k = 6; - if(i < 8) - z = new Classic(m); - else if(m.isEven()) - z = new Barrett(m); - else - z = new Montgomery(m); - - // precomputation - var g = new Array(), n = 3, k1 = k-1, km = (1< 1) { - var g2 = nbi(); - z.sqrTo(g[1],g2); - while(n <= km) { - g[n] = nbi(); - z.mulTo(g2,g[n-2],g[n]); - n += 2; - } - } - - var j = e.t-1, w, is1 = true, r2 = nbi(), t; - i = nbits(e_array[j])-1; - while(j >= 0) { - if(i >= k1) w = (e_array[j]>>(i-k1))&km; - else { - w = (e_array[j]&((1<<(i+1))-1))<<(k1-i); - if(j > 0) w |= e_array[j-1]>>(BI_DB+i-k1); - } - - n = k; - while((w&1) == 0) { w >>= 1; --n; } - if((i -= n) < 0) { i += BI_DB; --j; } - if(is1) { // ret == 1, don't bother squaring or multiplying it - g[w].copyTo(r); - is1 = false; - } - else { - while(n > 1) { z.sqrTo(r,r2); z.sqrTo(r2,r); n -= 2; } - if(n > 0) z.sqrTo(r,r2); else { t = r; r = r2; r2 = t; } - z.mulTo(r2,g[w],r); - } - - while(j >= 0 && (e_array[j]&(1< 0) { - x.rShiftTo(g,x); - y.rShiftTo(g,y); - } - while(x.signum() > 0) { - if((i = x.getLowestSetBit()) > 0) x.rShiftTo(i,x); - if((i = y.getLowestSetBit()) > 0) y.rShiftTo(i,y); - if(x.compareTo(y) >= 0) { - x.subTo(y,x); - x.rShiftTo(1,x); - } - else { - y.subTo(x,y); - y.rShiftTo(1,y); - } - } - if(g > 0) y.lShiftTo(g,y); - return y; -} - -// (protected) this % n, n < 2^26 -function bnpModInt(n) { - var this_array = this.array; - if(n <= 0) return 0; - var d = BI_DV%n, r = (this.s<0)?n-1:0; - if(this.t > 0) - if(d == 0) r = this_array[0]%n; - else for(var i = this.t-1; i >= 0; --i) r = (d*r+this_array[i])%n; - return r; -} - -// (public) 1/this % m (HAC 14.61) -function bnModInverse(m) { - var ac = m.isEven(); - if((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO; - var u = m.clone(), v = this.clone(); - var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1); - while(u.signum() != 0) { - while(u.isEven()) { - u.rShiftTo(1,u); - if(ac) { - if(!a.isEven() || !b.isEven()) { a.addTo(this,a); b.subTo(m,b); } - a.rShiftTo(1,a); - } - else if(!b.isEven()) b.subTo(m,b); - b.rShiftTo(1,b); - } - while(v.isEven()) { - v.rShiftTo(1,v); - if(ac) { - if(!c.isEven() || !d.isEven()) { c.addTo(this,c); d.subTo(m,d); } - c.rShiftTo(1,c); - } - else if(!d.isEven()) d.subTo(m,d); - d.rShiftTo(1,d); - } - if(u.compareTo(v) >= 0) { - u.subTo(v,u); - if(ac) a.subTo(c,a); - b.subTo(d,b); - } - else { - v.subTo(u,v); - if(ac) c.subTo(a,c); - d.subTo(b,d); - } - } - if(v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO; - if(d.compareTo(m) >= 0) return d.subtract(m); - if(d.signum() < 0) d.addTo(m,d); else return d; - if(d.signum() < 0) return d.add(m); else return d; -} - -var lowprimes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509]; -var lplim = (1<<26)/lowprimes[lowprimes.length-1]; - -// (public) test primality with certainty >= 1-.5^t -function bnIsProbablePrime(t) { - var i, x = this.abs(); - var x_array = x.array; - if(x.t == 1 && x_array[0] <= lowprimes[lowprimes.length-1]) { - for(i = 0; i < lowprimes.length; ++i) - if(x_array[0] == lowprimes[i]) return true; - return false; - } - if(x.isEven()) return false; - i = 1; - while(i < lowprimes.length) { - var m = lowprimes[i], j = i+1; - while(j < lowprimes.length && m < lplim) m *= lowprimes[j++]; - m = x.modInt(m); - while(i < j) if(m%lowprimes[i++] == 0) return false; - } - return x.millerRabin(t); -} - -// (protected) true if probably prime (HAC 4.24, Miller-Rabin) -function bnpMillerRabin(t) { - var n1 = this.subtract(BigInteger.ONE); - var k = n1.getLowestSetBit(); - if(k <= 0) return false; - var r = n1.shiftRight(k); - t = (t+1)>>1; - if(t > lowprimes.length) t = lowprimes.length; - var a = nbi(); - for(var i = 0; i < t; ++i) { - a.fromInt(lowprimes[i]); - var y = a.modPow(r,this); - if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { - var j = 1; - while(j++ < k && y.compareTo(n1) != 0) { - y = y.modPowInt(2,this); - if(y.compareTo(BigInteger.ONE) == 0) return false; - } - if(y.compareTo(n1) != 0) return false; - } - } - return true; -}; - -// protected -BigInteger.prototype.chunkSize = bnpChunkSize; -BigInteger.prototype.toRadix = bnpToRadix; -BigInteger.prototype.fromRadix = bnpFromRadix; -BigInteger.prototype.fromNumber = bnpFromNumber; -BigInteger.prototype.bitwiseTo = bnpBitwiseTo; -BigInteger.prototype.changeBit = bnpChangeBit; -BigInteger.prototype.addTo = bnpAddTo; -BigInteger.prototype.dMultiply = bnpDMultiply; -BigInteger.prototype.dAddOffset = bnpDAddOffset; -BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo; -BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo; -BigInteger.prototype.modInt = bnpModInt; -BigInteger.prototype.millerRabin = bnpMillerRabin; - -// public -BigInteger.prototype.clone = bnClone; -BigInteger.prototype.intValue = bnIntValue; -BigInteger.prototype.byteValue = bnByteValue; -BigInteger.prototype.shortValue = bnShortValue; -BigInteger.prototype.signum = bnSigNum; -BigInteger.prototype.toByteArray = bnToByteArray; -BigInteger.prototype.equals = bnEquals; -BigInteger.prototype.min = bnMin; -BigInteger.prototype.max = bnMax; -BigInteger.prototype.and = bnAnd; -BigInteger.prototype.or = bnOr; -BigInteger.prototype.xor = bnXor; -BigInteger.prototype.andNot = bnAndNot; -BigInteger.prototype.not = bnNot; -BigInteger.prototype.shiftLeft = bnShiftLeft; -BigInteger.prototype.shiftRight = bnShiftRight; -BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit; -BigInteger.prototype.bitCount = bnBitCount; -BigInteger.prototype.testBit = bnTestBit; -BigInteger.prototype.setBit = bnSetBit; -BigInteger.prototype.clearBit = bnClearBit; -BigInteger.prototype.flipBit = bnFlipBit; -BigInteger.prototype.add = bnAdd; -BigInteger.prototype.subtract = bnSubtract; -BigInteger.prototype.multiply = bnMultiply; -BigInteger.prototype.divide = bnDivide; -BigInteger.prototype.remainder = bnRemainder; -BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder; -BigInteger.prototype.modPow = bnModPow; -BigInteger.prototype.modInverse = bnModInverse; -BigInteger.prototype.pow = bnPow; -BigInteger.prototype.gcd = bnGCD; -BigInteger.prototype.isProbablePrime = bnIsProbablePrime; -BigInteger.prototype.am = am4; - -// end of stuff copied from github. \ No newline at end of file diff --git a/node_modules/ipv6/node_modules/sprintf/.npmignore b/node_modules/ipv6/node_modules/sprintf/.npmignore deleted file mode 100644 index b512c09..0000000 --- a/node_modules/ipv6/node_modules/sprintf/.npmignore +++ /dev/null @@ -1 +0,0 @@ -node_modules \ No newline at end of file diff --git a/node_modules/ipv6/node_modules/sprintf/README.md b/node_modules/ipv6/node_modules/sprintf/README.md deleted file mode 100644 index 6db7114..0000000 --- a/node_modules/ipv6/node_modules/sprintf/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# sprintf() for node - -## Disclaimer - -This was originally just an adoption of a browser library to node.js. -Since that library is now itself a node.js module, you should check that out: [alexei/sprintf.js](https://github.com/alexei/sprintf.js) - -There is also a [built-in util.format](http://nodejs.org/api/util.html#util_util_format_format). - - -## Install - - npm install sprintf - - -## How to - -Works exactly like http://www.diveintojavascript.com/projects/javascript-sprintf, except that it exports those two functions: - - sprintf = require('sprintf').sprintf; - vsprintf = require('sprintf').vsprintf; - -Have fun! diff --git a/node_modules/ipv6/node_modules/sprintf/lib/sprintf.js b/node_modules/ipv6/node_modules/sprintf/lib/sprintf.js deleted file mode 100644 index 9d1fd09..0000000 --- a/node_modules/ipv6/node_modules/sprintf/lib/sprintf.js +++ /dev/null @@ -1,251 +0,0 @@ -/** -sprintf() for JavaScript 0.7-beta1 -http://www.diveintojavascript.com/projects/javascript-sprintf - -Copyright (c) Alexandru Marasteanu -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of sprintf() for JavaScript nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL Alexandru Marasteanu BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -Changelog: -2010.11.07 - 0.7-beta1-node - - converted it to a node.js compatible module - -2010.09.06 - 0.7-beta1 - - features: vsprintf, support for named placeholders - - enhancements: format cache, reduced global namespace pollution - -2010.05.22 - 0.6: - - reverted to 0.4 and fixed the bug regarding the sign of the number 0 - Note: - Thanks to Raphael Pigulla (http://www.n3rd.org/) - who warned me about a bug in 0.5, I discovered that the last update was - a regress. I appologize for that. - -2010.05.09 - 0.5: - - bug fix: 0 is now preceeded with a + sign - - bug fix: the sign was not at the right position on padded results (Kamal Abdali) - - switched from GPL to BSD license - -2007.10.21 - 0.4: - - unit test and patch (David Baird) - -2007.09.17 - 0.3: - - bug fix: no longer throws exception on empty paramenters (Hans Pufal) - -2007.09.11 - 0.2: - - feature: added argument swapping - -2007.04.03 - 0.1: - - initial release -**/ - -var util = require('util'); - -var sprintf = (function() { - function get_type(variable) { - return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); - } - function str_repeat(input, multiplier) { - for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} - return output.join(''); - } - - var str_format = function() { - if (!str_format.cache.hasOwnProperty(arguments[0])) { - str_format.cache[arguments[0]] = str_format.parse(arguments[0]); - } - return str_format.format.call(null, str_format.cache[arguments[0]], arguments); - }; - - // convert object to simple one line string without indentation or - // newlines. Note that this implementation does not print array - // values to their actual place for sparse arrays. - // - // For example sparse array like this - // l = [] - // l[4] = 1 - // Would be printed as "[1]" instead of "[, , , , 1]" - // - // If argument 'seen' is not null and array the function will check for - // circular object references from argument. - str_format.object_stringify = function(obj, depth, maxdepth, seen) { - var str = ''; - if (obj != null) { - switch( typeof(obj) ) { - case 'function': - return '[Function' + (obj.name ? ': '+obj.name : '') + ']'; - break; - case 'object': - if ( obj instanceof Error) { return '[' + obj.toString() + ']' }; - if (depth >= maxdepth) return '[Object]' - if (seen) { - // add object to seen list - seen = seen.slice(0) - seen.push(obj); - } - if (obj.length != null) { //array - str += '['; - var arr = [] - for (var i in obj) { - if (seen && seen.indexOf(obj[i]) >= 0) arr.push('[Circular]'); - else arr.push(str_format.object_stringify(obj[i], depth+1, maxdepth, seen)); - } - str += arr.join(', ') + ']'; - } else if ('getMonth' in obj) { // date - return 'Date(' + obj + ')'; - } else { // object - str += '{'; - var arr = [] - for (var k in obj) { - if(obj.hasOwnProperty(k)) { - if (seen && seen.indexOf(obj[k]) >= 0) arr.push(k + ': [Circular]'); - else arr.push(k +': ' +str_format.object_stringify(obj[k], depth+1, maxdepth, seen)); - } - } - str += arr.join(', ') + '}'; - } - return str; - break; - case 'string': - return '"' + obj + '"'; - break - } - } - return '' + obj; - } - - str_format.format = function(parse_tree, argv) { - var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; - for (i = 0; i < tree_length; i++) { - node_type = get_type(parse_tree[i]); - if (node_type === 'string') { - output.push(parse_tree[i]); - } - else if (node_type === 'array') { - match = parse_tree[i]; // convenience purposes only - if (match[2]) { // keyword argument - arg = argv[cursor]; - for (k = 0; k < match[2].length; k++) { - if (!arg.hasOwnProperty(match[2][k])) { - throw new Error(sprintf('[sprintf] property "%s" does not exist', match[2][k])); - } - arg = arg[match[2][k]]; - } - } - else if (match[1]) { // positional argument (explicit) - arg = argv[match[1]]; - } - else { // positional argument (implicit) - arg = argv[cursor++]; - } - - if (/[^sO]/.test(match[8]) && (get_type(arg) != 'number')) { - throw new Error(sprintf('[sprintf] expecting number but found %s "' + arg + '"', get_type(arg))); - } - switch (match[8]) { - case 'b': arg = arg.toString(2); break; - case 'c': arg = String.fromCharCode(arg); break; - case 'd': arg = parseInt(arg, 10); break; - case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; - case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; - case 'O': arg = str_format.object_stringify(arg, 0, parseInt(match[7]) || 5); break; - case 'o': arg = arg.toString(8); break; - case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; - case 'u': arg = Math.abs(arg); break; - case 'x': arg = arg.toString(16); break; - case 'X': arg = arg.toString(16).toUpperCase(); break; - } - arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); - pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; - pad_length = match[6] - String(arg).length; - pad = match[6] ? str_repeat(pad_character, pad_length) : ''; - output.push(match[5] ? arg + pad : pad + arg); - } - } - return output.join(''); - }; - - str_format.cache = {}; - - str_format.parse = function(fmt) { - var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; - while (_fmt) { - if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { - parse_tree.push(match[0]); - } - else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { - parse_tree.push('%'); - } - else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosOuxX])/.exec(_fmt)) !== null) { - if (match[2]) { - arg_names |= 1; - var field_list = [], replacement_field = match[2], field_match = []; - if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { - field_list.push(field_match[1]); - while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { - if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { - field_list.push(field_match[1]); - } - else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { - field_list.push(field_match[1]); - } - else { - throw new Error('[sprintf] ' + replacement_field); - } - } - } - else { - throw new Error('[sprintf] ' + replacement_field); - } - match[2] = field_list; - } - else { - arg_names |= 2; - } - if (arg_names === 3) { - throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported'); - } - parse_tree.push(match); - } - else { - throw new Error('[sprintf] ' + _fmt); - } - _fmt = _fmt.substring(match[0].length); - } - return parse_tree; - }; - - return str_format; -})(); - -var vsprintf = function(fmt, argv) { - var argvClone = argv.slice(); - argvClone.unshift(fmt); - return sprintf.apply(null, argvClone); -}; - -module.exports = sprintf; -sprintf.sprintf = sprintf; -sprintf.vsprintf = vsprintf; diff --git a/node_modules/ipv6/node_modules/sprintf/package.json b/node_modules/ipv6/node_modules/sprintf/package.json deleted file mode 100644 index c81d208..0000000 --- a/node_modules/ipv6/node_modules/sprintf/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "sprintf", - "version": "0.1.3", - "engines": { - "node": ">=0.2.4" - }, - "author": { - "name": "Moritz Peters" - }, - "directories": { - "lib": "./lib" - }, - "description": "Sprintf() for node.js", - "main": "./lib/sprintf", - "homepage": "https://github.com/maritz/node-sprintf", - "repository": { - "type": "git", - "url": "https://github.com/maritz/node-sprintf.git" - }, - "scripts": { - "test": "nodeunit test/function-export.js" - }, - "devDependencies": { - "nodeunit": "0.8.0" - }, - "bugs": { - "url": "https://github.com/maritz/node-sprintf/issues" - }, - "_id": "sprintf@0.1.3", - "dist": { - "shasum": "530fc31405d47422f6edb40f29bdafac599ede11", - "tarball": "http://registry.npmjs.org/sprintf/-/sprintf-0.1.3.tgz" - }, - "_from": "sprintf@0.1.x", - "_npmVersion": "1.3.8", - "_npmUser": { - "name": "maritz", - "email": "maritz.peters@gmail.com" - }, - "maintainers": [ - { - "name": "maritz", - "email": "moritz@mpeters.biz" - } - ], - "_shasum": "530fc31405d47422f6edb40f29bdafac599ede11", - "_resolved": "https://registry.npmjs.org/sprintf/-/sprintf-0.1.3.tgz" -} diff --git a/node_modules/ipv6/node_modules/sprintf/test/function-export.js b/node_modules/ipv6/node_modules/sprintf/test/function-export.js deleted file mode 100644 index 468e760..0000000 --- a/node_modules/ipv6/node_modules/sprintf/test/function-export.js +++ /dev/null @@ -1,9 +0,0 @@ -var sprintf = require(__dirname + '/..'); - -exports['sprintf() export works'] = function(test) { - test.equal(sprintf('Hallo %s!', 'Welt'), 'Hallo Welt!'); - test.equal(sprintf.sprintf('Hallo %s!', 'Welt'), 'Hallo Welt!'); - test.equal(sprintf.vsprintf('Hallo %s!', ['Welt']), 'Hallo Welt!'); - - test.done(); -}; diff --git a/node_modules/ipv6/package.json b/node_modules/ipv6/package.json deleted file mode 100644 index 3e18f12..0000000 --- a/node_modules/ipv6/package.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "name": "ipv6", - "description": "A browser- and node-compatible library for parsing IPv6 addresses", - "keywords": [ - "ipv6", - "browser", - "validation" - ], - "version": "3.1.1", - "author": { - "name": "Beau Gunderson", - "email": "beau@beaugunderson.com" - }, - "license": "MIT", - "main": "index", - "scripts": { - "test": "./node_modules/.bin/mocha --reporter spec" - }, - "bin": { - "ipv6": "bin/ipv6.js", - "ipv6grep": "bin/ipv6grep.js" - }, - "engine": { - "node": ">= 0.4.1" - }, - "repository": { - "type": "git", - "url": "git://github.com/beaugunderson/javascript-ipv6.git" - }, - "dependencies": { - "sprintf": "0.1.x", - "cli": "0.4.x", - "cliff": "0.1.x" - }, - "devDependencies": { - "mocha": "1.15.x", - "chai": "1.8.x" - }, - "engines": { - "node": "*" - }, - "readme": "javascript-ipv6 [![Build Status](https://secure.travis-ci.org/beaugunderson/javascript-ipv6.png?branch=master)](http://travis-ci.org/beaugunderson/javascript-ipv6)\n===============\n\njavascript-ipv6 is a library for manipulating IPv6 addresses in JavaScript.\n\nExamples\n--------\n\nFor node:\n\n```js\nvar v6 = require('ipv6').v6;\n\nvar address = new v6.Address('2001:0:ce49:7601:e866:efff:62c3:fffe');\n\nconsole.log(address.isValid()); // Prints \"true\"\n\nvar teredo = address.teredo();\n\nconsole.log(teredo.client4); // Prints \"157.60.0.1\"\n```\n\nFor a browser:\n\n```html\n\n\n \n Simple IPv6 test\n\n \n\n \n \n\n \n\n \n\n \n \n\n \n The canonical form of a::b is: \n \n\n```\n\nCurrent functionality\n---------------------\n\n- Parsing of most IPv6 notations\n- Parsing of IPv6 Addresses and Ports from URLs with `v6.Address.fromURL(url)`\n- Validity checking\n- Decoding of the [Teredo information](http://en.wikipedia.org/wiki/Teredo_tunneling#IPv6_addressing) in an address\n- Whether one address is a valid subnet of another\n- What special properties a given address has (multicast prefix, unique local address prefix, etc.)\n- Number of subnets of a certain size in a given address\n- Display methods\n - Hex, binary, and decimal\n - Canonical form\n - Correct form\n - IPv4-compatible (i.e. `::ffff:192.168.0.1`)\n- Works in [node.js](http://nodejs.org/) and the browser\n- Unit tests with [node.js](http://nodejs.org/) and [Mocha](http://visionmedia.github.com/mocha/)\n\nUsed by\n-------\n\n- [Rackspace](http://www.rackspace.com/) in [node-swiz](https://github.com/racker/node-swiz)\n- [node-socksified](https://github.com/vially/node-socksified)\n\nFuture functionality\n--------------------\n\n- Investigate `procstreams` for the CLI tool\n- Base 64/85 encoding?\n- Reverse lookups? (Whether a domain name has IPv6 glue)\n\nTODO\n----\n\n- Documentation\n", - "readmeFilename": "README.md", - "bugs": { - "url": "https://github.com/beaugunderson/javascript-ipv6/issues" - }, - "homepage": "https://github.com/beaugunderson/javascript-ipv6", - "_id": "ipv6@3.1.1", - "dist": { - "shasum": "46da0e260af36fd9beb41297c987b7c21a2d9e1c", - "tarball": "http://registry.npmjs.org/ipv6/-/ipv6-3.1.1.tgz" - }, - "_from": "ipv6@", - "_npmVersion": "1.3.17", - "_npmUser": { - "name": "beaugunderson", - "email": "beau@beaugunderson.com" - }, - "maintainers": [ - { - "name": "beaugunderson", - "email": "beau@beaugunderson.com" - } - ], - "directories": {}, - "_shasum": "46da0e260af36fd9beb41297c987b7c21a2d9e1c", - "_resolved": "https://registry.npmjs.org/ipv6/-/ipv6-3.1.1.tgz" -} diff --git a/node_modules/ipv6/test/address-test.js b/node_modules/ipv6/test/address-test.js deleted file mode 100644 index 2996c34..0000000 --- a/node_modules/ipv6/test/address-test.js +++ /dev/null @@ -1,164 +0,0 @@ -var should = require('chai').should(); - -var v4 = require('../ipv6').v4; -var v6 = require('../ipv6').v6; - -function addressIs(addressString, descriptors) { - var address4 = new v4.Address(addressString); - var address6 = new v6.Address(addressString); - - describe(addressString, function () { - descriptors.forEach(function (descriptor) { - if (descriptor === 'valid-ipv4') { - it('is valid', function () { - address4.should.be.an('object'); - - address4.parsedAddress.should.be.an.instanceOf(Array); - address4.parsedAddress.length.should.equal(4); - - address4.subnetMask.should.be.a('number'); - - address4.subnetMask.should.be.at.least(0); - address4.subnetMask.should.be.at.most(128); - - should.not.exist(address4.error); - should.not.exist(address4.parseError); - - address4.isValid().should.equal(true); - }); - } - - if (descriptor === 'valid-ipv6') { - it('is valid', function () { - address6.should.be.an('object'); - - address6.zone.should.be.a('string'); - - address6.subnet.should.be.a('string'); - - address6.subnetMask.should.be.a('number'); - - address6.subnetMask.should.be.at.least(0); - address6.subnetMask.should.be.at.most(128); - - address6.parsedAddress.should.be.an.instanceOf(Array); - address6.parsedAddress.length.should.equal(8); - - should.not.exist(address6.error); - should.not.exist(address6.parseError); - - address6.isValid().should.equal(true); - }); - - // TODO: These aren't quite ready for primetime yet. - /* - it('validates the correct form via regex', function () { - var re = address.regularExpression(); - - re.test(address.correctForm()).should.equal(true); - }); - - it('validates the canonical form via regex', function () { - var re = address.regularExpression(); - - re.test(address.canonicalForm()).should.equal(true); - }); - */ - } - - if (descriptor === 'invalid-ipv4') { - it('is invalid as parsed by v4', function () { - address4.error.should.be.a('string'); - - address4.isValid().should.equal(false); - }); - } - - if (descriptor === 'invalid-ipv6') { - it('is invalid as parsed by v6', function () { - address6.error.should.be.a('string'); - - address6.isValid().should.equal(false); - }); - } - - if (descriptor === 'canonical') { - it('is canonical', function () { - address6.isCanonical().should.equal(true); - - should.equal(address6.addressMinusSuffix.length, 39); - }); - } - - if (descriptor === 'correct') { - it('is correct', function () { - address6.isCorrect().should.equal(true); - }); - } - - if (descriptor === 'correct-ipv4') { - it('is correct', function () { - address4.isCorrect().should.equal(true); - }); - } - - if (descriptor === 'incorrect') { - it('is incorrect', function () { - address6.isCorrect().should.equal(false); - }); - } - - if (descriptor === 'incorrect-ipv4') { - it('is incorrect', function () { - address4.isCorrect().should.equal(false); - }); - } - - if (descriptor === 'has-subnet') { - it('parses the subnet', function () { - address6.subnet.should.match(/^\/\d{1,3}/); - }); - } - - if (descriptor === 'v4-in-v6') { - it('is an ipv4-in-ipv6 address', function () { - address6.is4().should.equal(true); - }); - } - }); - }); -} - -function loadJsonBatch(file, classes, noMerge) { - // Load the list of test addresses - var addresses = require(file); - - addresses.forEach(function (address) { - if (address.conditions === undefined || - !address.conditions.length || noMerge) { - address.conditions = classes; - } else { - address.conditions = address.conditions.concat(classes); - } - - addressIs(address.address, address.conditions); - }); -} - -describe('Valid IPv4 addresses', function () { - loadJsonBatch('./data/valid-ipv4-addresses.json', ['valid-ipv4']); - loadJsonBatch('./data/valid-ipv4-addresses.json', ['invalid-ipv6'], true); -}); - -describe('Valid IPv6 addresses', function () { - loadJsonBatch('./data/valid-ipv6-addresses.json', ['valid-ipv6']); - loadJsonBatch('./data/valid-ipv6-addresses.json', ['invalid-ipv4'], true); -}); - -describe('Invalid IPv4 addresses', function () { - loadJsonBatch('./data/invalid-ipv4-addresses.json', ['invalid-ipv4']); -}); - -describe('Invalid IPv6 addresses', function () { - loadJsonBatch('./data/invalid-ipv6-addresses.json', ['invalid-ipv6']); -}); diff --git a/node_modules/ipv6/test/data/invalid-ipv4-addresses.json b/node_modules/ipv6/test/data/invalid-ipv4-addresses.json deleted file mode 100644 index 6486cea..0000000 --- a/node_modules/ipv6/test/data/invalid-ipv4-addresses.json +++ /dev/null @@ -1,46 +0,0 @@ -[ - { - "address": " 127.0.0.1", - "conditions": [] - }, - { - "address": "127.0.0.1 ", - "conditions": [] - }, - { - "address": "127.0.0.1 127.0.0.1", - "conditions": [] - }, - { - "address": "127.0.0.256", - "conditions": [] - }, - { - "address": "127.0.0.1//1", - "conditions": [] - }, - { - "address": "127.0.0.1/0x1", - "conditions": [] - }, - { - "address": "127.0.0.1/-1", - "conditions": [] - }, - { - "address": "127.0.0.1/ab", - "conditions": [] - }, - { - "address": "127.0.0.1/", - "conditions": [] - }, - { - "address": "127.0.0.256/32", - "conditions": [] - }, - { - "address": "127.0.0.1/33", - "conditions": [] - } -] diff --git a/node_modules/ipv6/test/data/invalid-ipv6-addresses.json b/node_modules/ipv6/test/data/invalid-ipv6-addresses.json deleted file mode 100644 index 1cca25f..0000000 --- a/node_modules/ipv6/test/data/invalid-ipv6-addresses.json +++ /dev/null @@ -1,1282 +0,0 @@ -[ - { - "address": "':10.0.0.1", - "conditions": [] - }, - { - "address": "-1", - "conditions": [] - }, - { - "address": "::1 ::1", - "conditions": [] - }, - { - "address": "02001:0000:1234:0000:0000:C1C0:ABCD:0876", - "conditions": [] - }, - { - "address": "1.2.3.4", - "conditions": [] - }, - { - "address": "1.2.3.4:1111:2222:3333:4444::5555", - "conditions": [] - }, - { - "address": "1.2.3.4:1111:2222:3333::5555", - "conditions": [] - }, - { - "address": "1.2.3.4:1111:2222::5555", - "conditions": [] - }, - { - "address": "1.2.3.4:1111::5555", - "conditions": [] - }, - { - "address": "1.2.3.4::", - "conditions": [] - }, - { - "address": "1.2.3.4::5555", - "conditions": [] - }, - { - "address": "1111", - "conditions": [] - }, - { - "address": "11112222:3333:4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": "11112222:3333:4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": "::1//64", - "conditions": [] - }, - { - "address": "::1/0001", - "conditions": [] - }, - { - "address": "1111:", - "conditions": [] - }, - { - "address": "1111:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222", - "conditions": [] - }, - { - "address": "1111:22223333:4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:22223333:4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": "1111:2222:", - "conditions": [] - }, - { - "address": "1111:2222:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333", - "conditions": [] - }, - { - "address": "1111:2222:33334444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:33334444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": "1111:2222:3333:", - "conditions": [] - }, - { - "address": "1111:2222:3333:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444", - "conditions": [] - }, - { - "address": "1111:2222:3333:44445555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333:44445555:6666:7777:8888", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:55556666:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:55556666:7777:8888", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:66661.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:66667777:8888", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:00.00.00.00", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:000.000.000.000", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:1.2.3.4.5", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:255.255.255255", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:255.255255.255", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:255255.255.255", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:256.256.256.256", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:7777", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:77778888", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:7777:", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:7777:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:7777:8888:", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:7777:8888:9999", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:7777:8888::", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:7777:::", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666::1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666::8888:", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:::", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:6666:::8888", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555::7777:8888:", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555::7777::", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555::8888:", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:::", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:::1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:5555:::7777:8888", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444::5555:", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444::6666:7777:8888:", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444::6666:7777::", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444::6666::8888", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444::7777:8888:", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444::8888:", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:::", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:::6666:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333:4444:::6666:7777:8888", - "conditions": [] - }, - { - "address": "1111:2222:3333::5555:", - "conditions": [] - }, - { - "address": "1111:2222:3333::5555:6666:7777:8888:", - "conditions": [] - }, - { - "address": "1111:2222:3333::5555:6666:7777::", - "conditions": [] - }, - { - "address": "1111:2222:3333::5555:6666::8888", - "conditions": [] - }, - { - "address": "1111:2222:3333::5555::1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333::5555::7777:8888", - "conditions": [] - }, - { - "address": "1111:2222:3333::6666:7777:8888:", - "conditions": [] - }, - { - "address": "1111:2222:3333::7777:8888:", - "conditions": [] - }, - { - "address": "1111:2222:3333::8888:", - "conditions": [] - }, - { - "address": "1111:2222:3333:::", - "conditions": [] - }, - { - "address": "1111:2222:3333:::5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:3333:::5555:6666:7777:8888", - "conditions": [] - }, - { - "address": "1111:2222::4444:5555:6666:7777:8888:", - "conditions": [] - }, - { - "address": "1111:2222::4444:5555:6666:7777::", - "conditions": [] - }, - { - "address": "1111:2222::4444:5555:6666::8888", - "conditions": [] - }, - { - "address": "1111:2222::4444:5555::1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222::4444:5555::7777:8888", - "conditions": [] - }, - { - "address": "1111:2222::4444::6666:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222::4444::6666:7777:8888", - "conditions": [] - }, - { - "address": "1111:2222::5555:", - "conditions": [] - }, - { - "address": "1111:2222::5555:6666:7777:8888:", - "conditions": [] - }, - { - "address": "1111:2222::6666:7777:8888:", - "conditions": [] - }, - { - "address": "1111:2222::7777:8888:", - "conditions": [] - }, - { - "address": "1111:2222::8888:", - "conditions": [] - }, - { - "address": "1111:2222:::", - "conditions": [] - }, - { - "address": "1111:2222:::4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:2222:::4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": "1111::3333:4444:5555:6666:7777:8888:", - "conditions": [] - }, - { - "address": "1111::3333:4444:5555:6666:7777::", - "conditions": [] - }, - { - "address": "1111::3333:4444:5555:6666::8888", - "conditions": [] - }, - { - "address": "1111::3333:4444:5555::1.2.3.4", - "conditions": [] - }, - { - "address": "1111::3333:4444:5555::7777:8888", - "conditions": [] - }, - { - "address": "1111::3333:4444::6666:1.2.3.4", - "conditions": [] - }, - { - "address": "1111::3333:4444::6666:7777:8888", - "conditions": [] - }, - { - "address": "1111::3333::5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": "1111::3333::5555:6666:7777:8888", - "conditions": [] - }, - { - "address": "1111::4444:5555:6666:7777:8888:", - "conditions": [] - }, - { - "address": "1111::5555:", - "conditions": [] - }, - { - "address": "1111::5555:6666:7777:8888:", - "conditions": [] - }, - { - "address": "1111::6666:7777:8888:", - "conditions": [] - }, - { - "address": "1111::7777:8888:", - "conditions": [] - }, - { - "address": "1111::8888:", - "conditions": [] - }, - { - "address": "1111:::", - "conditions": [] - }, - { - "address": "1111:::3333:4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": "1111:::3333:4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": "123", - "conditions": [] - }, - { - "address": "12345::6:7:8", - "conditions": [] - }, - { - "address": "124.15.6.89/60", - "conditions": [] - }, - { - "address": "1:2:3:4:5:6:7:8:9", - "conditions": [] - }, - { - "address": "1:2:3::4:5:6:7:8:9", - "conditions": [] - }, - { - "address": "1:2:3::4:5::7:8", - "conditions": [] - }, - { - "address": "1::1.2.256.4", - "conditions": [] - }, - { - "address": "1::1.2.3.256", - "conditions": [] - }, - { - "address": "1::1.2.3.300", - "conditions": [] - }, - { - "address": "1::1.2.3.900", - "conditions": [] - }, - { - "address": "1::1.2.300.4", - "conditions": [] - }, - { - "address": "1::1.2.900.4", - "conditions": [] - }, - { - "address": "1::1.256.3.4", - "conditions": [] - }, - { - "address": "1::1.300.3.4", - "conditions": [] - }, - { - "address": "1::1.900.3.4", - "conditions": [] - }, - { - "address": "1::256.2.3.4", - "conditions": [] - }, - { - "address": "1::260.2.3.4", - "conditions": [] - }, - { - "address": "1::2::3", - "conditions": [] - }, - { - "address": "1::300.2.3.4", - "conditions": [] - }, - { - "address": "1::300.300.300.300", - "conditions": [] - }, - { - "address": "1::3000.30.30.30", - "conditions": [] - }, - { - "address": "1::400.2.3.4", - "conditions": [] - }, - { - "address": "1::5:1.2.256.4", - "conditions": [] - }, - { - "address": "1::5:1.2.3.256", - "conditions": [] - }, - { - "address": "1::5:1.2.3.300", - "conditions": [] - }, - { - "address": "1::5:1.2.3.900", - "conditions": [] - }, - { - "address": "1::5:1.2.300.4", - "conditions": [] - }, - { - "address": "1::5:1.2.900.4", - "conditions": [] - }, - { - "address": "1::5:1.256.3.4", - "conditions": [] - }, - { - "address": "1::5:1.300.3.4", - "conditions": [] - }, - { - "address": "1::5:1.900.3.4", - "conditions": [] - }, - { - "address": "1::5:256.2.3.4", - "conditions": [] - }, - { - "address": "1::5:260.2.3.4", - "conditions": [] - }, - { - "address": "1::5:300.2.3.4", - "conditions": [] - }, - { - "address": "1::5:300.300.300.300", - "conditions": [] - }, - { - "address": "1::5:3000.30.30.30", - "conditions": [] - }, - { - "address": "1::5:400.2.3.4", - "conditions": [] - }, - { - "address": "1::5:900.2.3.4", - "conditions": [] - }, - { - "address": "1::900.2.3.4", - "conditions": [] - }, - { - "address": "1:::3:4:5", - "conditions": [] - }, - { - "address": "2001:0000:1234: 0000:0000:C1C0:ABCD:0876", - "conditions": [] - }, - { - "address": "2001:0000:1234:0000:00001:C1C0:ABCD:0876", - "conditions": [] - }, - { - "address": "2001:0000:1234:0000:0000:C1C0:ABCD:0876 0", - "conditions": [] - }, - { - "address": "2001:1:1:1:1:1:255Z255X255Y255", - "conditions": [] - }, - { - "address": "2001::FFD3::57ab", - "conditions": [] - }, - { - "address": "2001:DB8:0:0:8:800:200C:417A:221", - "conditions": [] - }, - { - "address": "2001:db8:85a3::8a2e:37023:7334", - "conditions": [] - }, - { - "address": "2001:db8:85a3::8a2e:370k:7334", - "conditions": [] - }, - { - "address": "3ffe:0b00:0000:0001:0000:0000:000a", - "conditions": [] - }, - { - "address": "3ffe:b00::1::a", - "conditions": [] - }, - { - "address": ":", - "conditions": [] - }, - { - "address": ":1.2.3.4", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444:5555:6666:7777::", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444:5555:6666::", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444:5555:6666::8888", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444:5555::", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444:5555::1.2.3.4", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444:5555::7777:8888", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444:5555::8888", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444::", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444::1.2.3.4", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444::5555", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444::6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444::6666:7777:8888", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444::7777:8888", - "conditions": [] - }, - { - "address": ":1111:2222:3333:4444::8888", - "conditions": [] - }, - { - "address": ":1111:2222:3333::", - "conditions": [] - }, - { - "address": ":1111:2222:3333::1.2.3.4", - "conditions": [] - }, - { - "address": ":1111:2222:3333::5555", - "conditions": [] - }, - { - "address": ":1111:2222:3333::5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":1111:2222:3333::5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":1111:2222:3333::6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":1111:2222:3333::6666:7777:8888", - "conditions": [] - }, - { - "address": ":1111:2222:3333::7777:8888", - "conditions": [] - }, - { - "address": ":1111:2222:3333::8888", - "conditions": [] - }, - { - "address": ":1111:2222::", - "conditions": [] - }, - { - "address": ":1111:2222::1.2.3.4", - "conditions": [] - }, - { - "address": ":1111:2222::4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":1111:2222::4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":1111:2222::5555", - "conditions": [] - }, - { - "address": ":1111:2222::5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":1111:2222::5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":1111:2222::6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":1111:2222::6666:7777:8888", - "conditions": [] - }, - { - "address": ":1111:2222::7777:8888", - "conditions": [] - }, - { - "address": ":1111:2222::8888", - "conditions": [] - }, - { - "address": ":1111::", - "conditions": [] - }, - { - "address": ":1111::1.2.3.4", - "conditions": [] - }, - { - "address": ":1111::3333:4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":1111::3333:4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":1111::4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":1111::4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":1111::5555", - "conditions": [] - }, - { - "address": ":1111::5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":1111::5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":1111::6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":1111::6666:7777:8888", - "conditions": [] - }, - { - "address": ":1111::7777:8888", - "conditions": [] - }, - { - "address": ":1111::8888", - "conditions": [] - }, - { - "address": ":2222:3333:4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":2222:3333:4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":3333:4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":3333:4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":6666:7777:8888", - "conditions": [] - }, - { - "address": ":7777:8888", - "conditions": [] - }, - { - "address": ":8888", - "conditions": [] - }, - { - "address": "::-1", - "conditions": [] - }, - { - "address": "::.", - "conditions": [] - }, - { - "address": "::..", - "conditions": [] - }, - { - "address": "::...", - "conditions": [] - }, - { - "address": "::...4", - "conditions": [] - }, - { - "address": "::..3.", - "conditions": [] - }, - { - "address": "::..3.4", - "conditions": [] - }, - { - "address": "::.2..", - "conditions": [] - }, - { - "address": "::.2.3.", - "conditions": [] - }, - { - "address": "::.2.3.4", - "conditions": [] - }, - { - "address": "::1...", - "conditions": [] - }, - { - "address": "::1.2..", - "conditions": [] - }, - { - "address": "::1.2.256.4", - "conditions": [] - }, - { - "address": "::1.2.3.", - "conditions": [] - }, - { - "address": "::1.2.3.256", - "conditions": [] - }, - { - "address": "::1.2.3.300", - "conditions": [] - }, - { - "address": "::1.2.3.900", - "conditions": [] - }, - { - "address": "::1.2.300.4", - "conditions": [] - }, - { - "address": "::1.2.900.4", - "conditions": [] - }, - { - "address": "::1.256.3.4", - "conditions": [] - }, - { - "address": "::1.300.3.4", - "conditions": [] - }, - { - "address": "::1.900.3.4", - "conditions": [] - }, - { - "address": "::1111:2222:3333:4444:5555:6666::", - "conditions": [] - }, - { - "address": "::2222:3333:4444:5555:6666:7777:1.2.3.4", - "conditions": [] - }, - { - "address": "::2222:3333:4444:5555:6666:7777:8888:", - "conditions": [] - }, - { - "address": "::2222:3333:4444:5555:6666:7777:8888:9999", - "conditions": [] - }, - { - "address": "::2222:3333:4444:5555:7777:8888::", - "conditions": [] - }, - { - "address": "::2222:3333:4444:5555:7777::8888", - "conditions": [] - }, - { - "address": "::2222:3333:4444:5555::1.2.3.4", - "conditions": [] - }, - { - "address": "::2222:3333:4444:5555::7777:8888", - "conditions": [] - }, - { - "address": "::2222:3333:4444::6666:1.2.3.4", - "conditions": [] - }, - { - "address": "::2222:3333:4444::6666:7777:8888", - "conditions": [] - }, - { - "address": "::2222:3333::5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": "::2222:3333::5555:6666:7777:8888", - "conditions": [] - }, - { - "address": "::2222::4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": "::2222::4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": "::256.2.3.4", - "conditions": [] - }, - { - "address": "::260.2.3.4", - "conditions": [] - }, - { - "address": "::300.2.3.4", - "conditions": [] - }, - { - "address": "::300.300.300.300", - "conditions": [] - }, - { - "address": "::3000.30.30.30", - "conditions": [] - }, - { - "address": "::3333:4444:5555:6666:7777:8888:", - "conditions": [] - }, - { - "address": "::400.2.3.4", - "conditions": [] - }, - { - "address": "::4444:5555:6666:7777:8888:", - "conditions": [] - }, - { - "address": "::5555:", - "conditions": [] - }, - { - "address": "::5555:6666:7777:8888:", - "conditions": [] - }, - { - "address": "::6666:7777:8888:", - "conditions": [] - }, - { - "address": "::7777:8888:", - "conditions": [] - }, - { - "address": "::8888:", - "conditions": [] - }, - { - "address": "::900.2.3.4", - "conditions": [] - }, - { - "address": ":::", - "conditions": [] - }, - { - "address": ":::1.2.3.4", - "conditions": [] - }, - { - "address": ":::2222:3333:4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":::2222:3333:4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":::3333:4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":::4444:5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":::4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":::5555", - "conditions": [] - }, - { - "address": ":::5555:6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":::5555:6666:7777:8888", - "conditions": [] - }, - { - "address": ":::6666:1.2.3.4", - "conditions": [] - }, - { - "address": ":::6666:7777:8888", - "conditions": [] - }, - { - "address": ":::7777:8888", - "conditions": [] - }, - { - "address": ":::8888", - "conditions": [] - }, - { - "address": "::ffff:192x168.1.26", - "conditions": [] - }, - { - "address": "::ffff:2.3.4", - "conditions": [] - }, - { - "address": "::ffff:257.1.2.3", - "conditions": [] - }, - { - "address": "FF01::101::2", - "conditions": [] - }, - { - "address": "FF02:0000:0000:0000:0000:0000:0000:0000:0001", - "conditions": [] - }, - { - "address": "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4", - "conditions": [] - }, - { - "address": "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX", - "conditions": [] - }, - { - "address": "a::b::c", - "conditions": [] - }, - { - "address": "a::g", - "conditions": [] - }, - { - "address": "a:a:a:a:a:a:a:a:a", - "conditions": [] - }, - { - "address": "a:aaaaa::", - "conditions": [] - }, - { - "address": "a:b", - "conditions": [] - }, - { - "address": "a:b:c:d:e:f:g:0", - "conditions": [] - }, - { - "address": "fe80:0000:0000:0000:0204:61ff:254.157.241.086", - "conditions": [] - }, - { - "address": "ffff:", - "conditions": [] - }, - { - "address": "ffff::ffff::ffff", - "conditions": [] - }, - { - "address": "ffgg:ffff:ffff:ffff:ffff:ffff:ffff:ffff", - "conditions": [] - }, - { - "address": "ldkfj", - "conditions": [] - }, - { - "address": "::/129", - "conditions": [] - }, - { - "address": "1000:://32", - "conditions": [] - }, - { - "address": "::/", - "conditions": [] - } -] diff --git a/node_modules/ipv6/test/data/valid-ipv4-addresses.json b/node_modules/ipv6/test/data/valid-ipv4-addresses.json deleted file mode 100644 index b2bf8a1..0000000 --- a/node_modules/ipv6/test/data/valid-ipv4-addresses.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "address": "001.002.003.004", - "conditions": ["incorrect-ipv4"] - }, - { - "address": "127.0.0.1", - "conditions": ["correct-ipv4"] - }, - { - "address": "127.0.0.1/02", - "conditions": ["incorrect-ipv4"] - }, - { - "address": "127.0.0.1/32", - "conditions": ["correct-ipv4"] - }, - { - "address": "255.255.255.255/32", - "conditions": ["correct-ipv4"] - } -] diff --git a/node_modules/ipv6/test/data/valid-ipv6-addresses.json b/node_modules/ipv6/test/data/valid-ipv6-addresses.json deleted file mode 100644 index ec0cade..0000000 --- a/node_modules/ipv6/test/data/valid-ipv6-addresses.json +++ /dev/null @@ -1,766 +0,0 @@ -[ - { - "address": "0000:0000:0000:0000:0000:0000:0000:0000/128", - "conditions": ["incorrect", "canonical", "has-subnet"] - }, - { - "address": "0000:0000:0000:0000:0000:0000:0000:0000", - "conditions": ["incorrect", "canonical"] - }, - { - "address": "0000:0000:0000:0000:0000:0000:0000:0001", - "conditions": ["incorrect", "canonical"] - }, - { - "address": "0:0:0:0:0:0:0:0", - "conditions": ["incorrect"] - }, - { - "address": "0:0:0:0:0:0:0:1", - "conditions": ["incorrect"] - }, - { - "address": "0:0:0:0:0:0:0::", - "conditions": ["incorrect"] - }, - { - "address": "0:0:0:0:0:0:13.1.68.3", - "conditions": ["incorrect", "v4-in-v6"] - }, - { - "address": "0:0:0:0:0:0::", - "conditions": ["incorrect"] - }, - { - "address": "0:0:0:0:0::", - "conditions": ["incorrect"] - }, - { - "address": "0:0:0:0:0:FFFF:129.144.52.38", - "conditions": ["incorrect", "v4-in-v6"] - }, - { - "address": "0:0:0:0:1:0:0:0", - "conditions": ["incorrect"] - }, - { - "address": "0:0:0:0::", - "conditions": ["incorrect"] - }, - { - "address": "0:0:0::", - "conditions": ["incorrect"] - }, - { - "address": "0:0::", - "conditions": ["incorrect"] - }, - { - "address": "0:1:2:3:4:5:6:7/001", - "conditions": ["incorrect", "has-subnet"] - }, - { - "address": "0:1:2:3:4:5:6:7/128", - "conditions": ["correct", "has-subnet"] - }, - { - "address": "0:1:2:3:4:5:6:7", - "conditions": ["correct"] - }, - { - "address": "0::", - "conditions": ["incorrect"] - }, - { - "address": "0:a:b:c:d:e:f::", - "conditions": ["incorrect"] - }, - { - "address": "1080:0:0:0:8:800:200c:417a", - "conditions": ["incorrect"] - }, - { - "address": "1080::8:800:200c:417a", - "conditions": ["correct"] - }, - { - "address": "1111:2222:3333:4444:5555:6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111:2222:3333:4444:5555:6666:7777:8888", - "conditions": ["correct"] - }, - { - "address": "1111:2222:3333:4444:5555:6666:7777::", - "conditions": ["incorrect"] - }, - { - "address": "1111:2222:3333:4444:5555:6666::", - "conditions": ["correct"] - }, - { - "address": "1111:2222:3333:4444:5555:6666::8888", - "conditions": ["incorrect"] - }, - { - "address": "1111:2222:3333:4444:5555::", - "conditions": ["correct"] - }, - { - "address": "1111:2222:3333:4444:5555::123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111:2222:3333:4444:5555::7777:8888", - "conditions": ["incorrect"] - }, - { - "address": "1111:2222:3333:4444:5555::8888", - "conditions": ["correct"] - }, - { - "address": "1111:2222:3333:4444::", - "conditions": ["correct"] - }, - { - "address": "1111:2222:3333:4444::123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111:2222:3333:4444::6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111:2222:3333:4444::6666:7777:8888", - "conditions": ["incorrect"] - }, - { - "address": "1111:2222:3333:4444::7777:8888", - "conditions": ["correct"] - }, - { - "address": "1111:2222:3333:4444::8888", - "conditions": ["correct"] - }, - { - "address": "1111:2222:3333::", - "conditions": ["correct"] - }, - { - "address": "1111:2222:3333::123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111:2222:3333::5555:6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111:2222:3333::5555:6666:7777:8888", - "conditions": ["incorrect"] - }, - { - "address": "1111:2222:3333::6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111:2222:3333::6666:7777:8888", - "conditions": ["correct"] - }, - { - "address": "1111:2222:3333::7777:8888", - "conditions": ["correct"] - }, - { - "address": "1111:2222:3333::8888", - "conditions": ["correct"] - }, - { - "address": "1111:2222::", - "conditions": ["correct"] - }, - { - "address": "1111:2222::123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111:2222::4444:5555:6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111:2222::4444:5555:6666:7777:8888", - "conditions": ["incorrect"] - }, - { - "address": "1111:2222::5555:6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111:2222::5555:6666:7777:8888", - "conditions": ["correct"] - }, - { - "address": "1111:2222::6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111:2222::6666:7777:8888", - "conditions": ["correct"] - }, - { - "address": "1111:2222::7777:8888", - "conditions": ["correct"] - }, - { - "address": "1111:2222::8888", - "conditions": ["correct"] - }, - { - "address": "1111::", - "conditions": ["correct"] - }, - { - "address": "1111::123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111::3333:4444:5555:6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111::3333:4444:5555:6666:7777:8888", - "conditions": ["incorrect"] - }, - { - "address": "1111::4444:5555:6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111::4444:5555:6666:7777:8888", - "conditions": ["correct"] - }, - { - "address": "1111::5555:6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111::5555:6666:7777:8888", - "conditions": ["correct"] - }, - { - "address": "1111::6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "1111::6666:7777:8888", - "conditions": ["correct"] - }, - { - "address": "1111::7777:8888", - "conditions": ["correct"] - }, - { - "address": "1111::8888", - "conditions": ["correct"] - }, - { - "address": "1:2:3:4:5:6:1.2.3.4", - "conditions": ["v4-in-v6"] - }, - { - "address": "1:2:3:4:5:6:7:8", - "conditions": ["correct"] - }, - { - "address": "1:2:3:4:5:6::", - "conditions": ["correct"] - }, - { - "address": "1:2:3:4:5:6::8", - "conditions": ["incorrect"] - }, - { - "address": "1:2:3:4:5::", - "conditions": ["correct"] - }, - { - "address": "1:2:3:4:5::1.2.3.4", - "conditions": ["v4-in-v6"] - }, - { - "address": "1:2:3:4:5::7:8", - "conditions": ["incorrect"] - }, - { - "address": "1:2:3:4:5::8", - "conditions": ["correct"] - }, - { - "address": "1:2:3:4::", - "conditions": ["correct"] - }, - { - "address": "1:2:3:4::1.2.3.4", - "conditions": ["v4-in-v6"] - }, - { - "address": "1:2:3:4::5:1.2.3.4", - "conditions": ["v4-in-v6"] - }, - { - "address": "1:2:3:4::7:8", - "conditions": ["correct"] - }, - { - "address": "1:2:3:4::8", - "conditions": ["correct"] - }, - { - "address": "1:2:3::", - "conditions": ["correct"] - }, - { - "address": "1:2:3::1.2.3.4", - "conditions": ["v4-in-v6"] - }, - { - "address": "1:2:3::5:1.2.3.4", - "conditions": ["v4-in-v6"] - }, - { - "address": "1:2:3::7:8", - "conditions": ["correct"] - }, - { - "address": "1:2:3::8", - "conditions": ["correct"] - }, - { - "address": "1:2::", - "conditions": ["correct"] - }, - { - "address": "1:2::1.2.3.4", - "conditions": ["v4-in-v6"] - }, - { - "address": "1:2::5:1.2.3.4", - "conditions": ["v4-in-v6"] - }, - { - "address": "1:2::7:8", - "conditions": ["correct"] - }, - { - "address": "1:2::8", - "conditions": ["correct"] - }, - { - "address": "1::", - "conditions": ["correct"] - }, - { - "address": "1::1.2.3.4", - "conditions": ["v4-in-v6"] - }, - { - "address": "1::2:3", - "conditions": ["correct"] - }, - { - "address": "1::2:3:4", - "conditions": ["correct"] - }, - { - "address": "1::2:3:4:5", - "conditions": ["correct"] - }, - { - "address": "1::2:3:4:5:6", - "conditions": ["correct"] - }, - { - "address": "1::2:3:4:5:6:7", - "conditions": ["incorrect"] - }, - { - "address": "1::5:1.2.3.4", - "conditions": ["v4-in-v6"] - }, - { - "address": "1::5:11.22.33.44", - "conditions": ["v4-in-v6"] - }, - { - "address": "1::7:8", - "conditions": ["correct"] - }, - { - "address": "1::8", - "conditions": ["correct"] - }, - { - "address": "2001:0000:1234:0000:0000:C1C0:ABCD:0876", - "conditions": ["incorrect"] - }, - { - "address": "2001:0000:4136:e378:8000:63bf:3fff:fdd2", - "conditions": ["canonical"] - }, - { - "address": "2001:0DB8:0000:CD30:0000:0000:0000:0000/60", - "conditions": ["incorrect", "has-subnet"] - }, - { - "address": "2001:0DB8:0:CD30::/60", - "conditions": ["incorrect", "has-subnet"] - }, - { - "address": "2001:0DB8::CD30:0:0:0:0/60", - "conditions": ["incorrect", "has-subnet"] - }, - { - "address": "2001:0db8:0000:0000:0000:0000:1428:57ab", - "conditions": [] - }, - { - "address": "2001:0db8:0000:0000:0000::1428:57ab", - "conditions": [] - }, - { - "address": "2001:0db8:0:0:0:0:1428:57ab", - "conditions": [] - }, - { - "address": "2001:0db8:0:0::1428:57ab", - "conditions": [] - }, - { - "address": "2001:0db8:1234:0000:0000:0000:0000:0000", - "conditions": [] - }, - { - "address": "2001:0db8:1234::", - "conditions": [] - }, - { - "address": "2001:0db8:1234:ffff:ffff:ffff:ffff:ffff", - "conditions": [] - }, - { - "address": "2001:0db8:85a3:0000:0000:8a2e:0370:7334", - "conditions": [] - }, - { - "address": "2001:0db8::1428:57ab", - "conditions": [] - }, - { - "address": "2001::CE49:7601:2CAD:DFFF:7C94:FFFE", - "conditions": ["incorrect"] - }, - { - "address": "2001::CE49:7601:E866:EFFF:62C3:FFFE", - "conditions": ["incorrect"] - }, - { - "address": "2001:DB8:0:0:8:800:200C:417A", - "conditions": ["incorrect"] - }, - { - "address": "2001:DB8::8:800:200C:417A", - "conditions": ["incorrect"] - }, - { - "address": "2001:db8:85a3:0:0:8a2e:370:7334", - "conditions": ["incorrect"] - }, - { - "address": "2001:db8:85a3::8a2e:370:7334", - "conditions": ["correct"] - }, - { - "address": "2001:db8::", - "conditions": ["correct"] - }, - { - "address": "2001:db8::1428:57ab", - "conditions": ["correct"] - }, - { - "address": "2001:db8:a::123", - "conditions": ["correct"] - }, - { - "address": "2002::", - "conditions": ["correct"] - }, - { - "address": "2608::3:5", - "conditions": ["correct"] - }, - { - "address": "2608:af09:30:0:0:0:0:134", - "conditions": [] - }, - { - "address": "2608:af09:30::102a:7b91:c239:baff", - "conditions": [] - }, - { - "address": "2::10", - "conditions": ["correct"] - }, - { - "address": "3ffe:0b00:0000:0000:0001:0000:0000:000a", - "conditions": ["canonical"] - }, - { - "address": "7:6:5:4:3:2:1:0", - "conditions": ["correct"] - }, - { - "address": "::", - "conditions": ["correct"] - }, - { - "address": "::/128", - "conditions": ["correct", "has-subnet"] - }, - { - "address": "::0", - "conditions": [] - }, - { - "address": "::0:0", - "conditions": [] - }, - { - "address": "::0:0:0", - "conditions": [] - }, - { - "address": "::0:0:0:0", - "conditions": [] - }, - { - "address": "::0:0:0:0:0", - "conditions": [] - }, - { - "address": "::0:0:0:0:0:0", - "conditions": [] - }, - { - "address": "::0:0:0:0:0:0:0", - "conditions": [] - }, - { - "address": "::0:a:b:c:d:e:f", - "conditions": [] - }, - { - "address": "::1", - "conditions": [] - }, - { - "address": "::1/128", - "conditions": ["correct", "has-subnet"] - }, - { - "address": "::123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "::13.1.68.3", - "conditions": ["v4-in-v6"] - }, - { - "address": "::2222:3333:4444:5555:6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "::2222:3333:4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": "::2:3", - "conditions": [] - }, - { - "address": "::2:3:4", - "conditions": [] - }, - { - "address": "::2:3:4:5", - "conditions": [] - }, - { - "address": "::2:3:4:5:6", - "conditions": [] - }, - { - "address": "::2:3:4:5:6:7", - "conditions": [] - }, - { - "address": "::2:3:4:5:6:7:8", - "conditions": [] - }, - { - "address": "::3333:4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": "::4444:5555:6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "::4444:5555:6666:7777:8888", - "conditions": [] - }, - { - "address": "::5555:6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "::5555:6666:7777:8888", - "conditions": [] - }, - { - "address": "::6666:123.123.123.123", - "conditions": ["v4-in-v6"] - }, - { - "address": "::6666:7777:8888", - "conditions": [] - }, - { - "address": "::7777:8888", - "conditions": [] - }, - { - "address": "::8", - "conditions": [] - }, - { - "address": "::8888", - "conditions": [] - }, - { - "address": "::FFFF:129.144.52.38", - "conditions": ["v4-in-v6"] - }, - { - "address": "::ffff:0:0", - "conditions": [] - }, - { - "address": "::ffff:0c22:384e", - "conditions": [] - }, - { - "address": "::ffff:12.34.56.78", - "conditions": ["v4-in-v6"] - }, - { - "address": "::ffff:192.0.2.128", - "conditions": ["v4-in-v6"] - }, - { - "address": "::ffff:192.168.1.1", - "conditions": ["v4-in-v6"] - }, - { - "address": "::ffff:192.168.1.26", - "conditions": ["v4-in-v6"] - }, - { - "address": "::ffff:c000:280", - "conditions": [] - }, - { - "address": "FE80::/10", - "conditions": ["incorrect", "has-subnet"] - }, - { - "address": "FEC0::/10", - "conditions": ["incorrect", "has-subnet"] - }, - { - "address": "FF00::/8", - "conditions": ["incorrect", "has-subnet"] - }, - { - "address": "FF01:0:0:0:0:0:0:101", - "conditions": ["incorrect"] - }, - { - "address": "FF01::101", - "conditions": ["incorrect"] - }, - { - "address": "FF02:0000:0000:0000:0000:0000:0000:0001", - "conditions": ["incorrect"] - }, - { - "address": "a:b:c:d:e:f:0::", - "conditions": ["incorrect"] - }, - { - "address": "fe80:0000:0000:0000:0204:61ff:fe9d:f156", - "conditions": ["canonical"] - }, - { - "address": "fe80:0:0:0:204:61ff:254.157.241.86", - "conditions": ["v4-in-v6"] - }, - { - "address": "fe80:0:0:0:204:61ff:fe9d:f156", - "conditions": ["incorrect"] - }, - { - "address": "fe80::", - "conditions": ["correct"] - }, - { - "address": "fe80::1", - "conditions": ["correct"] - }, - { - "address": "fe80::204:61ff:254.157.241.86", - "conditions": ["v4-in-v6"] - }, - { - "address": "fe80::204:61ff:fe9d:f156", - "conditions": [] - }, - { - "address": "fe80::217:f2ff:254.7.237.98", - "conditions": ["v4-in-v6"] - }, - { - "address": "fe80::217:f2ff:fe07:ed62", - "conditions": ["correct"] - }, - { - "address": "fedc:ba98:7654:3210:fedc:ba98:7654:3210", - "conditions": ["correct", "canonical"] - }, - { - "address": "ff02::1", - "conditions": ["correct"] - }, - { - "address": "ffff::", - "conditions": ["correct"] - }, - { - "address": "ffff::3:5", - "conditions": ["correct"] - }, - { - "address": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", - "conditions": ["correct", "canonical"] - } -] diff --git a/node_modules/ipv6/test/functionality-v4-test.js b/node_modules/ipv6/test/functionality-v4-test.js deleted file mode 100644 index 2a84740..0000000 --- a/node_modules/ipv6/test/functionality-v4-test.js +++ /dev/null @@ -1,175 +0,0 @@ -var sprintf = require('sprintf').sprintf; -var should = require('chai').should(); - -var v4 = require('../ipv6').v4; - -// A convenience function to convert a list of IPv4 address notations -// to v4.Address instances -function notationsToAddresseses(notations) { - var addresses = []; - - notations.forEach(function (notation) { - addresses.push(new v4.Address(notation)); - }); - - return addresses; -} - -describe('v4', function () { - describe('A correct address', function () { - var topic = new v4.Address('127.0.0.1'); - - it('validates as correct', function () { - topic.isCorrect().should.equal(true); - - should.equal(topic.correctForm(), '127.0.0.1'); - }); - }); - - describe('An address with a subnet', function () { - var topic = new v4.Address('127.0.0.1/16'); - - it('is contained by an identical address with an identical subnet', - function () { - var same = new v4.Address('127.0.0.1/16'); - - topic.isInSubnet(same).should.equal(true); - }); - }); - - describe('A small subnet', function () { - var topic = new v4.Address('127.0.0.1/16'); - - it('is contained by larger subnets', function () { - for (var i = 15; i > 0; i--) { - var larger = new v4.Address(sprintf('127.0.0.1/%d', i)); - - topic.isInSubnet(larger).should.equal(true); - } - }); - }); - - describe('A large subnet', function () { - var topic = new v4.Address('127.0.0.1/8'); - - it('is not contained by smaller subnets', function () { - for (var i = 9; i <= 32; i++) { - var smaller = new v4.Address(sprintf('127.0.0.1/%d', i)); - - topic.isInSubnet(smaller).should.equal(false); - } - }); - }); - - describe('An integer v4 address', function () { - var topic = new v4.Address.fromInteger(432432423); - - it('validates', function () { - topic.isValid().should.equal(true); - }); - - it('parses correctly', function () { - topic.address.should.equal('25.198.101.39'); - - topic.subnet.should.equal('/32'); - topic.subnetMask.should.equal(32); - }); - - it('should match an address from its hex representation', function () { - var hex = v4.Address.fromHex('19c66527'); - - hex.address.should.equal('25.198.101.39'); - - hex.subnet.should.equal('/32'); - hex.subnetMask.should.equal(32); - }); - }); - - describe('An address with a subnet', function () { - var topic = new v4.Address('127.0.0.1/16'); - - it('validates', function () { - topic.isValid().should.equal(true); - }); - - it('parses the subnet', function () { - should.equal(topic.subnet, '/16'); - }); - - it('is in its own subnet', function () { - topic.isInSubnet(new v4.Address('127.0.0.1/16')).should.equal(true); - }); - - it('is not in another subnet', function () { - topic.isInSubnet(new v4.Address('192.168.0.1/16')).should.equal(false); - }); - }); - - describe('Creating an address from a BigInteger', function () { - var topic = v4.Address.fromBigInteger(2130706433); - - it('should parse correctly', function () { - topic.isValid().should.equal(true); - topic.correctForm().should.equal('127.0.0.1'); - }); - }); - - describe('Converting an address to a BigInteger', function () { - var topic = new v4.Address('127.0.0.1'); - - it('should convert properly', function () { - topic.bigInteger().intValue().should.equal(2130706433); - }); - }); - - describe('Creating an address from hex', function () { - var topic = v4.Address.fromHex('7f:00:00:01'); - - it('should parse correctly', function () { - topic.isValid().should.equal(true); - topic.correctForm().should.equal('127.0.0.1'); - }); - }); - - describe('Converting an address to hex', function () { - var topic = new v4.Address('127.0.0.1'); - - it('should convert correctly', function () { - topic.toHex().should.equal('7f:00:00:01'); - }); - }); - - describe('Converting an address to an array', function () { - var topic = new v4.Address('127.0.0.1'); - - it('should convert correctly', function () { - var a = topic.toArray(); - - a.should.be.an.instanceOf(Array).and.have.lengthOf(4); - - a[0].should.equal(127); - a[1].should.equal(0); - a[2].should.equal(0); - a[3].should.equal(1); - }); - }); - - describe('A different notation of the same address', function () { - var addresses = notationsToAddresseses([ - "127.0.0.1/32", - "127.0.0.1/032", - "127.000.000.001/032", - "127.000.000.001/32", - "127.0.0.1", - "127.000.000.001", - "127.000.0.1" - ]); - - it('is parsed to the same result', function () { - addresses.forEach(function (topic) { - should.equal(topic.correctForm(), '127.0.0.1'); - should.equal(topic.subnetMask, 32); - }); - }); - }); -}); diff --git a/node_modules/ipv6/test/functionality-v6-test.js b/node_modules/ipv6/test/functionality-v6-test.js deleted file mode 100644 index fd5f95a..0000000 --- a/node_modules/ipv6/test/functionality-v6-test.js +++ /dev/null @@ -1,257 +0,0 @@ -var sprintf = require('sprintf').sprintf; -var chai = require('chai'); -var should = chai.should(); -var expect = chai.expect; - -var v6 = require('../ipv6').v6; - -// A convenience function to convert a list of IPv6 address notations -// to v6.Address instances -function notationsToAddresseses(notations) { - var addresses = []; - - notations.forEach(function (notation) { - addresses.push(new v6.Address(notation)); - }); - - return addresses; -} - -describe('v6', function () { - describe('A correct address', function () { - var topic = new v6.Address('a::b'); - - it('contains no uppercase letters', function () { - /[A-Z]/.test(topic.address).should.equal(false); - }); - - it('validates as correct', function () { - topic.isCorrect().should.equal(true); - - should.equal(topic.correctForm(), 'a::b'); - }); - }); - - describe('An address with a subnet', function () { - var topic = new v6.Address('ffff::/64'); - - it('is contained by an identical address with an identical subnet', - function () { - var same = new v6.Address('ffff::/64'); - - topic.isInSubnet(same).should.equal(true); - }); - }); - - describe('Small subnets', function () { - var topic = new v6.Address('ffff::/64'); - - it('is contained by larger subnets', function () { - for (var i = 63; i > 0; i--) { - var larger = new v6.Address(sprintf('ffff::/%d', i)); - - topic.isInSubnet(larger).should.equal(true); - } - }); - }); - - describe('Large subnets', function () { - var topic = new v6.Address('ffff::/8'); - - it('is not contained by smaller subnets', function () { - for (var i = 9; i <= 128; i++) { - var smaller = new v6.Address(sprintf('ffff::/%d', i)); - - topic.isInSubnet(smaller).should.equal(false); - } - }); - }); - - describe('A canonical address', function () { - var topic = new v6.Address('000a:0000:0000:0000:0000:0000:0000:000b'); - - it('is 39 characters long', function () { - should.equal(topic.address.length, 39); - }); - - it('validates as canonical', function () { - topic.isCanonical().should.equal(true); - - should.equal(topic.canonicalForm(), - '000a:0000:0000:0000:0000:0000:0000:000b'); - }); - }); - - describe('A v4-in-v6 address', function () { - var topic = new v6.Address('::192.168.0.1'); - - it('validates', function () { - topic.isValid().should.equal(true); - }); - - it('is v4', function () { - topic.is4().should.equal(true); - }); - }); - - describe('An address with a subnet', function () { - var topic = new v6.Address('a:b::/48'); - - it('validates', function () { - topic.isValid().should.equal(true); - }); - - it('parses the subnet', function () { - should.equal(topic.subnet, '/48'); - }); - - it('is in its own subnet', function () { - topic.isInSubnet(new v6.Address('a:b::/48')).should.equal(true); - }); - - it('is not in another subnet', function () { - topic.isInSubnet(new v6.Address('a:c::/48')).should.equal(false); - }); - }); - - describe('An address with a zone', function () { - var topic = new v6.Address('a::b%abcdefg'); - - it('validates', function () { - topic.isValid().should.equal(true); - }); - - it('parses the zone', function () { - should.equal(topic.zone, '%abcdefg'); - }); - }); - - describe('A teredo address', function () { - var topic = new v6.Address('2001:0000:ce49:7601:e866:efff:62c3:fffe'); - - it('validates as Teredo', function () { - topic.isTeredo().should.equal(true); - }); - - it('contains valid Teredo information', function () { - var teredo = topic.teredo(); - - should.equal(teredo.prefix, '2001:0000'); - should.equal(teredo.server4, '206.73.118.1'); - should.equal(teredo.flags, '1110100001100110'); - should.equal(teredo.udpPort, '4096'); - should.equal(teredo.client4, '157.60.0.1'); - }); - }); - - describe('A 6to4 address', function () { - var topic = new v6.Address('2002:ce49:7601:1:2de:adff:febe:eeef'); - - it('validates as 6to4', function () { - topic.is6to4().should.equal(true); - }); - - it('contains valid 6to4 information', function () { - var six2four = topic.six2four(); - - should.equal(six2four.prefix, '2002'); - should.equal(six2four.gateway, '206.73.118.1'); - }); - }); - - describe('A different notation of the same address', function () { - var addresses = notationsToAddresseses([ - "2001:db8:0:0:1:0:0:1/128", - "2001:db8:0:0:1:0:0:1/128%eth0", - "2001:db8:0:0:1:0:0:1%eth0", - "2001:db8:0:0:1:0:0:1", - "2001:0db8:0:0:1:0:0:1", - "2001:db8::1:0:0:1", - "2001:db8::0:1:0:0:1", - "2001:0db8::1:0:0:1", - "2001:db8:0:0:1::1", - "2001:db8:0000:0:1::1", - "2001:DB8:0:0:1::1" - ]); - - it('is parsed to the same result', function () { - addresses.forEach(function (topic) { - should.equal(topic.correctForm(), '2001:db8::1:0:0:1'); - should.equal(topic.canonicalForm(), - '2001:0db8:0000:0000:0001:0000:0000:0001'); - should.equal(topic.v4inv6(), '2001:db8::1:0:0.0.0.1'); - should.equal(topic.decimal(), - '08193:03512:00000:00000:00001:00000:00000:00001'); - should.equal(topic.binaryZeroPad(), - '0010000000000001000011011011100000000000000000000000000000000000' + - '0000000000000001000000000000000000000000000000000000000000000001'); - }); - }); - }); - - describe('Address inside a URL or inside a URL with a port', function () { - it('should work with a host address', function () { - var obj = v6.Address.fromURL('2001:db8::5'); - - expect(obj.address.valid).to.equal(true); - expect(obj.address.address).to.equal('2001:db8::5'); - expect(obj.port).to.equal(null); - }); - - it('should work with a basic URL', function () { - var obj = v6.Address.fromURL('http://2001:db8::5/foo'); - - expect(obj.address.isValid()).to.equal(true); - expect(obj.address.address).equal('2001:db8::5'); - expect(obj.port).to.equal(null); - }); - - it('should work with a URL with a port', function () { - var obj = v6.Address.fromURL('http://[2001:db8::5]:80/foo'); - - expect(obj.address.isValid()).to.equal(true); - expect(obj.address.address).to.equal('2001:db8::5'); - expect(obj.port).to.equal(80); - }); - - it('should work with a URL with a long port number', function () { - var obj = v6.Address.fromURL('http://[2001:db8::5]:65536/foo'); - - expect(obj.address.isValid()).to.equal(true); - expect(obj.address.address).to.equal('2001:db8::5'); - expect(obj.port).to.equal(65536); - }); - - it('should work with a address with a port', function () { - var obj = v6.Address.fromURL('[2001:db8::5]:80'); - - expect(obj.address.isValid()).to.equal(true); - expect(obj.address.address).to.equal('2001:db8::5'); - expect(obj.port).to.equal(80); - }); - - it('should work with a address with a long port', function () { - var obj = v6.Address.fromURL('[2001:db8::5]:65536'); - - expect(obj.address.isValid()).to.equal(true); - expect(obj.address.address).to.equal('2001:db8::5'); - expect(obj.port).to.equal(65536); - }); - - it('should parse the address but fail with an invalid port', function () { - var obj = v6.Address.fromURL('[2001:db8::5]:65537'); - - expect(obj.address.isValid()).to.equal(true); - expect(obj.address.address).to.equal('2001:db8::5'); - expect(obj.port).to.equal(null); - }); - - it('should fail with an invalid address and not return a port', - function () { - var obj = v6.Address.fromURL('[2001:db8:z:5]:65536'); - - expect(obj.error).to.equal('failed to parse address with port'); - expect(obj.port).to.equal(null); - }); - }); -}); diff --git a/node_modules/ipv6/test/unused/grep-test.txt b/node_modules/ipv6/test/unused/grep-test.txt deleted file mode 100644 index 74cb5ef..0000000 --- a/node_modules/ipv6/test/unused/grep-test.txt +++ /dev/null @@ -1,17 +0,0 @@ -a::b -a::b2 -a::b testing -http://[a::b]:80 testing -a::b2 testing2 -000a::000b -b::c -b::c2 -a:0:0:0:0:0:0:b -2001:db8:0:0:1:0:0:1 -2001:0db8:0:0:1:0:0:1 -2001:db8::1:0:0:1 -2001:db8::0:1:0:0:1 -2001:0db8::1:0:0:1 -2001:db8:0:0:1::1 -2001:db8:0000:0:1::1 -2001:DB8:0:0:1::1 diff --git a/node_modules/ipv6/test/unused/regex-test.js b/node_modules/ipv6/test/unused/regex-test.js deleted file mode 100644 index 879644b..0000000 --- a/node_modules/ipv6/test/unused/regex-test.js +++ /dev/null @@ -1,21 +0,0 @@ -var fs = require('fs'), - sprintf = require('sprintf').sprintf; - -var v6 = require('../ipv6').v6, - BigInteger = require('../lib/node/bigint'); - -var a = new v6.Address('::'); -var b = new v6.Address('a:b:c:d::'); - -console.log(a.regularExpressionString()); -console.log(b.regularExpressionString()); - -var ar = new RegExp(a.regularExpressionString()); -var br = new RegExp(a.regularExpressionString()); - -console.log(ar.test('::')); -console.log(ar.test('0:0:0:0:0:0:0:0')); - -console.log(br.test('a:b:c:d::')); -console.log(br.test('a:b:c:d:0000:0000:0000:0000')); -console.log(br.test('a:b:c:d:0:0:0:0')); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..fcafc4d --- /dev/null +++ b/package-lock.json @@ -0,0 +1,14 @@ +{ + "name": "socks-v5", + "version": "0.0.6", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/node": { + "version": "10.7.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.7.1.tgz", + "integrity": "sha512-EGoI4ylB/lPOaqXqtzAyL8HcgOuCtH2hkEaLmkueOYufsTFWBn4VCvlCDC2HW8Q+9iF+QVC3sxjDKQYjHQeZ9w==", + "dev": true + } + } +} diff --git a/package.json b/package.json index a007dc1..d431851 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,36 @@ -{ "name": "socksv5", +{ + "name": "socksv5", "version": "0.0.6", "author": "Brian White ", "description": "SOCKS protocol version 5 server and client implementations for node.js", - "main": "./index", + "main": "./index.js", + "types": "./index.d.ts", "scripts": { "test": "node test/test.js" }, - "dependencies": { - "ipv6": "*" + "engines": { + "node": ">=0.10.0" }, - "bundledDependencies": [ - "ipv6" + "keywords": [ + "socks", + "socks5", + "socksv5", + "proxy" + ], + "licenses": [ + { + "type": "MIT", + "url": "http://github.com/mscdex/socksv5/raw/master/LICENSE" + } ], - "engines": { "node": ">=0.10.0" }, - "keywords": [ "socks", "socks5", "socksv5", "proxy" ], - "licenses": [ { "type": "MIT", "url": "http://github.com/mscdex/socksv5/raw/master/LICENSE" } ], - "repository" : { "type": "git", "url": "http://github.com/mscdex/socksv5.git" } + "repository": { + "type": "git", + "url": "http://github.com/mscdex/socksv5.git" + }, + "dependencies": { + "ip-address": "^5.8.9" + }, + "devDependencies": { + "@types/node": "^10.7.1" + } } diff --git a/test/test-client-parser.js b/test/test-client-parser.js index d862fc3..0870bb2 100644 --- a/test/test-client-parser.js +++ b/test/test-client-parser.js @@ -21,7 +21,7 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05, 0xFF])); + stream.emit('data', Buffer.from([0x05, 0xFF])); assert(method === 0xFF, makeMsg(what, 'Unexpected method: ' + method)); next(); @@ -40,8 +40,8 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05])); - stream.emit('data', new Buffer([0x09])); + stream.emit('data', Buffer.from([0x05])); + stream.emit('data', Buffer.from([0x09])); assert(method === 0x09, makeMsg(what, 'Unexpected method: ' + method)); next(); @@ -60,7 +60,7 @@ var tests = [ }).on('error', function(err) { errors.push(err); }); - stream.emit('data', new Buffer([0x04, 0x09])); + stream.emit('data', Buffer.from([0x04, 0x09])); assert(errors.length === 1 && /Incompatible SOCKS protocol version: 4/i.test(errors[0].message), makeMsg(what, 'Error(s) mismatch')); @@ -81,7 +81,7 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05, + stream.emit('data', Buffer.from([0x05, 0x00, 0x00, 0x01, @@ -107,7 +107,7 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05, + stream.emit('data', Buffer.from([0x05, 0x00, 0x00, 0x04, @@ -136,7 +136,7 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05, + stream.emit('data', Buffer.from([0x05, 0x00, 0x00, 0x03, @@ -164,11 +164,11 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05, 0x00])); - stream.emit('data', new Buffer([0x00, 0x03, 0x0A, 0x6E, 0x6F, 0x64, 0x65])); - stream.emit('data', new Buffer([0x6A, 0x73, 0x2E, 0x6F, 0x72])); - stream.emit('data', new Buffer([0x67, 0x05])); - stream.emit('data', new Buffer([0x39])); + stream.emit('data', Buffer.from([0x05, 0x00])); + stream.emit('data', Buffer.from([0x00, 0x03, 0x0A, 0x6E, 0x6F, 0x64, 0x65])); + stream.emit('data', Buffer.from([0x6A, 0x73, 0x2E, 0x6F, 0x72])); + stream.emit('data', Buffer.from([0x67, 0x05])); + stream.emit('data', Buffer.from([0x39])); assert.deepEqual(reply, { bndAddr: 'nodejs.org', bndPort: 1337 }, @@ -190,7 +190,7 @@ var tests = [ }).on('error', function(err) { errors.push(err); }); - stream.emit('data', new Buffer([0x05, 0x02])); + stream.emit('data', Buffer.from([0x05, 0x02])); assert(errors.length === 1 && /connection not allowed by ruleset/i.test(errors[0].message), makeMsg(what, 'Error(s) mismatch')); @@ -211,7 +211,7 @@ var tests = [ }).on('error', function(err) { errors.push(err); }); - stream.emit('data', new Buffer([0x04, 0x02])); + stream.emit('data', Buffer.from([0x04, 0x02])); assert(errors.length === 1 && /Incompatible SOCKS protocol version: 4/i.test(errors[0].message), makeMsg(what, 'Error(s) mismatch')); @@ -232,11 +232,11 @@ var tests = [ }).on('error', function(err) { errors.push(err); }); - stream.emit('data', new Buffer([0x05, 0x00])); - stream.emit('data', new Buffer([0x00, 0xFF, 0x0A, 0x6E, 0x6F, 0x64, 0x65])); - stream.emit('data', new Buffer([0x6A, 0x73, 0x2E, 0x6F, 0x72])); - stream.emit('data', new Buffer([0x67, 0x05])); - stream.emit('data', new Buffer([0x39])); + stream.emit('data', Buffer.from([0x05, 0x00])); + stream.emit('data', Buffer.from([0x00, 0xFF, 0x0A, 0x6E, 0x6F, 0x64, 0x65])); + stream.emit('data', Buffer.from([0x6A, 0x73, 0x2E, 0x6F, 0x72])); + stream.emit('data', Buffer.from([0x67, 0x05])); + stream.emit('data', Buffer.from([0x39])); assert(errors.length === 1 && /Invalid request address type: 255/i.test(errors[0].message), makeMsg(what, 'Error(s) mismatch')); diff --git a/test/test-server-parser.js b/test/test-server-parser.js index b2ca7be..c1e6a9c 100644 --- a/test/test-server-parser.js +++ b/test/test-server-parser.js @@ -22,9 +22,9 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05, 0x01, 0x00])); + stream.emit('data', Buffer.from([0x05, 0x01, 0x00])); assert.deepEqual(methods, - new Buffer([0x00]), + Buffer.from([0x00]), makeMsg(what, 'Unexpected methods: ' + inspect(methods))); next(); }, @@ -42,11 +42,11 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05])); - stream.emit('data', new Buffer([0x01])); - stream.emit('data', new Buffer([0x00])); + stream.emit('data', Buffer.from([0x05])); + stream.emit('data', Buffer.from([0x01])); + stream.emit('data', Buffer.from([0x00])); assert.deepEqual(methods, - new Buffer([0x00]), + Buffer.from([0x00]), makeMsg(what, 'Unexpected methods: ' + inspect(methods))); next(); }, @@ -64,7 +64,7 @@ var tests = [ }).on('error', function(err) { errors.push(err); }); - stream.emit('data', new Buffer([0x04, 0x01, 0x00])); + stream.emit('data', Buffer.from([0x04, 0x01, 0x00])); assert(errors.length === 1 && /Incompatible SOCKS protocol version: 4/i.test(errors[0].message), makeMsg(what, 'Error(s) mismatch')); @@ -84,7 +84,7 @@ var tests = [ }).on('error', function(err) { errors.push(err); }); - stream.emit('data', new Buffer([0x05, 0x00])); + stream.emit('data', Buffer.from([0x05, 0x00])); assert(errors.length === 1 && /empty methods list/i.test(errors[0].message), makeMsg(what, 'Error(s) mismatch')); @@ -105,7 +105,7 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05, + stream.emit('data', Buffer.from([0x05, 0x01, 0x00, 0x01, @@ -135,7 +135,7 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05, + stream.emit('data', Buffer.from([0x05, 0x02, 0x00, 0x01, @@ -165,7 +165,7 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05, + stream.emit('data', Buffer.from([0x05, 0x03, 0x00, 0x01, @@ -195,7 +195,7 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05, + stream.emit('data', Buffer.from([0x05, 0x01, 0x00, 0x04, @@ -228,7 +228,7 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05, + stream.emit('data', Buffer.from([0x05, 0x01, 0x00, 0x03, @@ -259,14 +259,14 @@ var tests = [ }).on('error', function(err) { assert(false, makeMsg(what, 'Unexpected error: ' + err)); }); - stream.emit('data', new Buffer([0x05])); - stream.emit('data', new Buffer([0x01, 0x00, 0x03])); - stream.emit('data', new Buffer([0x0A])); - stream.emit('data', new Buffer([0x6E, 0x6F, 0x64, 0x65, 0x6A, 0x73])); - stream.emit('data', new Buffer([0x2E, 0x6F, 0x72])); - stream.emit('data', new Buffer([0x67])); - stream.emit('data', new Buffer([0x05])); - stream.emit('data', new Buffer([0x39])); + stream.emit('data', Buffer.from([0x05])); + stream.emit('data', Buffer.from([0x01, 0x00, 0x03])); + stream.emit('data', Buffer.from([0x0A])); + stream.emit('data', Buffer.from([0x6E, 0x6F, 0x64, 0x65, 0x6A, 0x73])); + stream.emit('data', Buffer.from([0x2E, 0x6F, 0x72])); + stream.emit('data', Buffer.from([0x67])); + stream.emit('data', Buffer.from([0x05])); + stream.emit('data', Buffer.from([0x39])); assert.deepEqual(request, { cmd: 'connect', srcAddr: undefined, @@ -291,7 +291,7 @@ var tests = [ }).on('error', function(err) { errors.push(err); }); - stream.emit('data', new Buffer([0x04, + stream.emit('data', Buffer.from([0x04, 0x01, 0x00, 0x01, @@ -317,7 +317,7 @@ var tests = [ }).on('error', function(err) { errors.push(err); }); - stream.emit('data', new Buffer([0x05, + stream.emit('data', Buffer.from([0x05, 0xFE, 0x00, 0x01, @@ -343,7 +343,7 @@ var tests = [ }).on('error', function(err) { errors.push(err); }); - stream.emit('data', new Buffer([0x05, + stream.emit('data', Buffer.from([0x05, 0x01, 0x00, 0xFF, diff --git a/test/test-server.js b/test/test-server.js index ebf17c0..1c13444 100644 --- a/test/test-server.js +++ b/test/test-server.js @@ -286,7 +286,7 @@ var tests = [ makeMsg(what, 'Timeout while waiting for bad client socket end')); }, 100); - clientSock.write(new Buffer([0x04, 0x01, 0x00])); + clientSock.write(Buffer.from([0x04, 0x01, 0x00])); }).connect(this.address().port, 'localhost'); }); }, From c11e14e4b733f1c0093c2fca9a7e78a5c3838dd8 Mon Sep 17 00:00:00 2001 From: phoenix344 <37783181+phoenix344@users.noreply.github.com> Date: Mon, 20 Aug 2018 00:46:20 +0200 Subject: [PATCH 2/9] updated readme nodejs version only tested on v10.x --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0db1e69..cd098b0 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ SOCKS protocol version 5 server and client implementations for node.js Requirements ============ -* [node.js](http://nodejs.org/) -- v0.10.0 or newer +* [node.js](http://nodejs.org/) -- v10.x or newer Install From 10b67813b166096e21b782b60cd8ffa95ea9ee37 Mon Sep 17 00:00:00 2001 From: EntropyFBC49934 Date: Fri, 24 Aug 2018 18:47:45 +0200 Subject: [PATCH 3/9] update declaration file and change package name --- index.d.ts | 6 +++++- package.json | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 5d719d4..1946516 100644 --- a/index.d.ts +++ b/index.d.ts @@ -279,8 +279,12 @@ declare module "socksv5/lib/server" { (intercept: true): Socket; } + export interface SocksDenyCallback { + (): void; + } + export interface SocksConnectionCallback { - (info: SocksProxyInfo, accept: SocksAcceptCallback, deny: () => void); + (info: SocksProxyInfo, accept: SocksAcceptCallback, deny: SocksDenyCallback); } export interface SocksServerOptions { diff --git a/package.json b/package.json index d431851..cbcd89e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "socksv5", - "version": "0.0.6", + "name": "@outtacontrol/socks", + "version": "1.0.0", "author": "Brian White ", "description": "SOCKS protocol version 5 server and client implementations for node.js", "main": "./index.js", From d363ccb51c34601ab49acf3298444225276cdcd2 Mon Sep 17 00:00:00 2001 From: EntropyFBC49934 Date: Fri, 24 Aug 2018 18:51:10 +0200 Subject: [PATCH 4/9] update name in readme --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cd098b0..af31817 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Requirements Install ======= - npm install socksv5 + npm install @outtacontrol/socks Examples @@ -22,7 +22,7 @@ Examples * Server with no authentication and allowing all connections: ```javascript -var socks = require('socksv5'); +var socks = require('@outtacontrol/socks'); var srv = socks.createServer(function(info, accept, deny) { accept(); @@ -37,7 +37,7 @@ srv.useAuth(socks.auth.None()); * Server with username/password authentication and allowing all (authenticated) connections: ```javascript -var socks = require('socksv5'); +var socks = require('@outtacontrol/socks'); var srv = socks.createServer(function(info, accept, deny) { accept(); @@ -54,7 +54,7 @@ srv.useAuth(socks.auth.UserPassword(function(user, password, cb) { * Server with no authentication and redirecting all connections to localhost: ```javascript -var socks = require('socksv5'); +var socks = require('@outtacontrol/socks'); var srv = socks.createServer(function(info, accept, deny) { info.dstAddr = 'localhost'; @@ -70,7 +70,7 @@ srv.useAuth(socks.auth.None()); * Server with no authentication and denying all connections not made to port 80: ```javascript -var socks = require('socksv5'); +var socks = require('@outtacontrol/socks'); var srv = socks.createServer(function(info, accept, deny) { if (info.dstPort === 80) @@ -88,7 +88,7 @@ srv.useAuth(socks.auth.None()); * Server with no authentication, intercepting all connections to port 80, and passing through all others: ```javascript -var socks = require('socksv5'); +var socks = require('@outtacontrol/socks'); var srv = socks.createServer(function(info, accept, deny) { if (info.dstPort === 80) { @@ -117,7 +117,7 @@ srv.useAuth(socks.auth.None()); * Client with no authentication: ```javascript -var socks = require('socksv5'); +var socks = require('@outtacontrol/socks'); var client = socks.connect({ host: 'google.com', @@ -135,7 +135,7 @@ var client = socks.connect({ * HTTP(s) client requests using a SOCKS Agent: ```javascript -var socks = require('socksv5'); +var socks = require('@outtacontrol/socks'); var http = require('http'); var socksConfig = { From 3586ac407b3c6718b9b22bb90676f35d022e31c6 Mon Sep 17 00:00:00 2001 From: EntropyFBC49934 Date: Fri, 24 Aug 2018 18:58:32 +0200 Subject: [PATCH 5/9] fix name for declaration file --- index.d.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index.d.ts b/index.d.ts index 1946516..bb47a9d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,5 @@ -declare module "socksv5/lib/Agents" { +declare module "@outtacontrol/socks/lib/Agents" { import { EventEmitter } from "events"; import { Client, createConnection } from "socksv5/lib/client"; @@ -71,7 +71,7 @@ declare module "socksv5/lib/Agents" { export class HttpsAgent extends Agent { } } -declare module "socksv5/lib/auth" { +declare module "@outtacontrol/socks/lib/auth" { import { Socket } from "net"; export interface AuthCallback { @@ -85,12 +85,12 @@ declare module "socksv5/lib/auth" { } } -declare module "socksv5/lib/auth/None" { +declare module "@outtacontrol/socks/lib/auth/None" { import { Auth } from "socksv5/lib/auth"; export default function None(): Auth; } -declare module "socksv5/lib/auth/UserPassword" { +declare module "@outtacontrol/socks/lib/auth/UserPassword" { import { Auth } from "socksv5/lib/auth"; export interface DoneCallback { @@ -105,7 +105,7 @@ declare module "socksv5/lib/auth/UserPassword" { export default function UserPassword(authCallback: AuthCallback): Auth; } -declare module "socksv5/lib/client" { +declare module "@outtacontrol/socks/lib/client" { import { EventEmitter } from "events"; export interface SocksClientOptions { @@ -195,7 +195,7 @@ declare module "socksv5/lib/client" { export function createConnection(path: string, listener?: () => void): Client; } -declare module "socksv5/lib/client.parser" { +declare module "@outtacontrol/socks/lib/client.parser" { import { Socket } from "net"; import { EventEmitter } from "events"; import { SocksBoundAddress, SocksProxyInfo } from "socksv5"; @@ -237,7 +237,7 @@ declare module "socksv5/lib/client.parser" { } } -declare module "socksv5/lib/constants" { +declare module "@outtacontrol/socks/lib/constants" { interface SocksCMD { CONNECT: number; @@ -268,7 +268,7 @@ declare module "socksv5/lib/constants" { export const REP: SocksREP; } -declare module "socksv5/lib/server" { +declare module "@outtacontrol/socks/lib/server" { import { EventEmitter } from "events"; import { Auth } from "socksv5/lib/auth"; import { Socket, AddressInfo } from "net"; @@ -352,7 +352,7 @@ declare module "socksv5/lib/server" { export function createServer(options: SocksServerOptions, connectionListener: SocksConnectionCallback): Server; } -declare module "socksv5/lib/server.parser" { +declare module "@outtacontrol/socks/lib/server.parser" { import { Socket } from "net"; import { SocksProxyInfo, SocksBoundAddress } from "socksv5"; export default class Parser { @@ -392,7 +392,7 @@ declare module "socksv5/lib/server.parser" { } } -declare module "socksv5" { +declare module "@outtacontrol/socks" { import None from "socksv5/lib/auth/None"; import UserPassword from "socksv5/lib/auth/UserPassword"; From 7e46add2f42c4d3d6f4c04d0b4db9998815ab124 Mon Sep 17 00:00:00 2001 From: EntropyFBC49934 Date: Fri, 24 Aug 2018 18:59:49 +0200 Subject: [PATCH 6/9] update names for imports inside of the declaration file --- index.d.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/index.d.ts b/index.d.ts index bb47a9d..bd11eaf 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,7 +1,7 @@ declare module "@outtacontrol/socks/lib/Agents" { import { EventEmitter } from "events"; - import { Client, createConnection } from "socksv5/lib/client"; + import { Client, createConnection } from "@outtacontrol/socks/lib/client"; export interface SocksAgentOptions { /** @@ -86,12 +86,12 @@ declare module "@outtacontrol/socks/lib/auth" { } declare module "@outtacontrol/socks/lib/auth/None" { - import { Auth } from "socksv5/lib/auth"; + import { Auth } from "@outtacontrol/socks/lib/auth"; export default function None(): Auth; } declare module "@outtacontrol/socks/lib/auth/UserPassword" { - import { Auth } from "socksv5/lib/auth"; + import { Auth } from "@outtacontrol/socks/lib/auth"; export interface DoneCallback { (success: boolean): void; @@ -198,7 +198,7 @@ declare module "@outtacontrol/socks/lib/client" { declare module "@outtacontrol/socks/lib/client.parser" { import { Socket } from "net"; import { EventEmitter } from "events"; - import { SocksBoundAddress, SocksProxyInfo } from "socksv5"; + import { SocksBoundAddress, SocksProxyInfo } from "@outtacontrol/socks"; export default class Parser extends EventEmitter { constructor(stream: Socket); @@ -270,9 +270,9 @@ declare module "@outtacontrol/socks/lib/constants" { declare module "@outtacontrol/socks/lib/server" { import { EventEmitter } from "events"; - import { Auth } from "socksv5/lib/auth"; + import { Auth } from "@outtacontrol/socks/lib/auth"; import { Socket, AddressInfo } from "net"; - import { SocksProxyInfo } from "socksv5"; + import { SocksProxyInfo } from "@outtacontrol/socks"; export interface SocksAcceptCallback { (intercept?: false): void; @@ -354,7 +354,7 @@ declare module "@outtacontrol/socks/lib/server" { declare module "@outtacontrol/socks/lib/server.parser" { import { Socket } from "net"; - import { SocksProxyInfo, SocksBoundAddress } from "socksv5"; + import { SocksProxyInfo, SocksBoundAddress } from "@outtacontrol/socks"; export default class Parser { constructor(stream: Socket); start(): void; @@ -393,8 +393,8 @@ declare module "@outtacontrol/socks/lib/server.parser" { } declare module "@outtacontrol/socks" { - import None from "socksv5/lib/auth/None"; - import UserPassword from "socksv5/lib/auth/UserPassword"; + import None from "@outtacontrol/socks/lib/auth/None"; + import UserPassword from "@outtacontrol/socks/lib/auth/UserPassword"; export interface SocksBoundAddress { bndAddr: string; @@ -409,9 +409,9 @@ declare module "@outtacontrol/socks" { dstPort: number; } - export * from "socksv5/lib/Agents"; - export * from "socksv5/lib/client"; - export * from "socksv5/lib/server"; + export * from "@outtacontrol/socks/lib/Agents"; + export * from "@outtacontrol/socks/lib/client"; + export * from "@outtacontrol/socks/lib/server"; export const auth: { None, UserPassword }; } \ No newline at end of file From 64dfa9bdcf7f48ec940d055b392ff35cf6491c3b Mon Sep 17 00:00:00 2001 From: EntropyFBC49934 Date: Fri, 24 Aug 2018 19:00:17 +0200 Subject: [PATCH 7/9] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cbcd89e..d95a6b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@outtacontrol/socks", - "version": "1.0.0", + "version": "1.0.1", "author": "Brian White ", "description": "SOCKS protocol version 5 server and client implementations for node.js", "main": "./index.js", From 34e0e22ac384b32040164a59513ff4eb32e089c3 Mon Sep 17 00:00:00 2001 From: EntropyFBC49934 Date: Fri, 24 Aug 2018 20:27:07 +0200 Subject: [PATCH 8/9] refactoring --- .vscode/launch.json | 15 +++++++ index.d.ts | 87 ++++++++++++++++++++-------------------- index.js | 25 ++++++------ lib/auth.js | 5 +++ lib/auth/None.js | 2 +- lib/auth/UserPassword.js | 2 +- package.json | 2 +- 7 files changed, 80 insertions(+), 58 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 lib/auth.js diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c139bce --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Verwendet IntelliSense zum Ermitteln möglicher Attribute. + // Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen. + // Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Start Test", + "program": "${workspaceFolder}/test/test.js", + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index bd11eaf..66b13b8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,6 +2,8 @@ declare module "@outtacontrol/socks/lib/Agents" { import { EventEmitter } from "events"; import { Client, createConnection } from "@outtacontrol/socks/lib/client"; + import { Socket } from "net"; + import { ClientRequest, ClientRequestArgs } from "http"; export interface SocksAgentOptions { /** @@ -61,9 +63,9 @@ declare module "@outtacontrol/socks/lib/Agents" { getName(options?: SocksAgentNameOptions): string; - addRequest(req, options?: SocksAgentNameOptions): void; - createSocket(req, options): Client; - removeSocket(socket, options): void; + addRequest(req: ClientRequest, options?: SocksAgentNameOptions): void; + createSocket(req: ClientRequest, options?: ClientRequestArgs): Client; + removeSocket(socket: Socket, options?: ClientRequestArgs): void; destroy(): void; } @@ -74,6 +76,9 @@ declare module "@outtacontrol/socks/lib/Agents" { declare module "@outtacontrol/socks/lib/auth" { import { Socket } from "net"; + export { None } from "@outtacontrol/socks/lib/auth/None"; + export { UserPassword } from "@outtacontrol/socks/lib/auth/UserPassword"; + export interface AuthCallback { (done: boolean): void; (error: Error): void; @@ -87,7 +92,7 @@ declare module "@outtacontrol/socks/lib/auth" { declare module "@outtacontrol/socks/lib/auth/None" { import { Auth } from "@outtacontrol/socks/lib/auth"; - export default function None(): Auth; + export function None(): Auth; } declare module "@outtacontrol/socks/lib/auth/UserPassword" { @@ -101,8 +106,8 @@ declare module "@outtacontrol/socks/lib/auth/UserPassword" { (username: string, password: string, callback: DoneCallback): void; } - export default function UserPassword(username: string, password: string): Auth; - export default function UserPassword(authCallback: AuthCallback): Auth; + export function UserPassword(username: string, password: string): Auth; + export function UserPassword(authCallback: AuthCallback): Auth; } declare module "@outtacontrol/socks/lib/client" { @@ -206,9 +211,9 @@ declare module "@outtacontrol/socks/lib/client.parser" { stop(): void; addListener(event: string, listener: (...args: any[]) => void): this; - addListener(event: "method", listener: (method: number) => void); - addListener(event: "reply", listener: (info: SocksBoundAddress) => void); - addListener(event: "error", listener: (err: Error) => void); + addListener(event: "method", listener: (method: number) => void): this; + addListener(event: "reply", listener: (info: SocksBoundAddress) => void): this; + addListener(event: "error", listener: (err: Error) => void): this; emit(event: string | symbol, ...args: any[]): boolean; emit(event: "method", method: number): boolean; @@ -216,24 +221,24 @@ declare module "@outtacontrol/socks/lib/client.parser" { emit(event: "error", err: Error): boolean; on(event: string, listener: (...args: any[]) => void): this; - on(event: "method", listener: (method: number) => void); - on(event: "reply", listener: (info: SocksBoundAddress) => void); - on(event: "error", listener: (err: Error) => void); + on(event: "method", listener: (method: number) => void): this; + on(event: "reply", listener: (info: SocksBoundAddress) => void): this; + on(event: "error", listener: (err: Error) => void): this; once(event: string, listener: (...args: any[]) => void): this; - once(event: "method", listener: (method: number) => void); - once(event: "reply", listener: (info: SocksBoundAddress) => void); - once(event: "error", listener: (err: Error) => void); + once(event: "method", listener: (method: number) => void): this; + once(event: "reply", listener: (info: SocksBoundAddress) => void): this; + once(event: "error", listener: (err: Error) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; - prependListener(event: "method", listener: (method: number) => void); - prependListener(event: "reply", listener: (info: SocksBoundAddress) => void); - prependListener(event: "error", listener: (err: Error) => void); + prependListener(event: "method", listener: (method: number) => void): this; + prependListener(event: "reply", listener: (info: SocksBoundAddress) => void): this; + prependListener(event: "error", listener: (err: Error) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; - prependOnceListener(event: "method", listener: (method: number) => void); - prependOnceListener(event: "reply", listener: (info: SocksBoundAddress) => void); - prependOnceListener(event: "error", listener: (err: Error) => void); + prependOnceListener(event: "method", listener: (method: number) => void): this; + prependOnceListener(event: "reply", listener: (info: SocksBoundAddress) => void): this; + prependOnceListener(event: "error", listener: (err: Error) => void): this; } } @@ -284,7 +289,7 @@ declare module "@outtacontrol/socks/lib/server" { } export interface SocksConnectionCallback { - (info: SocksProxyInfo, accept: SocksAcceptCallback, deny: SocksDenyCallback); + (info: SocksProxyInfo, accept: SocksAcceptCallback, deny: SocksDenyCallback): void; } export interface SocksServerOptions { @@ -361,9 +366,9 @@ declare module "@outtacontrol/socks/lib/server.parser" { stop(): void; addListener(event: string, listener: (...args: any[]) => void): this; - addListener(event: "methods", listener: (methods: Buffer) => void); - addListener(event: "request", listener: (info: SocksProxyInfo) => void); - addListener(event: "error", listener: (err: Error) => void); + addListener(event: "methods", listener: (methods: Buffer) => void): this; + addListener(event: "request", listener: (info: SocksProxyInfo) => void): this; + addListener(event: "error", listener: (err: Error) => void): this; emit(event: string | symbol, ...args: any[]): boolean; emit(event: "methods", methods: Buffer): boolean; @@ -371,31 +376,28 @@ declare module "@outtacontrol/socks/lib/server.parser" { emit(event: "error", err: Error): boolean; on(event: string, listener: (...args: any[]) => void): this; - on(event: "methods", listener: (methods: Buffer) => void); - on(event: "request", listener: (info: SocksProxyInfo) => void); - on(event: "error", listener: (err: Error) => void); + on(event: "methods", listener: (methods: Buffer) => void): this; + on(event: "request", listener: (info: SocksProxyInfo) => void): this; + on(event: "error", listener: (err: Error) => void): this; once(event: string, listener: (...args: any[]) => void): this; - once(event: "methods", listener: (methods: Buffer) => void); - once(event: "request", listener: (info: SocksProxyInfo) => void); - once(event: "error", listener: (err: Error) => void); + once(event: "methods", listener: (methods: Buffer) => void): this; + once(event: "request", listener: (info: SocksProxyInfo) => void): this; + once(event: "error", listener: (err: Error) => void): this; prependListener(event: string, listener: (...args: any[]) => void): this; - prependListener(event: "methods", listener: (methods: Buffer) => void); - prependListener(event: "request", listener: (info: SocksProxyInfo) => void); - prependListener(event: "error", listener: (err: Error) => void); + prependListener(event: "methods", listener: (methods: Buffer) => void): this; + prependListener(event: "request", listener: (info: SocksProxyInfo) => void): this; + prependListener(event: "error", listener: (err: Error) => void): this; prependOnceListener(event: string, listener: (...args: any[]) => void): this; - prependOnceListener(event: "methods", listener: (methods: Buffer) => void); - prependOnceListener(event: "request", listener: (info: SocksProxyInfo) => void); - prependOnceListener(event: "error", listener: (err: Error) => void); + prependOnceListener(event: "methods", listener: (methods: Buffer) => void): this; + prependOnceListener(event: "request", listener: (info: SocksProxyInfo) => void): this; + prependOnceListener(event: "error", listener: (err: Error) => void): this; } } declare module "@outtacontrol/socks" { - import None from "@outtacontrol/socks/lib/auth/None"; - import UserPassword from "@outtacontrol/socks/lib/auth/UserPassword"; - export interface SocksBoundAddress { bndAddr: string; bndPort: number; @@ -412,6 +414,5 @@ declare module "@outtacontrol/socks" { export * from "@outtacontrol/socks/lib/Agents"; export * from "@outtacontrol/socks/lib/client"; export * from "@outtacontrol/socks/lib/server"; - - export const auth: { None, UserPassword }; -} \ No newline at end of file + export * from "@outtacontrol/socks/lib/auth"; +} diff --git a/index.js b/index.js index 84ca1f4..97fa4b1 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,16 @@ -var fs = require('fs'), - path = require('path'); +const { HttpAgent, HttpsAgent } = require('./lib/Agents'); +const { None, UserPassword } = require('./lib/auth'); +const { Client, connect, createConnection } = require('./lib/client'); +const { Server, createServer } = require('./lib/server'); -['server', 'client', 'Agents'].forEach(function(f) { - var exp = require(__dirname + '/lib/' + f), - keys = Object.keys(exp); - for (var i = 0, len = keys.length; i < len; ++i) - exports[keys[i]] = exp[keys[i]]; -}); +exports.auth = { None, UserPassword }; -exports.auth = {}; +exports.HttpAgent = HttpAgent; +exports.HttpsAgent = HttpsAgent; -fs.readdirSync(__dirname + '/lib/auth').forEach(function(f) { - exports.auth[path.basename(f, '.js')] = require(__dirname + '/lib/auth/' + f); -}); \ No newline at end of file +exports.Client = Client; +exports.connect = connect; +exports.createConnection = createConnection; + +exports.Server = Server; +exports.createServer = createServer; diff --git a/lib/auth.js b/lib/auth.js new file mode 100644 index 0000000..85976b2 --- /dev/null +++ b/lib/auth.js @@ -0,0 +1,5 @@ +const { None } = require('./auth/None'); +const { UserPassword } = require('./auth/UserPassword'); + +exports.None = None; +exports.UserPassword = UserPassword; diff --git a/lib/auth/None.js b/lib/auth/None.js index 75c3f52..10131b9 100644 --- a/lib/auth/None.js +++ b/lib/auth/None.js @@ -1,4 +1,4 @@ -module.exports = function NoneAuthHandlers() { +exports.None = function None() { return { METHOD: 0x00, server: function serverHandler(stream, cb) { diff --git a/lib/auth/UserPassword.js b/lib/auth/UserPassword.js index 5feb972..4bf97cd 100644 --- a/lib/auth/UserPassword.js +++ b/lib/auth/UserPassword.js @@ -11,7 +11,7 @@ var STATE_VERSION = 0, var BUF_SUCCESS = Buffer.from([0x01, 0x00]), BUF_FAILURE = Buffer.from([0x01, 0x01]); -module.exports = function UserPasswordAuthHandlers() { +exports.UserPassword = function UserPassword() { var authcb, user, pass, diff --git a/package.json b/package.json index d95a6b7..9a9c6e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@outtacontrol/socks", - "version": "1.0.1", + "version": "1.0.2", "author": "Brian White ", "description": "SOCKS protocol version 5 server and client implementations for node.js", "main": "./index.js", From dbdecf75be849337a31e78ba14d316deed43287f Mon Sep 17 00:00:00 2001 From: EntropyFBC49934 Date: Sat, 25 Aug 2018 11:16:25 +0200 Subject: [PATCH 9/9] bump version --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 9a9c6e8..71dc9b0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@outtacontrol/socks", - "version": "1.0.2", - "author": "Brian White ", + "version": "1.0.3", + "author": "Brian White , phoenix344", "description": "SOCKS protocol version 5 server and client implementations for node.js", "main": "./index.js", "types": "./index.d.ts", @@ -9,7 +9,7 @@ "test": "node test/test.js" }, "engines": { - "node": ">=0.10.0" + "node": ">=10" }, "keywords": [ "socks", @@ -20,12 +20,12 @@ "licenses": [ { "type": "MIT", - "url": "http://github.com/mscdex/socksv5/raw/master/LICENSE" + "url": "https://github.com/phoenix344/socksv5/raw/master/LICENSE" } ], "repository": { "type": "git", - "url": "http://github.com/mscdex/socksv5.git" + "url": "https://github.com/phoenix344/socksv5.git" }, "dependencies": { "ip-address": "^5.8.9"