Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom committed Jul 19, 2019
1 parent b51a0a4 commit 6ab1b07
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
58 changes: 23 additions & 35 deletions src/absil/ilwritepdb.fs
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,22 @@ type idd =

/// The specified Hash algorithm to use on portable pdb files.
type HashAlgorithm =
| Sha1
| Sha256
| Sha1
| Sha256

// Document checksum algorithms
let guidSha1 = Guid("ff1816ec-aa5e-4d10-87f7-6f4963833460")
let guidSha2 = Guid("8829d00f-11b8-4213-878b-770e8597ac16")

// If the FIPS algorithm policy is enabled on the computer (e.g., for US government employees and contractors)
// then obtaining the MD5 implementation in BCL will throw.
// In this case, catch the failure, and not set a checksum.
let checkSum (url: string) (checksumAlgorithm: HashAlgorithm) =
try
use file = FileSystem.FileStreamReadShim url
let guid, alg =
match checksumAlgorithm with
| HashAlgorithm.Sha1 -> guidSha1, System.Security.Cryptography.SHA1.Create() :> System.Security.Cryptography.HashAlgorithm
| HashAlgorithm.Sha256 -> guidSha2, System.Security.Cryptography.SHA256.Create() :> System.Security.Cryptography.HashAlgorithm
use file = FileSystem.FileStreamReadShim url
let guid, alg =
match checksumAlgorithm with
| HashAlgorithm.Sha1 -> guidSha1, System.Security.Cryptography.SHA1.Create() :> System.Security.Cryptography.HashAlgorithm
| HashAlgorithm.Sha256 -> guidSha2, System.Security.Cryptography.SHA256.Create() :> System.Security.Cryptography.HashAlgorithm

let checkSum = alg.ComputeHash file
Some (guid, checkSum)
with _ -> None
let checkSum = alg.ComputeHash file
guid, checkSum

//---------------------------------------------------------------------
// Portable PDB Writer
Expand Down Expand Up @@ -335,27 +330,19 @@ let generatePortablePdb (embedAllSource: bool) (embedSourceList: string list) (s
metadata.SetCapacity(TableIndex.Document, docLength)
for doc in docs do
let handle =
match checkSum doc.File checksumAlgorithm with
| Some (hashAlg, checkSum) ->
let dbgInfo =
(serializeDocumentName doc.File,
metadata.GetOrAddGuid hashAlg,
metadata.GetOrAddBlob(checkSum.ToImmutableArray()),
metadata.GetOrAddGuid corSymLanguageTypeId) |> metadata.AddDocument
match includeSource doc.File with
| None -> ()
| Some blob ->
metadata.AddCustomDebugInformation(DocumentHandle.op_Implicit dbgInfo,
metadata.GetOrAddGuid embeddedSourceId,
metadata.GetOrAddBlob blob) |> ignore
dbgInfo
| None ->
let dbgInfo =
(serializeDocumentName doc.File,
metadata.GetOrAddGuid(System.Guid.Empty),
metadata.GetOrAddBlob(ImmutableArray<byte>.Empty),
metadata.GetOrAddGuid corSymLanguageTypeId) |> metadata.AddDocument
dbgInfo
let hashAlg, checkSum = checkSum doc.File checksumAlgorithm
let dbgInfo =
(serializeDocumentName doc.File,
metadata.GetOrAddGuid hashAlg,
metadata.GetOrAddBlob(checkSum.ToImmutableArray()),
metadata.GetOrAddGuid corSymLanguageTypeId) |> metadata.AddDocument
match includeSource doc.File with
| None -> ()
| Some blob ->
metadata.AddCustomDebugInformation(DocumentHandle.op_Implicit dbgInfo,
metadata.GetOrAddGuid embeddedSourceId,
metadata.GetOrAddBlob blob) |> ignore
dbgInfo
index.Add(doc.File, handle)

if not (String.IsNullOrEmpty sourceLink) then
Expand Down Expand Up @@ -538,6 +525,7 @@ let generatePortablePdb (embedAllSource: bool) (embedSourceList: string list) (s
match checksumAlgorithm with
| HashAlgorithm.Sha1 -> "SHA1", System.Security.Cryptography.SHA1.Create() :> System.Security.Cryptography.HashAlgorithm
| HashAlgorithm.Sha256 -> "SHA256", System.Security.Cryptography.SHA256.Create() :> System.Security.Cryptography.HashAlgorithm

let idProvider: System.Func<IEnumerable<Blob>, BlobContentId> =
let convert (content: IEnumerable<Blob>) =
let contentBytes = content |> Seq.collect (fun c -> c.GetBytes()) |> Array.ofSeq
Expand Down
4 changes: 2 additions & 2 deletions src/absil/ilwritepdb.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ type idd =
iddChunk: BinaryChunk }

type HashAlgorithm =
| Sha1
| Sha256
| Sha1
| Sha256

val generatePortablePdb : embedAllSource: bool -> embedSourceList: string list -> sourceLink: string -> checksumAlgorithm: HashAlgorithm -> showTimes: bool -> info: PdbData -> pathMap:PathMap -> (int64 * BlobContentId * MemoryStream * string * byte[])
val compressPortablePdbStream : uncompressedLength:int64 -> contentId:BlobContentId -> stream:MemoryStream -> (int64 * BlobContentId * MemoryStream)
Expand Down

0 comments on commit 6ab1b07

Please sign in to comment.