Skip to content

Commit 28a1892

Browse files
committed
Fixed some warnings.
1 parent e7ce249 commit 28a1892

File tree

5 files changed

+44
-47
lines changed

5 files changed

+44
-47
lines changed

src/Renci.SshNet/Common/DerData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public DerData()
7474
public DerData(byte[] data)
7575
{
7676
_data = new List<byte>(data);
77-
var dataType = ReadByte();
77+
ReadByte(); // skip dataType
7878
var length = ReadLength();
7979
_lastIndex = _readerIndex + length;
8080
}
@@ -160,7 +160,7 @@ public void Write(bool data)
160160
/// Writes UInt32 data into internal buffer.
161161
/// </summary>
162162
/// <param name="data">UInt32 data to write.</param>
163-
public void Write(UInt32 data)
163+
public void Write(uint data)
164164
{
165165
var bytes = data.GetBytes();
166166
_data.Add(Integer);

src/Renci.SshNet/Messages/Transport/NewKeysMessage.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
3-
namespace Renci.SshNet.Messages.Transport
1+
namespace Renci.SshNet.Messages.Transport
42
{
53
/// <summary>
64
/// Represents SSH_MSG_NEWKEYS message.

src/Renci.SshNet/Security/Cryptography/Ciphers/TwofishCipher.cs

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public TwofishCipher(byte[] key, CipherMode mode, CipherPadding padding)
5151
gMDS3[i] = mX[P_30] | m1[P_30] << 8 | mY[P_30] << 16 | mX[P_30] << 24;
5252
}
5353

54-
k64Cnt = key.Length / 8; // pre-padded ?
54+
_k64Cnt = key.Length / 8; // pre-padded ?
5555
SetKey(key);
5656
}
5757

@@ -68,17 +68,16 @@ public TwofishCipher(byte[] key, CipherMode mode, CipherPadding padding)
6868
/// </returns>
6969
public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
7070
{
71-
int x0 = BytesTo32Bits(inputBuffer, inputOffset) ^ gSubKeys[INPUT_WHITEN];
72-
int x1 = BytesTo32Bits(inputBuffer, inputOffset + 4) ^ gSubKeys[INPUT_WHITEN + 1];
73-
int x2 = BytesTo32Bits(inputBuffer, inputOffset + 8) ^ gSubKeys[INPUT_WHITEN + 2];
74-
int x3 = BytesTo32Bits(inputBuffer, inputOffset + 12) ^ gSubKeys[INPUT_WHITEN + 3];
75-
76-
int k = ROUND_SUBKEYS;
77-
int t0, t1;
78-
for (int r = 0; r < ROUNDS; r += 2)
71+
var x0 = BytesTo32Bits(inputBuffer, inputOffset) ^ gSubKeys[INPUT_WHITEN];
72+
var x1 = BytesTo32Bits(inputBuffer, inputOffset + 4) ^ gSubKeys[INPUT_WHITEN + 1];
73+
var x2 = BytesTo32Bits(inputBuffer, inputOffset + 8) ^ gSubKeys[INPUT_WHITEN + 2];
74+
var x3 = BytesTo32Bits(inputBuffer, inputOffset + 12) ^ gSubKeys[INPUT_WHITEN + 3];
75+
76+
var k = ROUND_SUBKEYS;
77+
for (var r = 0; r < ROUNDS; r += 2)
7978
{
80-
t0 = Fe32_0(gSBox, x0);
81-
t1 = Fe32_3(gSBox, x1);
79+
var t0 = Fe32_0(gSBox, x0);
80+
var t1 = Fe32_3(gSBox, x1);
8281
x2 ^= t0 + t1 + gSubKeys[k++];
8382
x2 = (int)((uint)x2 >> 1) | x2 << 31;
8483
x3 = (x3 << 1 | (int)((uint)x3 >> 31)) ^ (t0 + 2 * t1 + gSubKeys[k++]);
@@ -345,7 +344,7 @@ public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputC
345344
private int[] gSubKeys;
346345
private int[] gSBox;
347346

348-
private int k64Cnt;
347+
private readonly int _k64Cnt;
349348

350349
private void SetKey(byte[] key)
351350
{
@@ -355,12 +354,12 @@ private void SetKey(byte[] key)
355354
var sBoxKeys = new int[MAX_KEY_BITS / 64]; // 4
356355
gSubKeys = new int[TOTAL_SUBKEYS];
357356

358-
if (k64Cnt < 1)
357+
if (_k64Cnt < 1)
359358
{
360359
throw new ArgumentException("Key size less than 64 bits");
361360
}
362361

363-
if (k64Cnt > 4)
362+
if (_k64Cnt > 4)
364363
{
365364
throw new ArgumentException("Key size larger than 256 bits");
366365
}
@@ -371,26 +370,26 @@ private void SetKey(byte[] key)
371370
* maximum of 32 bytes ( 256 bits ), so the range
372371
* for k64Cnt is 1..4
373372
*/
374-
for (int i = 0; i < k64Cnt; i++)
373+
for (var i = 0; i < _k64Cnt; i++)
375374
{
376375
var p = i * 8;
377376

378377
k32e[i] = BytesTo32Bits(key, p);
379378
k32o[i] = BytesTo32Bits(key, p + 4);
380379

381-
sBoxKeys[k64Cnt - 1 - i] = RS_MDS_Encode(k32e[i], k32o[i]);
380+
sBoxKeys[_k64Cnt - 1 - i] = RS_MDS_Encode(k32e[i], k32o[i]);
382381
}
383382

384-
for (int i = 0; i < TOTAL_SUBKEYS / 2; i++)
383+
for (var i = 0; i < TOTAL_SUBKEYS / 2; i++)
385384
{
386385
var q = i * SK_STEP;
387-
var A = F32(q, k32e);
388-
var B = F32(q + SK_BUMP, k32o);
389-
B = B << 8 | (int)((uint)B >> 24);
390-
A += B;
391-
gSubKeys[i * 2] = A;
392-
A += B;
393-
gSubKeys[i * 2 + 1] = A << SK_ROTL | (int)((uint)A >> (32 - SK_ROTL));
386+
var a = F32(q, k32e);
387+
var b = F32(q + SK_BUMP, k32o);
388+
b = b << 8 | (int)((uint)b >> 24);
389+
a += b;
390+
gSubKeys[i * 2] = a;
391+
a += b;
392+
gSubKeys[i * 2 + 1] = a << SK_ROTL | (int)((uint)a >> (32 - SK_ROTL));
394393
}
395394

396395
/*
@@ -405,7 +404,7 @@ private void SetKey(byte[] key)
405404
{
406405
int b1, b2, b3;
407406
var b0 = b1 = b2 = b3 = i;
408-
switch (k64Cnt & 3)
407+
switch (_k64Cnt & 3)
409408
{
410409
case 1:
411410
gSBox[i * 2] = gMDS0[(P[P_01 * 256 + b0] & 0xff) ^ M_b0(k0)];
@@ -447,17 +446,17 @@ private void SetKey(byte[] key)
447446
*/
448447
private int F32(int x, int[] k32)
449448
{
450-
int b0 = M_b0(x);
451-
int b1 = M_b1(x);
452-
int b2 = M_b2(x);
453-
int b3 = M_b3(x);
454-
int k0 = k32[0];
455-
int k1 = k32[1];
456-
int k2 = k32[2];
457-
int k3 = k32[3];
458-
459-
int result = 0;
460-
switch (k64Cnt & 3)
449+
var b0 = M_b0(x);
450+
var b1 = M_b1(x);
451+
var b2 = M_b2(x);
452+
var b3 = M_b3(x);
453+
var k0 = k32[0];
454+
var k1 = k32[1];
455+
var k2 = k32[2];
456+
var k3 = k32[3];
457+
458+
var result = 0;
459+
switch (_k64Cnt & 3)
461460
{
462461
case 1:
463462
result = gMDS0[(P[P_01 * 256 + b0] & 0xff) ^ M_b0(k0)] ^
@@ -499,7 +498,7 @@ private int F32(int x, int[] k32)
499498
*/
500499
private static int RS_MDS_Encode(int k0, int k1)
501500
{
502-
int r = k1;
501+
var r = k1;
503502
// shift 1 byte at a time
504503
r = RS_rem(r);
505504
r = RS_rem(r);
@@ -525,10 +524,10 @@ private static int RS_MDS_Encode(int k0, int k1)
525524
*/
526525
private static int RS_rem(int x)
527526
{
528-
int b = (int)(((uint)x >> 24) & 0xff);
529-
int g2 = ((b << 1) ^
527+
var b = (int)(((uint)x >> 24) & 0xff);
528+
var g2 = ((b << 1) ^
530529
((b & 0x80) != 0 ? RS_GF_FDBK : 0)) & 0xff;
531-
int g3 = ((int)((uint)b >> 1) ^
530+
var g3 = ((int)((uint)b >> 1) ^
532531
((b & 0x01) != 0 ? (int)((uint)RS_GF_FDBK >> 1) : 0)) ^ g2;
533532
return ((x << 8) ^ (g3 << 24) ^ (g2 << 16) ^ (g3 << 8) ^ b);
534533
}

src/Renci.SshNet/Security/Cryptography/Key.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected Key(byte[] data)
4646
throw new ArgumentNullException("data");
4747

4848
var der = new DerData(data);
49-
var version = der.ReadBigInteger();
49+
der.ReadBigInteger(); // skip version
5050

5151
var keys = new List<BigInteger>();
5252
while (!der.IsEndOfData)

src/Renci.SshNet/Sftp/SftpFileSystemInformation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class SftpFileSytemInformation
88
internal const ulong SSH_FXE_STATVFS_ST_RDONLY = 0x1;
99
internal const ulong SSH_FXE_STATVFS_ST_NOSUID = 0x2;
1010

11-
private ulong _flag;
11+
private readonly ulong _flag;
1212

1313
/// <summary>
1414
/// Gets the file system block size.

0 commit comments

Comments
 (0)