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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

- Multiple functions, such as `generate_key` and `hash_password`, now return a `Result` due to the `rand` library upgrade.

## Added

- C#: Nullable annotations were added for nullable reference types.

### Removed

- Removed `EncryptWithKeyAsString`, `EncryptWithPasswordAsString`, `DecryptWithKeyAsString`, `DecryptWithPasswordAsString`,
- C#: Removed `EncryptWithKeyAsString`, `EncryptWithPasswordAsString`, `DecryptWithKeyAsString`, `DecryptWithPasswordAsString`,
`GenerateAPIKey`.

## [0.9.2] - 2025-01-20
Expand Down
16 changes: 5 additions & 11 deletions wrappers/csharp/src/Argon2Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ internal Argon2Parameters(bool defaultParameters = true)
/// <summary>
/// Gets the size of the raw Argon2 data.
/// </summary>
public static long NativeSize
{
get
{
return Native.GetDefaultArgon2ParametersSizeNative();
}
}
public static long NativeSize => Native.GetDefaultArgon2ParametersSizeNative();

/// <summary>
/// Gets or sets the number of iterations over the memory.
Expand All @@ -62,7 +56,7 @@ public static long NativeSize
/// <summary>
/// Gets or sets the associated data.
/// </summary>
internal byte[] AssociatedData { get; set; }
internal byte[]? AssociatedData { get; set; }

/// <summary>
/// Gets or sets the devolutions crypto version.
Expand All @@ -72,7 +66,7 @@ public static long NativeSize
/// <summary>
/// Gets or sets the salt used by the algorithm.
/// </summary>
internal byte[] Salt { get; set; }
internal byte[]? Salt { get; set; }

/// <summary>
/// Gets or sets the Argon2 variant used by the algorithm.
Expand All @@ -89,7 +83,7 @@ public static long NativeSize
/// </summary>
/// <param name="data">The data to deserialize.</param>
/// <returns>Returns the deserialized parameters.</returns>
public static Argon2Parameters FromByteArray(byte[] data)
public static Argon2Parameters? FromByteArray(byte[]? data)
{
if (data == null)
{
Expand Down Expand Up @@ -281,7 +275,7 @@ public byte[] ToByteArray()
// === Salt Length ===
if (this.Salt == null)
{
this.Salt = Array.Empty<byte>();
this.Salt = [];
}

byte[] saltLength = BitConverter.GetBytes(this.Salt.Length);
Expand Down
16 changes: 5 additions & 11 deletions wrappers/csharp/src/DevolutionsCryptoException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DevolutionsCryptoException : Exception
/// <param name="managedError">The managed error code.</param>
/// <param name="message">The exception message. (Optional).</param>
/// <param name="exception">The managed exception. (Optional).</param>
public DevolutionsCryptoException(ManagedError managedError, string message = null, Exception exception = null) : base(message)
public DevolutionsCryptoException(ManagedError managedError, string? message = null, Exception? exception = null) : base(message)
{
this.ManagedError = managedError;
this.ManagedException = exception;
Expand All @@ -25,7 +25,7 @@ public DevolutionsCryptoException(ManagedError managedError, string message = nu
/// <param name="nativeError">The native error code.</param>
/// <param name="message">The exception message. (Optional).</param>
/// <param name="exception">The managed exception. (Optional).</param>
public DevolutionsCryptoException(NativeError nativeError, string message = null, Exception exception = null) : base(message)
public DevolutionsCryptoException(NativeError nativeError, string? message = null, Exception? exception = null) : base(message)
{
this.NativeError = nativeError;
this.ManagedException = exception;
Expand All @@ -39,7 +39,7 @@ public DevolutionsCryptoException(NativeError nativeError, string message = null
/// <summary>
/// Gets or sets if an unknown exception happens this property will contain it..
/// </summary>
public Exception ManagedException { get; set; }
public Exception? ManagedException { get; set; }

/// <summary>
/// Gets override to add additionnal info in the exception message.
Expand Down Expand Up @@ -81,21 +81,15 @@ public string GetDetailedMessage()
result = "NativeError :\r\n";
result = result + this.NativeError.Value.ToString() + "\r\n";

if (this.Data != null)
{
this.Data["NativeError"] = this.NativeError.Value.ToString();
}
this.Data["NativeError"] = this.NativeError.Value.ToString();
}

if (this.ManagedError != null)
{
result = "ManagedError : \r\n";
result = result + this.ManagedError.Value.ToString() + "\r\n";

if (this.Data != null)
{
this.Data["ManagedError"] = this.ManagedError.Value.ToString();
}
this.Data["ManagedError"] = this.ManagedError.Value.ToString();

if (this.ManagedException != null)
{
Expand Down
16 changes: 5 additions & 11 deletions wrappers/csharp/src/EncryptionStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@ public class EncryptionStream
: Stream, IDisposable
{
private UIntPtr _native_ptr = UIntPtr.Zero;
private readonly int _chunkLength;
private readonly int _tagLength;
private bool _finalBlockTransformed = false;
private readonly bool _leaveOpen;

public int ChunkLength { get { return _chunkLength; } }
public int ChunkLength { get; }

public int TagLength { get { return _tagLength; } }
public int TagLength { get; }

public bool HasFlushedFinalBlock
{
get { return _finalBlockTransformed; }
}
public bool HasFlushedFinalBlock => _finalBlockTransformed;

private readonly byte[] _inputBuffer;

Expand All @@ -33,7 +28,7 @@ public EncryptionStream(byte[] key, byte[] aad, int chunkLength, bool asymmetric

public EncryptionStream(byte[] key, byte[] aad, int chunkLength, bool asymmetric, int version, Stream outputStream, bool leaveOpen)
{
_chunkLength = chunkLength;
ChunkLength = chunkLength;
_outputStream = outputStream;
_leaveOpen = leaveOpen;

Expand All @@ -51,7 +46,7 @@ public EncryptionStream(byte[] key, byte[] aad, int chunkLength, bool asymmetric
Utils.HandleError(tagSize);
}

_tagLength = (int)tagSize;
TagLength = (int)tagSize;

_inputBuffer = new byte[chunkLength];
}
Expand Down Expand Up @@ -108,7 +103,6 @@ public void FlushFinalBlock()

public override void Flush()
{
return;
}

public override int Read(byte[] buffer, int offset, int count)
Expand Down
2 changes: 1 addition & 1 deletion wrappers/csharp/src/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public enum ManagedError

/// <summary>
/// Error when the native library cannot be loaded
/// </summery>
/// </summary>
NativeLibraryLoad,

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions wrappers/csharp/src/KeyPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class KeyPair
/// <summary>
/// Gets or sets the private key.
/// </summary>
public byte[] PrivateKey { get; set; }
public byte[]? PrivateKey { get; set; }

/// <summary>
/// Gets the private key as base 64 string.
/// </summary>
public string PrivateKeyString
public string? PrivateKeyString
{
get
{
Expand All @@ -31,12 +31,12 @@ public string PrivateKeyString
/// <summary>
/// Gets or sets the public key.
/// </summary>
public byte[] PublicKey { get; set; }
public byte[]? PublicKey { get; set; }

/// <summary>
/// Gets the public key key as base 64 string.
/// </summary>
public string PublicKeyString
public string? PublicKeyString
{
get
{
Expand Down
Loading