diff options
author | Jeffrey Stedfast <jestedfa@microsoft.com> | 2019-07-24 18:07:32 +0300 |
---|---|---|
committer | Jeffrey Stedfast <jestedfa@microsoft.com> | 2019-07-26 19:59:34 +0300 |
commit | 701538f3018c08a5ab6406f119a137b0cf83a212 (patch) | |
tree | 91ff5c01cdcc7ef586c04192a08f7656a3e9cce7 /main/src/addins/MonoDevelop.Debugger.VSCodeDebugProtocol | |
parent | 5417bdbef0b796ecc0ef083247a5f01e87331bcb (diff) |
[Debugger] Fixed .NET Core debugger to allow use of SHA256 and MD5 hashes
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/951772
Diffstat (limited to 'main/src/addins/MonoDevelop.Debugger.VSCodeDebugProtocol')
-rw-r--r-- | main/src/addins/MonoDevelop.Debugger.VSCodeDebugProtocol/MonoDevelop.Debugger.VsCodeDebugProtocol/VsCodeStackFrame.cs | 55 |
1 files changed, 44 insertions, 11 deletions
diff --git a/main/src/addins/MonoDevelop.Debugger.VSCodeDebugProtocol/MonoDevelop.Debugger.VsCodeDebugProtocol/VsCodeStackFrame.cs b/main/src/addins/MonoDevelop.Debugger.VSCodeDebugProtocol/MonoDevelop.Debugger.VsCodeDebugProtocol/VsCodeStackFrame.cs index 09930da9ee..ee0c8e77ac 100644 --- a/main/src/addins/MonoDevelop.Debugger.VSCodeDebugProtocol/MonoDevelop.Debugger.VsCodeDebugProtocol/VsCodeStackFrame.cs +++ b/main/src/addins/MonoDevelop.Debugger.VSCodeDebugProtocol/MonoDevelop.Debugger.VsCodeDebugProtocol/VsCodeStackFrame.cs @@ -58,25 +58,58 @@ namespace MonoDevelop.Debugger.VsCodeDebugProtocol this.frameId = frame.Id; } - static byte [] HexToByteArray (string hex) + static byte ToXDigit (char c) + { + if (c >= 'A' && c <= 'F') + return (byte) ((c - 'A') + 10); + + if (c >= 'a' && c <= 'f') + return (byte) ((c - 'a') + 10); + + if (c >= '0' && c <= '9') + return (byte) (c - '0'); + + throw new ArgumentException (); + } + + static byte[] HexToByteArray (string hex) { if (hex.Length % 2 == 1) - throw new ArgumentException (); - byte [] bytes = new byte [hex.Length / 2]; - for (int i = 0; i < bytes.Length; i++) { - bytes [i] = Convert.ToByte (hex.Substring (i * 2, 2), 16); + return null; + + try { + var bytes = new byte[hex.Length / 2]; + for (int i = 0, j = 0; i < bytes.Length; i++, j += 2) { + var x1 = ToXDigit (hex[j]); + var x2 = ToXDigit (hex[j + 1]); + + bytes[i] = (byte) ((x1 << 4) | x2); + } + + return bytes; + } catch { + return null; } - return bytes; } - static byte [] GetHashBytes (Source source) + static byte[] GetHashBytes (Source source) { if (source == null) return null; - var checkSum = source.Checksums.FirstOrDefault (c => c.Algorithm == ChecksumAlgorithm.SHA1); - if (checkSum == null) - return null; - return HexToByteArray (checkSum.ChecksumValue); + + foreach (var checksum in source.Checksums) { + switch (checksum.Algorithm) { + case ChecksumAlgorithm.SHA256: + case ChecksumAlgorithm.SHA1: + case ChecksumAlgorithm.MD5: + var hash = HexToByteArray (checksum.ChecksumValue); + if (hash != null) + return hash; + break; + } + } + + return null; } public override string FullStackframeText { |