Skip to content

Commit

Permalink
Enhance errors handling
Browse files Browse the repository at this point in the history
  • Loading branch information
duduita committed Oct 31, 2023
1 parent d86416b commit d2a0396
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions source/implementations/f7/Meadow.F7/F7PlatformOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ public int[] GetProcessorUtilization()
return new[] {100 - Core.Interop.Nuttx.meadow_idle_monitor_get_value()};
}


/// <summary>
/// Enum representing different server certificate validation error returns.
/// </summary>
public enum ServerCertificateValidationError
{
InvalidMode = -1,
CannotChangeAfterInitialization = -2
}

/// <inheritdoc/>
public void SetServerCertificateValidationMode(ServerCertificateValidationMode authmode)

Check failure on line 107 in source/implementations/f7/Meadow.F7/F7PlatformOS.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ServerCertificateValidationMode' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 107 in source/implementations/f7/Meadow.F7/F7PlatformOS.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ServerCertificateValidationMode' could not be found (are you missing a using directive or an assembly reference?)
{
Expand All @@ -107,12 +117,24 @@ public void SetServerCertificateValidationMode(ServerCertificateValidationMode a
}

int ret = Core.Interop.Nuttx.mono_mbedtls_set_server_cert_authmode(authModeInt);
if (ret < 0)
if (ret == InvalidMode)
{
string errorMessage = $"Error setting validation mode.";
string errorMessage = $"Invalid validation mode: {authModeInt}";
Resolver.Log.Error($"Invalid validation mode: {authModeInt}");
throw new ArgumentException(errorMessage);
}
else if (ret == CannotChangeAfterInitialization)
{
string errorMessage = $"The server certificate validation mode cannot be changed after the TLS initialization.";
Resolver.Log.Error(errorMessage);
throw new Exception(errorMessage);
}
else
{
string errorMessage = $"Error setting validation mode.";
Resolver.Log.Error(errorMessage);
throw new Exception(errorMessage);
}

Resolver.Log.Trace($"Server certificate validation mode set to {authmode} successfully!");

Expand Down

0 comments on commit d2a0396

Please sign in to comment.