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.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
@@ -20,7 +19,6 @@ namespace Lidgren.Network
|
||||
|
||||
static NetAESEncryption()
|
||||
{
|
||||
|
||||
AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
|
||||
List<int> temp = new List<int>();
|
||||
foreach (KeySizes keysize in aes.LegalKeySizes)
|
||||
@@ -55,18 +53,11 @@ namespace Lidgren.Network
|
||||
public NetAESEncryption(byte[] key, byte[] iv)
|
||||
{
|
||||
if (!m_keysizes.Contains(key.Length * 8))
|
||||
{
|
||||
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));
|
||||
}
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
if (!m_blocksizes.Contains(iv.Length * 8))
|
||||
{
|
||||
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));
|
||||
}
|
||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_blocksizes)));
|
||||
|
||||
m_key = key;
|
||||
m_iv = iv;
|
||||
m_bitSize = m_key.Length * 8;
|
||||
@@ -78,11 +69,8 @@ namespace Lidgren.Network
|
||||
public NetAESEncryption(string key, int bitsize)
|
||||
{
|
||||
if (!m_keysizes.Contains(bitsize))
|
||||
{
|
||||
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));
|
||||
}
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
||||
@@ -104,7 +92,7 @@ namespace Lidgren.Network
|
||||
/// NetAESEncryption constructor
|
||||
/// </summary>
|
||||
public NetAESEncryption(string key)
|
||||
: this(key, m_keysizes.Max())
|
||||
: this(key, m_keysizes[0])
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
@@ -55,18 +54,11 @@ namespace Lidgren.Network
|
||||
public NetDESEncryption(byte[] key, byte[] iv)
|
||||
{
|
||||
if (!m_keysizes.Contains(key.Length * 8))
|
||||
{
|
||||
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));
|
||||
}
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
if (!m_blocksizes.Contains(iv.Length * 8))
|
||||
{
|
||||
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));
|
||||
}
|
||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_blocksizes)));
|
||||
|
||||
m_key = key;
|
||||
m_iv = iv;
|
||||
m_bitSize = m_key.Length * 8;
|
||||
@@ -78,11 +70,8 @@ namespace Lidgren.Network
|
||||
public NetDESEncryption(string key, int bitsize)
|
||||
{
|
||||
if (!m_keysizes.Contains(bitsize))
|
||||
{
|
||||
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));
|
||||
}
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
||||
@@ -104,7 +93,7 @@ namespace Lidgren.Network
|
||||
/// NetDESEncryption constructor
|
||||
/// </summary>
|
||||
public NetDESEncryption(string key)
|
||||
: this(key, m_keysizes.Max())
|
||||
: this(key, m_keysizes[0])
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
@@ -55,18 +54,11 @@ namespace Lidgren.Network
|
||||
public NetRC2Encryption(byte[] key, byte[] iv)
|
||||
{
|
||||
if (!m_keysizes.Contains(key.Length * 8))
|
||||
{
|
||||
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));
|
||||
}
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
if (!m_blocksizes.Contains(iv.Length * 8))
|
||||
{
|
||||
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));
|
||||
}
|
||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_blocksizes)));
|
||||
|
||||
m_key = key;
|
||||
m_iv = iv;
|
||||
m_bitSize = m_key.Length * 8;
|
||||
@@ -78,11 +70,8 @@ namespace Lidgren.Network
|
||||
public NetRC2Encryption(string key, int bitsize)
|
||||
{
|
||||
if (!m_keysizes.Contains(bitsize))
|
||||
{
|
||||
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));
|
||||
}
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
||||
@@ -105,7 +94,7 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
public NetRC2Encryption(string key)
|
||||
: this(key, m_keysizes.Max())
|
||||
: this(key, m_keysizes[0])
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
@@ -55,18 +54,11 @@ namespace Lidgren.Network
|
||||
public NetTripleDESEncryption(byte[] key, byte[] iv)
|
||||
{
|
||||
if (!m_keysizes.Contains(key.Length * 8))
|
||||
{
|
||||
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));
|
||||
}
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
if (!m_blocksizes.Contains(iv.Length * 8))
|
||||
{
|
||||
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));
|
||||
}
|
||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_blocksizes)));
|
||||
|
||||
m_key = key;
|
||||
m_iv = iv;
|
||||
m_bitSize = m_key.Length * 8;
|
||||
@@ -78,11 +70,8 @@ namespace Lidgren.Network
|
||||
public NetTripleDESEncryption(string key, int bitsize)
|
||||
{
|
||||
if (!m_keysizes.Contains(bitsize))
|
||||
{
|
||||
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));
|
||||
}
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
||||
@@ -104,7 +93,7 @@ namespace Lidgren.Network
|
||||
/// NetTriplsDESEncryption constructor
|
||||
/// </summary>
|
||||
public NetTripleDESEncryption(string key)
|
||||
: this(key, m_keysizes.Max())
|
||||
: this(key, m_keysizes[0])
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using System.Net;
|
||||
|
||||
@@ -26,6 +26,7 @@ using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
@@ -555,5 +556,18 @@ namespace Lidgren.Network
|
||||
return NetDeliveryMethod.UnreliableSequenced;
|
||||
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