Skip to content

Commit

Permalink
fix: custom exceptions fwk/vs/core https://learn.microsoft.com/en-gb/…
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisMcKee committed Jan 2, 2025
1 parent 14a9dde commit 016d1d2
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 28 deletions.
62 changes: 46 additions & 16 deletions src/BCrypt.Net/BcryptAuthenticationException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System.Runtime.Serialization;
using System;
using System.Runtime.Serialization;

namespace BCryptNet
{
/// <inheritdoc />
#if NETFRAMEWORK
/// <summary>Exception for signalling hash validation errors. </summary>
[Serializable]
public class BcryptAuthenticationException : Exception
public sealed class BcryptAuthenticationException : Exception
{
/// <inheritdoc />
/// <summary>Default constructor. </summary>
/// <summary>
/// Default Constructor
/// </summary>
protected BcryptAuthenticationException()
{
}
Expand All @@ -18,22 +20,50 @@ protected BcryptAuthenticationException(SerializationInfo info, StreamingContext
{
}

/// <inheritdoc />
/// <summary>Initializes a new instance of <see cref="BcryptAuthenticationException" />.</summary>
/// <param name="message">The message.</param>
public BcryptAuthenticationException(string message)
: base(message)
/// <summary>
/// Initializes a new instance of <see cref="BcryptAuthenticationException" />.
/// </summary>
/// <param name="message"></param>
public BcryptAuthenticationException(string message) : base(message)
{
}

/// <inheritdoc />
/// <summary>Initializes a new instance of <see cref="BcryptAuthenticationException" />.</summary>
/// <param name="message"> The message.</param>
/// <param name="innerException">The inner exception.</param>
public BcryptAuthenticationException(string message, Exception innerException)
: base(message, innerException)
/// <summary>
/// Initializes a new instance of <see cref="BcryptAuthenticationException" />.
/// </summary>
/// <param name="message"></param>
/// <param name="innerException"></param>
public BcryptAuthenticationException(string message, Exception innerException) : base(message, innerException)
{
}
}
#else
/// <summary>Exception for signalling hash validation errors. </summary>
public sealed class BcryptAuthenticationException : Exception
{
/// <summary>
/// Default Constructor
/// </summary>
public BcryptAuthenticationException()
{
}

/// <summary>
/// Initializes a new instance of <see cref="BcryptAuthenticationException" />.
/// </summary>
/// <param name="message"></param>
public BcryptAuthenticationException(string message) : base(message)
{
}

/// <summary>
/// Initializes a new instance of <see cref="BcryptAuthenticationException" />.
/// </summary>
/// <param name="message"></param>
/// <param name="innerException"></param>
public BcryptAuthenticationException(string message, Exception innerException) : base(message, innerException)
{
}
}
#endif
}
32 changes: 32 additions & 0 deletions src/BCrypt.Net/HashInformationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace BCryptNet
{
#if NETFRAMEWORK
/// <summary>
/// Exception used to signal errors that occur during use of the hash information methods
/// </summary>
Expand Down Expand Up @@ -37,4 +38,35 @@ public HashInformationException(string message, Exception innerException) : base
{
}
}
#else
/// <summary>
/// Exception used to signal errors that occur during use of the hash information methods
/// </summary>
public sealed class HashInformationException : Exception
{
/// <summary>
/// Default Constructor
/// </summary>
public HashInformationException()
{
}

/// <summary>
/// Initializes a new instance of <see cref="HashInformationException" />.
/// </summary>
/// <param name="message"></param>
public HashInformationException(string message) : base(message)
{
}

/// <summary>
/// Initializes a new instance of <see cref="HashInformationException" />.
/// </summary>
/// <param name="message"></param>
/// <param name="innerException"></param>
public HashInformationException(string message, Exception innerException) : base(message, innerException)
{
}
}
#endif
}
69 changes: 57 additions & 12 deletions src/BCrypt.Net/SaltParseException.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,73 @@
using System;
using System.Runtime.Serialization;

namespace BCryptNet
{
/// <summary>Exception for signalling parse errors during salt checks. </summary>
public class SaltParseException : Exception
#if NETFRAMEWORK
/// <summary>
/// Exception used to signal errors that occur during use salt parsing
/// </summary>
[Serializable]
public sealed class SaltParseException : Exception
{
/// <summary>Default constructor. </summary>
/// <summary>
/// Default Constructor
/// </summary>
protected SaltParseException()
{
}

/// <inheritdoc />
protected SaltParseException(SerializationInfo info, StreamingContext streamingContext) : base(info, streamingContext)
{
}

/// <summary>
/// Initializes a new instance of <see cref="SaltParseException" />.
/// </summary>
/// <param name="message"></param>
public SaltParseException(string message) : base(message)
{
}

/// <summary>
/// Initializes a new instance of <see cref="SaltParseException" />.
/// </summary>
/// <param name="message"></param>
/// <param name="innerException"></param>
public SaltParseException(string message, Exception innerException) : base(message, innerException)
{
}
}
#else
/// <summary>
/// Exception used to signal errors that occur during salt parsing
/// </summary>
public sealed class SaltParseException : Exception
{
/// <summary>
/// Default Constructor
/// </summary>
public SaltParseException()
{
}

/// <summary>Initializes a new instance of <see cref="SaltParseException" />.</summary>
/// <param name="message">The message.</param>
public SaltParseException(string message)
: base(message)
/// <summary>
/// Initializes a new instance of <see cref="SaltParseException" />.
/// </summary>
/// <param name="message"></param>
public SaltParseException(string message) : base(message)
{
}

/// <summary>Initializes a new instance of <see cref="SaltParseException" />.</summary>
/// <param name="message"> The message.</param>
/// <param name="innerException">The inner exception.</param>
public SaltParseException(string message, Exception innerException)
: base(message, innerException)
/// <summary>
/// Initializes a new instance of <see cref="SaltParseException" />.
/// </summary>
/// <param name="message"></param>
/// <param name="innerException"></param>
public SaltParseException(string message, Exception innerException) : base(message, innerException)
{
}
}
#endif
}

0 comments on commit 016d1d2

Please sign in to comment.