Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sutor-aes/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SutorAes
{
class Client
public class Client
{
Guid Id { get; set; }
public string Name { get; set; }
Expand All @@ -16,7 +16,7 @@

RSAEncryptionPadding padding = RSAEncryptionPadding.Pkcs1;

public Client(string _name)

Check warning on line 19 in sutor-aes/Client.cs

View workflow job for this annotation

GitHub Actions / tests

Non-nullable property 'RsaPriv' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 19 in sutor-aes/Client.cs

View workflow job for this annotation

GitHub Actions / tests

Non-nullable property 'RsaPub' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 19 in sutor-aes/Client.cs

View workflow job for this annotation

GitHub Actions / tests

Non-nullable property 'RsaPriv' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 19 in sutor-aes/Client.cs

View workflow job for this annotation

GitHub Actions / tests

Non-nullable property 'RsaPub' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
{
this.Name = _name;
GenerateRSAKeys();
Expand Down
77 changes: 0 additions & 77 deletions sutor-aes/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,82 +11,5 @@ static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}

public static string DecryptString(byte[] cipherText, byte[] key, byte[] iv)
{
if (cipherText == null || cipherText.Length <= 0)
{
throw new ArgumentNullException(nameof(cipherText));
}
if (key == null || key.Length <= 0)
{
throw new ArgumentNullException(nameof(key));
}
if (iv == null || iv.Length <= 0)
{
throw new ArgumentNullException(nameof(iv));
}

string plaintext = null;

using (Aes aesAlg = Aes.Create())
{
aesAlg.Key = key;
aesAlg.IV = iv;

ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);

using (MemoryStream msDecrypt = new MemoryStream(cipherText))
{
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
{
plaintext = srDecrypt.ReadToEnd();
}
}
}
}

return plaintext;
}

public static byte[] EncryptString(string plainText, byte[] key, byte[] iv)
{
if (plainText == null)
{
throw new ArgumentNullException(nameof(plainText));
}
if (key == null || key.Length <= 0)
{
throw new ArgumentNullException(nameof(key));
}
if (iv == null || iv.Length <= 0)
{
throw new ArgumentNullException(nameof(iv));
}

using (Aes aesAlg = Aes.Create())
{
aesAlg.Key = key;
aesAlg.IV = iv;

ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);

using (MemoryStream msEncrypt = new MemoryStream())
{
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
swEncrypt.Write(plainText);
}
}
// Return the encrypted bytes directly without Base64 encoding
return msEncrypt.ToArray();
}
}
}
}

}
39 changes: 39 additions & 0 deletions tests/ClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Text;
using NUnit.Framework;
using SutorAes;

namespace tests;

public class ProgramTests
{
private byte[] _key;
private byte[] _iv;

[SetUp]
public void Setup()
{
_key = new byte[32];
Random random = new Random();
random.NextBytes(_key);

_iv = new byte[16];
random.NextBytes(_iv);
Comment on lines +10 to +21
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_key and _iv are initialized in Setup but never used in this test. Consider removing them to simplify the test fixture.

Suggested change
private byte[] _key;
private byte[] _iv;
[SetUp]
public void Setup()
{
_key = new byte[32];
Random random = new Random();
random.NextBytes(_key);
_iv = new byte[16];
random.NextBytes(_iv);
// Removed unused variables _key and _iv
[SetUp]
public void Setup()
{
// Removed initialization of unused variables _key and _iv

Copilot uses AI. Check for mistakes.
}

[Test]
public void EstablishConnection_SendMessage()
{
string originalText = "This is a test message for encryption and decryption";

Client bob = new Client("Bob");
Client alice = new Client("Alice");

bob.EstablishConnection(alice);

bool recieved = false;
alice.OnMessage((string msg) => recieved = msg == originalText);
bob.SendMessage(alice, originalText);
Assert.That(recieved);
Comment on lines +34 to +37
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable recieved is misspelled; correct it to received.

Suggested change
bool recieved = false;
alice.OnMessage((string msg) => recieved = msg == originalText);
bob.SendMessage(alice, originalText);
Assert.That(recieved);
bool received = false;
alice.OnMessage((string msg) => received = msg == originalText);
bob.SendMessage(alice, originalText);
Assert.That(received);

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion lacks a constraint and will not compile under NUnit. Use Assert.That(received, Is.True) or Assert.IsTrue(received) to explicitly check the boolean.

Suggested change
Assert.That(recieved);
Assert.IsTrue(recieved);

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot is an idiot, this works

}
}
68 changes: 0 additions & 68 deletions tests/CryptTests.cs

This file was deleted.