You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-06 02:11:06 +09:00
Linq namespace usage removed
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -20,7 +19,6 @@ namespace Lidgren.Network
|
|||||||
|
|
||||||
static NetAESEncryption()
|
static NetAESEncryption()
|
||||||
{
|
{
|
||||||
|
|
||||||
AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
|
AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
|
||||||
List<int> temp = new List<int>();
|
List<int> temp = new List<int>();
|
||||||
foreach (KeySizes keysize in aes.LegalKeySizes)
|
foreach (KeySizes keysize in aes.LegalKeySizes)
|
||||||
@@ -55,18 +53,11 @@ namespace Lidgren.Network
|
|||||||
public NetAESEncryption(byte[] key, byte[] iv)
|
public NetAESEncryption(byte[] key, byte[] iv)
|
||||||
{
|
{
|
||||||
if (!m_keysizes.Contains(key.Length * 8))
|
if (!m_keysizes.Contains(key.Length * 8))
|
||||||
{
|
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||||
string lengths = m_keysizes.Aggregate("", (current, i) => current + string.Format("{0}, ", i));
|
|
||||||
lengths = lengths.Remove(lengths.Length - 3);
|
|
||||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", lengths));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_blocksizes.Contains(iv.Length * 8))
|
if (!m_blocksizes.Contains(iv.Length * 8))
|
||||||
{
|
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_blocksizes)));
|
||||||
string lengths = m_blocksizes.Aggregate("", (current, i) => current + string.Format("{0}, ", i));
|
|
||||||
lengths = lengths.Remove(lengths.Length - 3);
|
|
||||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", lengths));
|
|
||||||
}
|
|
||||||
m_key = key;
|
m_key = key;
|
||||||
m_iv = iv;
|
m_iv = iv;
|
||||||
m_bitSize = m_key.Length * 8;
|
m_bitSize = m_key.Length * 8;
|
||||||
@@ -78,11 +69,8 @@ namespace Lidgren.Network
|
|||||||
public NetAESEncryption(string key, int bitsize)
|
public NetAESEncryption(string key, int bitsize)
|
||||||
{
|
{
|
||||||
if (!m_keysizes.Contains(bitsize))
|
if (!m_keysizes.Contains(bitsize))
|
||||||
{
|
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||||
string lengths = m_keysizes.Aggregate("", (current, i) => current + string.Format("{0}, ", i));
|
|
||||||
lengths = lengths.Remove(lengths.Length - 3);
|
|
||||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", lengths));
|
|
||||||
}
|
|
||||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||||
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
||||||
@@ -104,7 +92,7 @@ namespace Lidgren.Network
|
|||||||
/// NetAESEncryption constructor
|
/// NetAESEncryption constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public NetAESEncryption(string key)
|
public NetAESEncryption(string key)
|
||||||
: this(key, m_keysizes.Max())
|
: this(key, m_keysizes[0])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -55,18 +54,11 @@ namespace Lidgren.Network
|
|||||||
public NetDESEncryption(byte[] key, byte[] iv)
|
public NetDESEncryption(byte[] key, byte[] iv)
|
||||||
{
|
{
|
||||||
if (!m_keysizes.Contains(key.Length * 8))
|
if (!m_keysizes.Contains(key.Length * 8))
|
||||||
{
|
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||||
string lengths = m_keysizes.Aggregate("", (current, i) => current + string.Format("{0}, ", i));
|
|
||||||
lengths = lengths.Remove(lengths.Length - 3);
|
|
||||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", lengths));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_blocksizes.Contains(iv.Length * 8))
|
if (!m_blocksizes.Contains(iv.Length * 8))
|
||||||
{
|
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_blocksizes)));
|
||||||
string lengths = m_blocksizes.Aggregate("", (current, i) => current + string.Format("{0}, ", i));
|
|
||||||
lengths = lengths.Remove(lengths.Length - 3);
|
|
||||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", lengths));
|
|
||||||
}
|
|
||||||
m_key = key;
|
m_key = key;
|
||||||
m_iv = iv;
|
m_iv = iv;
|
||||||
m_bitSize = m_key.Length * 8;
|
m_bitSize = m_key.Length * 8;
|
||||||
@@ -78,11 +70,8 @@ namespace Lidgren.Network
|
|||||||
public NetDESEncryption(string key, int bitsize)
|
public NetDESEncryption(string key, int bitsize)
|
||||||
{
|
{
|
||||||
if (!m_keysizes.Contains(bitsize))
|
if (!m_keysizes.Contains(bitsize))
|
||||||
{
|
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||||
string lengths = m_keysizes.Aggregate("", (current, i) => current + string.Format("{0}, ", i));
|
|
||||||
lengths = lengths.Remove(lengths.Length - 3);
|
|
||||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", lengths));
|
|
||||||
}
|
|
||||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||||
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
||||||
@@ -104,7 +93,7 @@ namespace Lidgren.Network
|
|||||||
/// NetDESEncryption constructor
|
/// NetDESEncryption constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public NetDESEncryption(string key)
|
public NetDESEncryption(string key)
|
||||||
: this(key, m_keysizes.Max())
|
: this(key, m_keysizes[0])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -55,18 +54,11 @@ namespace Lidgren.Network
|
|||||||
public NetRC2Encryption(byte[] key, byte[] iv)
|
public NetRC2Encryption(byte[] key, byte[] iv)
|
||||||
{
|
{
|
||||||
if (!m_keysizes.Contains(key.Length * 8))
|
if (!m_keysizes.Contains(key.Length * 8))
|
||||||
{
|
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||||
string lengths = m_keysizes.Aggregate("", (current, i) => current + string.Format("{0}, ", i));
|
|
||||||
lengths = lengths.Remove(lengths.Length - 3);
|
|
||||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", lengths));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_blocksizes.Contains(iv.Length * 8))
|
if (!m_blocksizes.Contains(iv.Length * 8))
|
||||||
{
|
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_blocksizes)));
|
||||||
string lengths = m_blocksizes.Aggregate("", (current, i) => current + string.Format("{0}, ", i));
|
|
||||||
lengths = lengths.Remove(lengths.Length - 3);
|
|
||||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", lengths));
|
|
||||||
}
|
|
||||||
m_key = key;
|
m_key = key;
|
||||||
m_iv = iv;
|
m_iv = iv;
|
||||||
m_bitSize = m_key.Length * 8;
|
m_bitSize = m_key.Length * 8;
|
||||||
@@ -78,11 +70,8 @@ namespace Lidgren.Network
|
|||||||
public NetRC2Encryption(string key, int bitsize)
|
public NetRC2Encryption(string key, int bitsize)
|
||||||
{
|
{
|
||||||
if (!m_keysizes.Contains(bitsize))
|
if (!m_keysizes.Contains(bitsize))
|
||||||
{
|
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||||
string lengths = m_keysizes.Aggregate("", (current, i) => current + string.Format("{0}, ", i));
|
|
||||||
lengths = lengths.Remove(lengths.Length - 3);
|
|
||||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", lengths));
|
|
||||||
}
|
|
||||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||||
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
||||||
@@ -105,7 +94,7 @@ namespace Lidgren.Network
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
public NetRC2Encryption(string key)
|
public NetRC2Encryption(string key)
|
||||||
: this(key, m_keysizes.Max())
|
: this(key, m_keysizes[0])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -55,18 +54,11 @@ namespace Lidgren.Network
|
|||||||
public NetTripleDESEncryption(byte[] key, byte[] iv)
|
public NetTripleDESEncryption(byte[] key, byte[] iv)
|
||||||
{
|
{
|
||||||
if (!m_keysizes.Contains(key.Length * 8))
|
if (!m_keysizes.Contains(key.Length * 8))
|
||||||
{
|
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||||
string lengths = m_keysizes.Aggregate("", (current, i) => current + string.Format("{0}, ", i));
|
|
||||||
lengths = lengths.Remove(lengths.Length - 3);
|
|
||||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", lengths));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_blocksizes.Contains(iv.Length * 8))
|
if (!m_blocksizes.Contains(iv.Length * 8))
|
||||||
{
|
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_blocksizes)));
|
||||||
string lengths = m_blocksizes.Aggregate("", (current, i) => current + string.Format("{0}, ", i));
|
|
||||||
lengths = lengths.Remove(lengths.Length - 3);
|
|
||||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", lengths));
|
|
||||||
}
|
|
||||||
m_key = key;
|
m_key = key;
|
||||||
m_iv = iv;
|
m_iv = iv;
|
||||||
m_bitSize = m_key.Length * 8;
|
m_bitSize = m_key.Length * 8;
|
||||||
@@ -78,11 +70,8 @@ namespace Lidgren.Network
|
|||||||
public NetTripleDESEncryption(string key, int bitsize)
|
public NetTripleDESEncryption(string key, int bitsize)
|
||||||
{
|
{
|
||||||
if (!m_keysizes.Contains(bitsize))
|
if (!m_keysizes.Contains(bitsize))
|
||||||
{
|
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||||
string lengths = m_keysizes.Aggregate("", (current, i) => current + string.Format("{0}, ", i));
|
|
||||||
lengths = lengths.Remove(lengths.Length - 3);
|
|
||||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", lengths));
|
|
||||||
}
|
|
||||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||||
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
||||||
@@ -104,7 +93,7 @@ namespace Lidgren.Network
|
|||||||
/// NetTriplsDESEncryption constructor
|
/// NetTriplsDESEncryption constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public NetTripleDESEncryption(string key)
|
public NetTripleDESEncryption(string key)
|
||||||
: this(key, m_keysizes.Max())
|
: this(key, m_keysizes[0])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ using System.Net.NetworkInformation;
|
|||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Lidgren.Network
|
namespace Lidgren.Network
|
||||||
{
|
{
|
||||||
@@ -555,5 +556,18 @@ namespace Lidgren.Network
|
|||||||
return NetDeliveryMethod.UnreliableSequenced;
|
return NetDeliveryMethod.UnreliableSequenced;
|
||||||
return NetDeliveryMethod.Unreliable;
|
return NetDeliveryMethod.Unreliable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string MakeCommaDelimitedList<T>(IList<T> list)
|
||||||
|
{
|
||||||
|
var cnt = list.Count;
|
||||||
|
StringBuilder bdr = new StringBuilder(cnt * 5); // educated guess
|
||||||
|
for(int i=0;i<cnt;i++)
|
||||||
|
{
|
||||||
|
bdr.Append(list[i].ToString());
|
||||||
|
if (i != cnt - 1)
|
||||||
|
bdr.Append(", ");
|
||||||
|
}
|
||||||
|
return bdr.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user