-
Notifications
You must be signed in to change notification settings - Fork 105
Add parse validation helpers, tests, and docs updates #1436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
|
||
| if (list.Count == 0) | ||
| EnsureCoverageInternal(Assembly.GetExecutingAssembly(), CachedContracts.Select(u => (u.Key, u.Value.DbgInfo))); | ||
| EnsureCoverageInternal(Assembly.GetExecutingAssembly(), CachedContracts.Select(u => (u.Key, u.Value.DbgInfo)), 0.89M); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is not full covered now?
| return valueBytes[0] == (byte)'0' && (valueBytes[1] == (byte)'x' || valueBytes[1] == (byte)'X') ? 2 : 0; | ||
| } | ||
|
|
||
| internal static byte[] ParseHex(byte[] valueBytes, int offset, int expectedLength) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we only use full read, or I miss something? It will be clear a regular ParseHex(byte[] data)
| if (value >= (byte)'0' && value <= (byte)'9') return (byte)(value - (byte)'0'); | ||
| if (value >= (byte)'a' && value <= (byte)'f') return (byte)(value - (byte)'a' + 10); | ||
| if (value >= (byte)'A' && value <= (byte)'F') return (byte)(value - (byte)'A' + 10); | ||
| throw new FormatException("Invalid hex character."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| throw new FormatException("Invalid hex character."); | |
| throw new FormatException("Invalid hex character: ${value}."); |
| internal static byte[] ParseHex(byte[] valueBytes, int offset, int expectedLength) | ||
| { | ||
| int hexLength = valueBytes.Length - offset; | ||
| if (hexLength != expectedLength * 2) | ||
| throw new FormatException("Invalid hex length."); | ||
|
|
||
| byte[] result = new byte[expectedLength]; | ||
| for (int i = 0; i < expectedLength; i++) | ||
| { | ||
| byte high = FromHexByte(valueBytes[offset + i * 2]); | ||
| byte low = FromHexByte(valueBytes[offset + i * 2 + 1]); | ||
| result[i] = (byte)((high << 4) | low); | ||
| } | ||
|
|
||
| return result; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| internal static byte[] ParseHex(byte[] valueBytes, int offset, int expectedLength) | |
| { | |
| int hexLength = valueBytes.Length - offset; | |
| if (hexLength != expectedLength * 2) | |
| throw new FormatException("Invalid hex length."); | |
| byte[] result = new byte[expectedLength]; | |
| for (int i = 0; i < expectedLength; i++) | |
| { | |
| byte high = FromHexByte(valueBytes[offset + i * 2]); | |
| byte low = FromHexByte(valueBytes[offset + i * 2 + 1]); | |
| result[i] = (byte)((high << 4) | low); | |
| } | |
| return result; | |
| } | |
| internal static byte[] ParseHex(byte[] valueBytes, int offset, int expectedLength) | |
| { | |
| int hexLength = valueBytes.Length - offset; | |
| if (hexLength != expectedLength * 2) | |
| throw new FormatException("Invalid hex length."); | |
| return Convert.FromHexString(valueBytes.AsSpan()[offset..]); | |
| } |
This is better?
Summary
Testing