Skip to content

Commit

Permalink
Remove unsafe code
Browse files Browse the repository at this point in the history
jbevain committed May 31, 2019
1 parent 6ad97f8 commit da13c6e
Showing 2 changed files with 7 additions and 10 deletions.
1 change: 0 additions & 1 deletion Mono.Cecil.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="Current">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net40</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="ProjectInfo.cs" />
16 changes: 7 additions & 9 deletions Mono.Security.Cryptography/CryptoService.cs
Original file line number Diff line number Diff line change
@@ -132,19 +132,17 @@ public static byte [] ComputeHash (params ByteBuffer [] buffers)
return sha1.Hash;
}

public static unsafe Guid ComputeGuid (byte [] hash)
public static Guid ComputeGuid (byte [] hash)
{
// From corefx/src/System.Reflection.Metadata/src/System/Reflection/Metadata/BlobContentId.cs
Guid guid = default (Guid);
byte* guidPtr = (byte*) &guid;
for (var i = 0; i < 16; i++) {
guidPtr[i] = hash [i];
}
var guid = new byte [16];
Buffer.BlockCopy (hash, 0, guid, 0, 16);

// modify the guid data so it decodes to the form of a "random" guid ala rfc4122
guidPtr [7] = (byte) ((guidPtr [7] & 0x0f) | (4 << 4));
guidPtr [8] = (byte) ((guidPtr [8] & 0x3f) | (2 << 6));
guid [7] = (byte) ((guid [7] & 0x0f) | (4 << 4));
guid [8] = (byte) ((guid [8] & 0x3f) | (2 << 6));

return guid;
return new Guid (guid);
}
}

0 comments on commit da13c6e

Please sign in to comment.