Skip to content

Commit

Permalink
net40, net45, net46, signed assemblies
Browse files Browse the repository at this point in the history
  • Loading branch information
lduchosal committed Aug 18, 2017
1 parent c0d4235 commit d203556
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 163 deletions.
29 changes: 25 additions & 4 deletions nant/release.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<property name="ipnetwork.sln" value="..\src\ipnetwork.sln" />
<property name="doc.base" value="${project::get-base-directory()}\..\doc" />
<property name="doc.doxygen" value="${doc.base}\Doxyfile" />
<property name="release.version" value="2.1.0" />
<property name="release.version" value="2.1.1" />
<property name="release.doc" value="..\doc\html" />
<property name="release.base" value="..\release" />
<property name="src.base" value="..\" />
Expand All @@ -14,7 +14,10 @@
<property name="src.dir" value="..\src" />
<property name="consoleappnetframework.dir" value="..\src\System.Net.IPNetwork.ConsoleApplication.NetFramework\bin\Release" />
<property name="consoleappnetcore.dir" value="..\src\System.Net.IPNetwork.ConsoleApplication.NetCore\bin\Release\netcoreapp1.1" />
<property name="lib.dir" value="..\src\System.Net.IPNetwork\bin\release\netstandard1.3" />
<property name="lib.dir.netstandard1.3" value="..\src\System.Net.IPNetwork\bin\release\netstandard1.3" />
<property name="lib.dir.net46" value="..\src\System.Net.IPNetwork\bin\release\net46" />
<property name="lib.dir.net45" value="..\src\System.Net.IPNetwork\bin\release\net45" />
<property name="lib.dir.net40" value="..\src\System.Net.IPNetwork\bin\release\net40" />

<property name="nupkg.dir" value="..\src\System.Net.IPNetwork\bin\release" />
<property name="nuget.dir" value="..\release" />
Expand Down Expand Up @@ -115,8 +118,26 @@
</fileset>
</delete>

<copy todir="${release.temp}/lib">
<fileset basedir="${lib.dir}" >
<copy todir="${release.temp}/lib/netstandard1.3">
<fileset basedir="${lib.dir.netstandard1.3}" >
<include name="System.Net.IPNetwork.dll" />
</fileset>
</copy>

<copy todir="${release.temp}/lib/net46">
<fileset basedir="${lib.dir.net46}" >
<include name="System.Net.IPNetwork.dll" />
</fileset>
</copy>

<copy todir="${release.temp}/lib/net45">
<fileset basedir="${lib.dir.net45}" >
<include name="System.Net.IPNetwork.dll" />
</fileset>
</copy>

<copy todir="${release.temp}/lib/net40">
<fileset basedir="${lib.dir.net40}" >
<include name="System.Net.IPNetwork.dll" />
</fileset>
</copy>
Expand Down
Binary file added release/IPNetwork-2.1.1.zip
Binary file not shown.
Binary file added release/IPNetwork2.2.1.1.nupkg
Binary file not shown.
Binary file added src/System.Net.IPNetwork.snk
Binary file not shown.
304 changes: 152 additions & 152 deletions src/System.Net.IPNetwork/BigIntegerExt.cs
Original file line number Diff line number Diff line change
@@ -1,153 +1,153 @@
using System.Collections.Generic;

using System.Collections.Generic;

namespace System.Net
{
using System;
using System.Numerics;
using System.Text;

/// <summary>
/// Extension methods to convert <see cref="System.Numerics.BigInteger"/>
/// instances to hexadecimal, octal, and binary strings.
/// </summary>
public static class BigIntegerExtensions {
/// <summary>
/// Converts a <see cref="BigInteger"/> to a binary string.
/// </summary>
/// <param name="bigint">A <see cref="BigInteger"/>.</param>
/// <returns>
/// A <see cref="System.String"/> containing a binary
/// representation of the supplied <see cref="BigInteger"/>.
/// </returns>
public static string ToBinaryString(this BigInteger bigint) {
var bytes = bigint.ToByteArray();
var idx = bytes.Length - 1;

// Create a StringBuilder having appropriate capacity.
var base2 = new StringBuilder(bytes.Length * 8);

// Convert first byte to binary.
var binary = Convert.ToString(bytes[idx], 2);

// Ensure leading zero exists if value is positive.
if (binary[0] != '0' && bigint.Sign == 1) {
base2.Append('0');
}

// Append binary string to StringBuilder.
base2.Append(binary);

// Convert remaining bytes adding leading zeros.
for (idx--; idx >= 0; idx--) {
base2.Append(Convert.ToString(bytes[idx], 2).PadLeft(8, '0'));
}

return base2.ToString();
}

/// <summary>
/// Converts a <see cref="BigInteger"/> to a hexadecimal string.
/// </summary>
/// <param name="bigint">A <see cref="BigInteger"/>.</param>
/// <returns>
/// A <see cref="System.String"/> containing a hexadecimal
/// representation of the supplied <see cref="BigInteger"/>.
/// </returns>
public static string ToHexadecimalString(this BigInteger bigint) {
return bigint.ToString("X");
}

/// <summary>
/// Converts a <see cref="BigInteger"/> to a octal string.
/// </summary>
/// <param name="bigint">A <see cref="BigInteger"/>.</param>
/// <returns>
/// A <see cref="System.String"/> containing an octal
/// representation of the supplied <see cref="BigInteger"/>.
/// </returns>
public static string ToOctalString(this BigInteger bigint) {
var bytes = bigint.ToByteArray();
var idx = bytes.Length - 1;

// Create a StringBuilder having appropriate capacity.
var base8 = new StringBuilder(((bytes.Length / 3) + 1) * 8);

// Calculate how many bytes are extra when byte array is split
// into three-byte (24-bit) chunks.
var extra = bytes.Length % 3;

// If no bytes are extra, use three bytes for first chunk.
if (extra == 0) {
extra = 3;
}

// Convert first chunk (24-bits) to integer value.
int int24 = 0;
for (; extra != 0; extra--) {
int24 <<= 8;
int24 += bytes[idx--];
}

// Convert 24-bit integer to octal without adding leading zeros.
var octal = Convert.ToString(int24, 8);

// Ensure leading zero exists if value is positive.
if (octal[0] != '0' && bigint.Sign == 1) {
base8.Append('0');
}

// Append first converted chunk to StringBuilder.
base8.Append(octal);

// Convert remaining 24-bit chunks, adding leading zeros.
for (; idx >= 0; idx -= 3) {
int24 = (bytes[idx] << 16) + (bytes[idx - 1] << 8) + bytes[idx - 2];
base8.Append(Convert.ToString(int24, 8).PadLeft(8, '0'));
}

return base8.ToString();
}

/// <summary>
///
/// Reverse a Positive BigInteger ONLY
/// Bitwise ~ operator
///
/// Input : FF FF FF FF
/// Width : 4
/// Result : 00 00 00 00
///
///
/// Input : 00 00 00 00
/// Width : 4
/// Result : FF FF FF FF
///
/// Input : FF FF FF FF
/// Width : 8
/// Result : FF FF FF FF 00 00 00 00
///
///
/// Input : 00 00 00 00
/// Width : 8
/// Result : FF FF FF FF FF FF FF FF
///
/// </summary>
/// <param name="input"></param>
/// <param name="width"></param>
/// <returns></returns>
public static BigInteger PositiveReverse(this BigInteger input, int width) {

var result = new List<byte>();
var bytes = input.ToByteArray();
var work = new byte[width];
Array.Copy(bytes, 0, work, 0, bytes.Length - 1); // Length -1 : positive BigInteger

for (int i = 0; i < work.Length; i++) {
result.Add((byte)(~work[i]));
}
result.Add(0); // positive BigInteger
return new BigInteger(result.ToArray());

}
}
}
{
using System;
using System.Numerics;
using System.Text;

/// <summary>
/// Extension methods to convert <see cref="System.Numerics.BigInteger"/>
/// instances to hexadecimal, octal, and binary strings.
/// </summary>
public static class BigIntegerExtensions {
/// <summary>
/// Converts a <see cref="BigInteger"/> to a binary string.
/// </summary>
/// <param name="bigint">A <see cref="BigInteger"/>.</param>
/// <returns>
/// A <see cref="System.String"/> containing a binary
/// representation of the supplied <see cref="BigInteger"/>.
/// </returns>
public static string ToBinaryString(this BigInteger bigint) {
var bytes = bigint.ToByteArray();
var idx = bytes.Length - 1;

// Create a StringBuilder having appropriate capacity.
var base2 = new StringBuilder(bytes.Length * 8);

// Convert first byte to binary.
var binary = Convert.ToString(bytes[idx], 2);

// Ensure leading zero exists if value is positive.
if (binary[0] != '0' && bigint.Sign == 1) {
base2.Append('0');
}

// Append binary string to StringBuilder.
base2.Append(binary);

// Convert remaining bytes adding leading zeros.
for (idx--; idx >= 0; idx--) {
base2.Append(Convert.ToString(bytes[idx], 2).PadLeft(8, '0'));
}

return base2.ToString();
}

/// <summary>
/// Converts a <see cref="BigInteger"/> to a hexadecimal string.
/// </summary>
/// <param name="bigint">A <see cref="BigInteger"/>.</param>
/// <returns>
/// A <see cref="System.String"/> containing a hexadecimal
/// representation of the supplied <see cref="BigInteger"/>.
/// </returns>
public static string ToHexadecimalString(this BigInteger bigint) {
return bigint.ToString("X");
}

/// <summary>
/// Converts a <see cref="BigInteger"/> to a octal string.
/// </summary>
/// <param name="bigint">A <see cref="BigInteger"/>.</param>
/// <returns>
/// A <see cref="System.String"/> containing an octal
/// representation of the supplied <see cref="BigInteger"/>.
/// </returns>
public static string ToOctalString(this BigInteger bigint) {
var bytes = bigint.ToByteArray();
var idx = bytes.Length - 1;

// Create a StringBuilder having appropriate capacity.
var base8 = new StringBuilder(((bytes.Length / 3) + 1) * 8);

// Calculate how many bytes are extra when byte array is split
// into three-byte (24-bit) chunks.
var extra = bytes.Length % 3;

// If no bytes are extra, use three bytes for first chunk.
if (extra == 0) {
extra = 3;
}

// Convert first chunk (24-bits) to integer value.
int int24 = 0;
for (; extra != 0; extra--) {
int24 <<= 8;
int24 += bytes[idx--];
}

// Convert 24-bit integer to octal without adding leading zeros.
var octal = Convert.ToString(int24, 8);

// Ensure leading zero exists if value is positive.
if (octal[0] != '0' && bigint.Sign == 1) {
base8.Append('0');
}

// Append first converted chunk to StringBuilder.
base8.Append(octal);

// Convert remaining 24-bit chunks, adding leading zeros.
for (; idx >= 0; idx -= 3) {
int24 = (bytes[idx] << 16) + (bytes[idx - 1] << 8) + bytes[idx - 2];
base8.Append(Convert.ToString(int24, 8).PadLeft(8, '0'));
}

return base8.ToString();
}

/// <summary>
///
/// Reverse a Positive BigInteger ONLY
/// Bitwise ~ operator
///
/// Input : FF FF FF FF
/// Width : 4
/// Result : 00 00 00 00
///
///
/// Input : 00 00 00 00
/// Width : 4
/// Result : FF FF FF FF
///
/// Input : FF FF FF FF
/// Width : 8
/// Result : FF FF FF FF 00 00 00 00
///
///
/// Input : 00 00 00 00
/// Width : 8
/// Result : FF FF FF FF FF FF FF FF
///
/// </summary>
/// <param name="input"></param>
/// <param name="width"></param>
/// <returns></returns>
public static BigInteger PositiveReverse(this BigInteger input, int width) {

var result = new List<byte>();
var bytes = input.ToByteArray();
var work = new byte[width];
Array.Copy(bytes, 0, work, 0, bytes.Length - 1); // Length -1 : positive BigInteger

for (int i = 0; i < work.Length; i++) {
result.Add((byte)(~work[i]));
}
result.Add(0); // positive BigInteger
return new BigInteger(result.ToArray());

}
}
}
4 changes: 2 additions & 2 deletions src/System.Net.IPNetwork/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("System.Net.IPNetwork")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("IPNetwork C# library take care of complex network, ip, ipv4, ipv6, netmask, cidr, subnet, subnetting, supernet and supernetting calculation for .Net developpers. It works with IPv4 and IPv6 as well. It is written in C# for .NetStandard and coreclr and has a light and clean API and is fully unit tested.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Luc Dvchosal")]
[assembly: AssemblyProduct("System.Net.IPNetwork")]
Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyVersion("2.1.1.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
Loading

0 comments on commit d203556

Please sign in to comment.