@@ -28,8 +28,6 @@ exports.Address4 = void 0;
2828const common = __importStar ( require ( "./common" ) ) ;
2929const constants = __importStar ( require ( "./v4/constants" ) ) ;
3030const address_error_1 = require ( "./address-error" ) ;
31- const jsbn_1 = require ( "jsbn" ) ;
32- const sprintf_js_1 = require ( "sprintf-js" ) ;
3331/**
3432 * Represents an IPv4 address
3533 * @class Address4
@@ -150,7 +148,7 @@ class Address4 {
150148 * @returns {String }
151149 */
152150 toHex ( ) {
153- return this . parsedAddress . map ( ( part ) => ( 0 , sprintf_js_1 . sprintf ) ( '%02x' , parseInt ( part , 10 ) ) ) . join ( ':' ) ;
151+ return this . parsedAddress . map ( ( part ) => common . stringToPaddedHex ( part ) ) . join ( ':' ) ;
154152 }
155153 /**
156154 * Converts an IPv4 address object to an array of bytes
@@ -171,28 +169,27 @@ class Address4 {
171169 const output = [ ] ;
172170 let i ;
173171 for ( i = 0 ; i < constants . GROUPS ; i += 2 ) {
174- const hex = ( 0 , sprintf_js_1 . sprintf ) ( '%02x%02x' , parseInt ( this . parsedAddress [ i ] , 10 ) , parseInt ( this . parsedAddress [ i + 1 ] , 10 ) ) ;
175- output . push ( ( 0 , sprintf_js_1 . sprintf ) ( '%x' , parseInt ( hex , 16 ) ) ) ;
172+ output . push ( `${ common . stringToPaddedHex ( this . parsedAddress [ i ] ) } ${ common . stringToPaddedHex ( this . parsedAddress [ i + 1 ] ) } ` ) ;
176173 }
177174 return output . join ( ':' ) ;
178175 }
179176 /**
180- * Returns the address as a BigInteger
177+ * Returns the address as a `bigint`
181178 * @memberof Address4
182179 * @instance
183- * @returns {BigInteger }
180+ * @returns {bigint }
184181 */
185- bigInteger ( ) {
186- return new jsbn_1 . BigInteger ( this . parsedAddress . map ( ( n ) => ( 0 , sprintf_js_1 . sprintf ) ( '%02x' , parseInt ( n , 10 ) ) ) . join ( '' ) , 16 ) ;
182+ bigInt ( ) {
183+ return BigInt ( `0x ${ this . parsedAddress . map ( ( n ) => common . stringToPaddedHex ( n ) ) . join ( '' ) } ` ) ;
187184 }
188185 /**
189186 * Helper function getting start address.
190187 * @memberof Address4
191188 * @instance
192- * @returns {BigInteger }
189+ * @returns {bigint }
193190 */
194191 _startAddress ( ) {
195- return new jsbn_1 . BigInteger ( this . mask ( ) + '0' . repeat ( constants . BITS - this . subnetMask ) , 2 ) ;
192+ return BigInt ( `0b ${ this . mask ( ) + '0' . repeat ( constants . BITS - this . subnetMask ) } ` ) ;
196193 }
197194 /**
198195 * The first address in the range given by this address' subnet.
@@ -202,7 +199,7 @@ class Address4 {
202199 * @returns {Address4 }
203200 */
204201 startAddress ( ) {
205- return Address4 . fromBigInteger ( this . _startAddress ( ) ) ;
202+ return Address4 . fromBigInt ( this . _startAddress ( ) ) ;
206203 }
207204 /**
208205 * The first host address in the range given by this address's subnet ie
@@ -212,17 +209,17 @@ class Address4 {
212209 * @returns {Address4 }
213210 */
214211 startAddressExclusive ( ) {
215- const adjust = new jsbn_1 . BigInteger ( '1' ) ;
216- return Address4 . fromBigInteger ( this . _startAddress ( ) . add ( adjust ) ) ;
212+ const adjust = BigInt ( '1' ) ;
213+ return Address4 . fromBigInt ( this . _startAddress ( ) + adjust ) ;
217214 }
218215 /**
219216 * Helper function getting end address.
220217 * @memberof Address4
221218 * @instance
222- * @returns {BigInteger }
219+ * @returns {bigint }
223220 */
224221 _endAddress ( ) {
225- return new jsbn_1 . BigInteger ( this . mask ( ) + '1' . repeat ( constants . BITS - this . subnetMask ) , 2 ) ;
222+ return BigInt ( `0b ${ this . mask ( ) + '1' . repeat ( constants . BITS - this . subnetMask ) } ` ) ;
226223 }
227224 /**
228225 * The last address in the range given by this address' subnet
@@ -232,7 +229,7 @@ class Address4 {
232229 * @returns {Address4 }
233230 */
234231 endAddress ( ) {
235- return Address4 . fromBigInteger ( this . _endAddress ( ) ) ;
232+ return Address4 . fromBigInt ( this . _endAddress ( ) ) ;
236233 }
237234 /**
238235 * The last host address in the range given by this address's subnet ie
@@ -242,18 +239,18 @@ class Address4 {
242239 * @returns {Address4 }
243240 */
244241 endAddressExclusive ( ) {
245- const adjust = new jsbn_1 . BigInteger ( '1' ) ;
246- return Address4 . fromBigInteger ( this . _endAddress ( ) . subtract ( adjust ) ) ;
242+ const adjust = BigInt ( '1' ) ;
243+ return Address4 . fromBigInt ( this . _endAddress ( ) - adjust ) ;
247244 }
248245 /**
249- * Converts a BigInteger to a v4 address object
246+ * Converts a BigInt to a v4 address object
250247 * @memberof Address4
251248 * @static
252- * @param {BigInteger } bigInteger - a BigInteger to convert
249+ * @param {bigint } bigInt - a BigInt to convert
253250 * @returns {Address4 }
254251 */
255- static fromBigInteger ( bigInteger ) {
256- return Address4 . fromInteger ( parseInt ( bigInteger . toString ( ) , 10 ) ) ;
252+ static fromBigInt ( bigInt ) {
253+ return Address4 . fromHex ( bigInt . toString ( 16 ) ) ;
257254 }
258255 /**
259256 * Returns the first n bits of the address, defaulting to the
@@ -293,7 +290,7 @@ class Address4 {
293290 if ( options . omitSuffix ) {
294291 return reversed ;
295292 }
296- return ( 0 , sprintf_js_1 . sprintf ) ( '%s. in-addr.arpa.' , reversed ) ;
293+ return ` ${ reversed } . in-addr.arpa.` ;
297294 }
298295 /**
299296 * Returns true if the given address is a multicast address
@@ -311,15 +308,19 @@ class Address4 {
311308 * @returns {string }
312309 */
313310 binaryZeroPad ( ) {
314- return this . bigInteger ( ) . toString ( 2 ) . padStart ( constants . BITS , '0' ) ;
311+ return this . bigInt ( ) . toString ( 2 ) . padStart ( constants . BITS , '0' ) ;
315312 }
316313 /**
317314 * Groups an IPv4 address for inclusion at the end of an IPv6 address
318315 * @returns {String }
319316 */
320317 groupForV6 ( ) {
321318 const segments = this . parsedAddress ;
322- return this . address . replace ( constants . RE_ADDRESS , ( 0 , sprintf_js_1 . sprintf ) ( '<span class="hover-group group-v4 group-6">%s</span>.<span class="hover-group group-v4 group-7">%s</span>' , segments . slice ( 0 , 2 ) . join ( '.' ) , segments . slice ( 2 , 4 ) . join ( '.' ) ) ) ;
319+ return this . address . replace ( constants . RE_ADDRESS , `<span class="hover-group group-v4 group-6">${ segments
320+ . slice ( 0 , 2 )
321+ . join ( '.' ) } </span>.<span class="hover-group group-v4 group-7">${ segments
322+ . slice ( 2 , 4 )
323+ . join ( '.' ) } </span>`) ;
323324 }
324325}
325326exports . Address4 = Address4 ;
0 commit comments