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
Warnings and minor inconsistencies fixed
This commit is contained in:
@@ -14,8 +14,8 @@ namespace Lidgren.Network
|
||||
private readonly byte[] m_key;
|
||||
private readonly byte[] m_iv;
|
||||
private readonly int m_bitSize;
|
||||
private static readonly List<int> m_keysizes;
|
||||
private static readonly List<int> m_blocksizes;
|
||||
private static readonly List<int> s_keysizes;
|
||||
private static readonly List<int> s_blocksizes;
|
||||
|
||||
static NetAESEncryption()
|
||||
{
|
||||
@@ -32,7 +32,7 @@ namespace Lidgren.Network
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_keysizes = temp;
|
||||
s_keysizes = temp;
|
||||
temp = new List<int>();
|
||||
foreach (KeySizes keysize in aes.LegalBlockSizes)
|
||||
{
|
||||
@@ -45,7 +45,7 @@ namespace Lidgren.Network
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_blocksizes = temp;
|
||||
s_blocksizes = temp;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -54,11 +54,11 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public NetAESEncryption(byte[] key, byte[] iv)
|
||||
{
|
||||
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)));
|
||||
if (!s_keysizes.Contains(key.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes)));
|
||||
|
||||
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)));
|
||||
if (!s_blocksizes.Contains(iv.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_blocksizes)));
|
||||
|
||||
m_key = key;
|
||||
m_iv = iv;
|
||||
@@ -70,8 +70,8 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public NetAESEncryption(string key, int bitsize)
|
||||
{
|
||||
if (!m_keysizes.Contains(bitsize))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
if (!s_keysizes.Contains(bitsize))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes)));
|
||||
|
||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||
@@ -84,7 +84,7 @@ namespace Lidgren.Network
|
||||
int keylen = bitsize / 8;
|
||||
m_key = new byte[keylen];
|
||||
Buffer.BlockCopy(entropy, 0, m_key, 0, keylen);
|
||||
m_iv = new byte[m_blocksizes[0] / 8];
|
||||
m_iv = new byte[s_blocksizes[0] / 8];
|
||||
|
||||
Buffer.BlockCopy(entropy, entropy.Length - m_iv.Length - 1, m_iv, 0, m_iv.Length);
|
||||
m_bitSize = bitsize;
|
||||
@@ -94,7 +94,7 @@ namespace Lidgren.Network
|
||||
/// NetAESEncryption constructor
|
||||
/// </summary>
|
||||
public NetAESEncryption(string key)
|
||||
: this(key, m_keysizes[0])
|
||||
: this(key, s_keysizes[0])
|
||||
{
|
||||
}
|
||||
|
||||
@@ -111,12 +111,11 @@ namespace Lidgren.Network
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = aesCryptoServiceProvider.CreateEncryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
var memoryStream = new MemoryStream();
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write))
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
cryptoStream.Close();
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -146,13 +145,11 @@ namespace Lidgren.Network
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = aesCryptoServiceProvider.CreateDecryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
var memoryStream = new MemoryStream();
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write))
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform,
|
||||
CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
cryptoStream.Close();
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Lidgren.Network
|
||||
private readonly byte[] m_key;
|
||||
private readonly byte[] m_iv;
|
||||
private readonly int m_bitSize;
|
||||
private static readonly List<int> m_keysizes;
|
||||
private static readonly List<int> m_blocksizes;
|
||||
private static readonly List<int> s_keysizes;
|
||||
private static readonly List<int> s_blocksizes;
|
||||
|
||||
static NetDESEncryption()
|
||||
{
|
||||
@@ -32,7 +32,7 @@ namespace Lidgren.Network
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_keysizes = temp;
|
||||
s_keysizes = temp;
|
||||
temp = new List<int>();
|
||||
foreach (KeySizes keysize in des.LegalBlockSizes)
|
||||
{
|
||||
@@ -45,7 +45,7 @@ namespace Lidgren.Network
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_blocksizes = temp;
|
||||
s_blocksizes = temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,11 +53,11 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public NetDESEncryption(byte[] key, byte[] iv)
|
||||
{
|
||||
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)));
|
||||
if (!s_keysizes.Contains(key.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes)));
|
||||
|
||||
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)));
|
||||
if (!s_blocksizes.Contains(iv.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_blocksizes)));
|
||||
|
||||
m_key = key;
|
||||
m_iv = iv;
|
||||
@@ -69,8 +69,8 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public NetDESEncryption(string key, int bitsize)
|
||||
{
|
||||
if (!m_keysizes.Contains(bitsize))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
if (!s_keysizes.Contains(bitsize))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes)));
|
||||
|
||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||
@@ -83,7 +83,7 @@ namespace Lidgren.Network
|
||||
int keylen = bitsize / 8;
|
||||
m_key = new byte[keylen];
|
||||
Buffer.BlockCopy(entropy, 0, m_key, 0, keylen);
|
||||
m_iv = new byte[m_blocksizes[0] / 8];
|
||||
m_iv = new byte[s_blocksizes[0] / 8];
|
||||
|
||||
Buffer.BlockCopy(entropy, entropy.Length - m_iv.Length - 1, m_iv, 0, m_iv.Length);
|
||||
m_bitSize = bitsize;
|
||||
@@ -93,7 +93,7 @@ namespace Lidgren.Network
|
||||
/// NetDESEncryption constructor
|
||||
/// </summary>
|
||||
public NetDESEncryption(string key)
|
||||
: this(key, m_keysizes[0])
|
||||
: this(key, s_keysizes[0])
|
||||
{
|
||||
}
|
||||
|
||||
@@ -109,13 +109,11 @@ namespace Lidgren.Network
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = desCryptoServiceProvider.CreateEncryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
var memoryStream = new MemoryStream();
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write))
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform,
|
||||
CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
cryptoStream.Close();
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -141,13 +139,11 @@ namespace Lidgren.Network
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = desCryptoServiceProvider.CreateDecryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
var memoryStream = new MemoryStream();
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write))
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform,
|
||||
CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
cryptoStream.Close();
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Lidgren.Network
|
||||
private readonly byte[] m_key;
|
||||
private readonly byte[] m_iv;
|
||||
private readonly int m_bitSize;
|
||||
private static readonly List<int> m_keysizes;
|
||||
private static readonly List<int> m_blocksizes;
|
||||
private static readonly List<int> s_keysizes;
|
||||
private static readonly List<int> s_blocksizes;
|
||||
|
||||
static NetRC2Encryption()
|
||||
{
|
||||
@@ -32,7 +32,7 @@ namespace Lidgren.Network
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_keysizes = temp;
|
||||
s_keysizes = temp;
|
||||
temp = new List<int>();
|
||||
foreach (KeySizes keysize in rc2.LegalBlockSizes)
|
||||
{
|
||||
@@ -45,7 +45,7 @@ namespace Lidgren.Network
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_blocksizes = temp;
|
||||
s_blocksizes = temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,11 +53,11 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public NetRC2Encryption(byte[] key, byte[] iv)
|
||||
{
|
||||
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)));
|
||||
if (!s_keysizes.Contains(key.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes)));
|
||||
|
||||
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)));
|
||||
if (!s_blocksizes.Contains(iv.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_blocksizes)));
|
||||
|
||||
m_key = key;
|
||||
m_iv = iv;
|
||||
@@ -69,8 +69,8 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public NetRC2Encryption(string key, int bitsize)
|
||||
{
|
||||
if (!m_keysizes.Contains(bitsize))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
if (!s_keysizes.Contains(bitsize))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes)));
|
||||
|
||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||
@@ -83,7 +83,7 @@ namespace Lidgren.Network
|
||||
int keylen = bitsize / 8;
|
||||
m_key = new byte[keylen];
|
||||
Buffer.BlockCopy(entropy, 0, m_key, 0, keylen);
|
||||
m_iv = new byte[m_blocksizes[0] / 8];
|
||||
m_iv = new byte[s_blocksizes[0] / 8];
|
||||
|
||||
Buffer.BlockCopy(entropy, entropy.Length - m_iv.Length - 1, m_iv, 0, m_iv.Length);
|
||||
m_bitSize = bitsize;
|
||||
@@ -94,7 +94,7 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
public NetRC2Encryption(string key)
|
||||
: this(key, m_keysizes[0])
|
||||
: this(key, s_keysizes[0])
|
||||
{
|
||||
}
|
||||
|
||||
@@ -110,13 +110,11 @@ namespace Lidgren.Network
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = rc2CryptoServiceProvider.CreateEncryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
var memoryStream = new MemoryStream();
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write))
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform,
|
||||
CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
cryptoStream.Close();
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -142,13 +140,11 @@ namespace Lidgren.Network
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = rc2CryptoServiceProvider.CreateDecryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
var memoryStream = new MemoryStream();
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write))
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform,
|
||||
CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
cryptoStream.Close();
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Lidgren.Network
|
||||
private readonly byte[] m_key;
|
||||
private readonly byte[] m_iv;
|
||||
private readonly int m_bitSize;
|
||||
private static readonly List<int> m_keysizes;
|
||||
private static readonly List<int> m_blocksizes;
|
||||
private static readonly List<int> s_keysizes;
|
||||
private static readonly List<int> s_blocksizes;
|
||||
|
||||
static NetTripleDESEncryption()
|
||||
{
|
||||
@@ -32,7 +32,7 @@ namespace Lidgren.Network
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_keysizes = temp;
|
||||
s_keysizes = temp;
|
||||
temp = new List<int>();
|
||||
foreach (KeySizes keysize in tripleDES.LegalBlockSizes)
|
||||
{
|
||||
@@ -45,7 +45,7 @@ namespace Lidgren.Network
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_blocksizes = temp;
|
||||
s_blocksizes = temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,11 +53,11 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public NetTripleDESEncryption(byte[] key, byte[] iv)
|
||||
{
|
||||
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)));
|
||||
if (!s_keysizes.Contains(key.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes)));
|
||||
|
||||
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)));
|
||||
if (!s_blocksizes.Contains(iv.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_blocksizes)));
|
||||
|
||||
m_key = key;
|
||||
m_iv = iv;
|
||||
@@ -69,8 +69,8 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public NetTripleDESEncryption(string key, int bitsize)
|
||||
{
|
||||
if (!m_keysizes.Contains(bitsize))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
if (!s_keysizes.Contains(bitsize))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(s_keysizes)));
|
||||
|
||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||
@@ -83,7 +83,7 @@ namespace Lidgren.Network
|
||||
int keylen = bitsize / 8;
|
||||
m_key = new byte[keylen];
|
||||
Buffer.BlockCopy(entropy, 0, m_key, 0, keylen);
|
||||
m_iv = new byte[m_blocksizes[0] / 8];
|
||||
m_iv = new byte[s_blocksizes[0] / 8];
|
||||
|
||||
Buffer.BlockCopy(entropy, entropy.Length - m_iv.Length - 1, m_iv, 0, m_iv.Length);
|
||||
m_bitSize = bitsize;
|
||||
@@ -93,7 +93,7 @@ namespace Lidgren.Network
|
||||
/// NetTriplsDESEncryption constructor
|
||||
/// </summary>
|
||||
public NetTripleDESEncryption(string key)
|
||||
: this(key, m_keysizes[0])
|
||||
: this(key, s_keysizes[0])
|
||||
{
|
||||
}
|
||||
|
||||
@@ -109,13 +109,11 @@ namespace Lidgren.Network
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = tripleDESCryptoServiceProvider.CreateEncryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
var memoryStream = new MemoryStream();
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write))
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform,
|
||||
CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
cryptoStream.Close();
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -141,13 +139,11 @@ namespace Lidgren.Network
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = tripleDESCryptoServiceProvider.CreateDecryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
var memoryStream = new MemoryStream();
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write))
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform,
|
||||
CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
cryptoStream.Close();
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace Lidgren.Network
|
||||
/// String to hash for key
|
||||
/// </summary>
|
||||
public NetXtea(string key)
|
||||
: this(SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(key)), 32)
|
||||
: this(NetUtility.CreateSHA1Hash(key), 32)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Lidgren.Network
|
||||
{
|
||||
internal class ReceivedFragmentGroup
|
||||
{
|
||||
public float LastReceived;
|
||||
//public float LastReceived;
|
||||
public byte[] Data;
|
||||
public NetBitVector ReceivedChunks;
|
||||
}
|
||||
@@ -126,7 +126,7 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
info.ReceivedChunks[chunkNumber] = true;
|
||||
info.LastReceived = (float)NetTime.Now;
|
||||
//info.LastReceived = (float)NetTime.Now;
|
||||
|
||||
// copy to data
|
||||
int offset = (chunkNumber * chunkByteSize);
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace Lidgren.Network
|
||||
byte[] combined = new byte[epBytes.Length + macBytes.Length];
|
||||
Array.Copy(epBytes, 0, combined, 0, epBytes.Length);
|
||||
Array.Copy(macBytes, 0, combined, epBytes.Length, macBytes.Length);
|
||||
m_uniqueIdentifier = BitConverter.ToInt64(SHA1.Create().ComputeHash(combined), 0);
|
||||
m_uniqueIdentifier = BitConverter.ToInt64(NetUtility.CreateSHA1Hash(combined), 0);
|
||||
|
||||
m_status = NetPeerStatus.Running;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ using System.Threading;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
/// <summary>
|
||||
/// Class for generating random seeds
|
||||
/// </summary>
|
||||
public static class NetRandomSeed
|
||||
{
|
||||
private static int m_seedIncrement = -1640531527;
|
||||
|
||||
@@ -168,11 +168,11 @@ namespace Lidgren.Network
|
||||
|
||||
try
|
||||
{
|
||||
XmlDocument xdoc = SOAPRequest(m_serviceUrl,
|
||||
SOAPRequest(m_serviceUrl,
|
||||
"<u:AddPortMapping xmlns:u=\"urn:schemas-upnp-org:service:" + m_serviceName + ":1\">" +
|
||||
"<NewRemoteHost></NewRemoteHost>" +
|
||||
"<NewExternalPort>" + port.ToString() + "</NewExternalPort>" +
|
||||
"<NewProtocol>" + ProtocolType.Udp.ToString().ToUpper() + "</NewProtocol>" +
|
||||
"<NewProtocol>" + ProtocolType.Udp.ToString().ToUpper(System.Globalization.CultureInfo.InvariantCulture) + "</NewProtocol>" +
|
||||
"<NewInternalPort>" + port.ToString() + "</NewInternalPort>" +
|
||||
"<NewInternalClient>" + client.ToString() + "</NewInternalClient>" +
|
||||
"<NewEnabled>1</NewEnabled>" +
|
||||
@@ -202,12 +202,12 @@ namespace Lidgren.Network
|
||||
|
||||
try
|
||||
{
|
||||
XmlDocument xdoc = SOAPRequest(m_serviceUrl,
|
||||
SOAPRequest(m_serviceUrl,
|
||||
"<u:DeletePortMapping xmlns:u=\"urn:schemas-upnp-org:service:" + m_serviceName + ":1\">" +
|
||||
"<NewRemoteHost>" +
|
||||
"</NewRemoteHost>" +
|
||||
"<NewExternalPort>" + port + "</NewExternalPort>" +
|
||||
"<NewProtocol>" + ProtocolType.Udp.ToString().ToUpper() + "</NewProtocol>" +
|
||||
"<NewProtocol>" + ProtocolType.Udp.ToString().ToUpper(System.Globalization.CultureInfo.InvariantCulture) + "</NewProtocol>" +
|
||||
"</u:DeletePortMapping>", "DeletePortMapping");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
@@ -592,5 +593,23 @@ namespace Lidgren.Network
|
||||
}
|
||||
return bdr.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a SHA1 digest from a string
|
||||
/// </summary>
|
||||
public static byte[] CreateSHA1Hash(string key)
|
||||
{
|
||||
using (var sha = SHA1.Create())
|
||||
return sha.ComputeHash(Encoding.UTF8.GetBytes(key));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a SHA1 digest from a byte buffer
|
||||
/// </summary>
|
||||
public static byte[] CreateSHA1Hash(byte[] data)
|
||||
{
|
||||
using (var sha = SHA1.Create())
|
||||
return sha.ComputeHash(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,9 +36,12 @@ namespace UnitTests
|
||||
|
||||
// convert to incoming message
|
||||
NetIncomingMessage im = Program.CreateIncomingMessage(om.PeekDataBuffer(), om.LengthBits);
|
||||
if (im.Data == null || im.Data.Length == 0)
|
||||
throw new NetException("bad im!");
|
||||
|
||||
im.Decrypt(algo);
|
||||
|
||||
if (im.LengthBits != trueLen)
|
||||
if (im.Data == null || im.Data.Length == 0 || im.LengthBits != trueLen)
|
||||
throw new NetException("Length fail");
|
||||
|
||||
if (im.ReadString() != "Hallon")
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace UnitTests
|
||||
catch (NetException nex)
|
||||
{
|
||||
if (nex.Message != "This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently")
|
||||
throw nex;
|
||||
throw;
|
||||
}
|
||||
|
||||
peer.Shutdown("bye");
|
||||
|
||||
Reference in New Issue
Block a user