diff --git a/src/absil/ilwritepdb.fs b/src/absil/ilwritepdb.fs index 01248622f48..5e013cc2ba1 100644 --- a/src/absil/ilwritepdb.fs +++ b/src/absil/ilwritepdb.fs @@ -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 @@ -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.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 @@ -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, BlobContentId> = let convert (content: IEnumerable) = let contentBytes = content |> Seq.collect (fun c -> c.GetBytes()) |> Array.ofSeq diff --git a/src/absil/ilwritepdb.fsi b/src/absil/ilwritepdb.fsi index d96b40170e1..748e178a461 100644 --- a/src/absil/ilwritepdb.fsi +++ b/src/absil/ilwritepdb.fsi @@ -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)