Closed zhichao-h closed 1 year ago
Hi @zhichao-h , also great suggestion!
Does this look like a good example for what WolfTpm2Exception
would look like?
[Serializable]
public class WolfTpm2Exception : Exception
{
public int ErrorCode { get; }
public WolfTpm2Exception() { }
public WolfTpm2Exception(string message)
: base(message) { }
public WolfTpm2Exception(string message, Exception inner)
: base(message, inner) { }
public WolfTpm2Exception(string message, int errorCode)
: this(message)
{
ErrorCode = errorCode;
}
}
Thanks, David Garske, wolfSSL
Fixed in PR #224. Marking closed.
The wolftpm.cs bridges the native calls and transparently returns the error codes. This forces the high level code must research the different error returns. This can be hard to use or abuse.
I recommend raise C# Exceptions such as WolfTpmException("message", error_code) when the return code indicates error. So the following code:
should better be implemented as
With this modification, the high level code will not need to get into the details of understanding the error codes from native side.