Skip to content

Commit fc35ff4

Browse files
authored
Merge pull request #14475 from dotnet/merges/main-to-release/dev17.5
Merge main to release/dev17.5
2 parents ad3033a + 3794da3 commit fc35ff4

File tree

3 files changed

+27
-46
lines changed

3 files changed

+27
-46
lines changed

src/Compiler/AbstractIL/ilsign.fs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,6 @@ let signStream stream keyBlob =
297297
let signature = createSignature hash keyBlob KeyType.KeyPair
298298
patchSignature stream peReader signature
299299

300-
let signFile fileName keyBlob =
301-
use fs =
302-
FileSystem.OpenFileForWriteShim(fileName, FileMode.Open, FileAccess.ReadWrite)
303-
304-
signStream fs keyBlob
305-
306300
let signatureSize (pk: byte[]) =
307301
if pk.Length < 25 then
308302
raise (CryptographicException(getResourceString (FSComp.SR.ilSignInvalidPKBlob ())))
@@ -339,18 +333,9 @@ let signerOpenKeyPairFile filePath =
339333

340334
let signerGetPublicKeyForKeyPair (kp: keyPair) : pubkey = getPublicKeyForKeyPair kp
341335

342-
let signerGetPublicKeyForKeyContainer (_kcName: keyContainerName) : pubkey =
343-
raise (NotImplementedException("signerGetPublicKeyForKeyContainer is not yet implemented"))
344-
345-
let signerCloseKeyContainer (_kc: keyContainerName) : unit =
346-
raise (NotImplementedException("signerCloseKeyContainer is not yet implemented"))
347-
348336
let signerSignatureSize (pk: pubkey) : int = signatureSize pk
349337

350-
let signerSignFileWithKeyPair (fileName: string) (kp: keyPair) : unit = signFile fileName kp
351-
352-
let signerSignFileWithKeyContainer (_fileName: string) (_kcName: keyContainerName) : unit =
353-
raise (NotImplementedException("signerSignFileWithKeyContainer is not yet implemented"))
338+
let signerSignStreamWithKeyPair stream keyBlob = signStream stream keyBlob
354339

355340
let failWithContainerSigningUnsupportedOnThisPlatform () =
356341
failwith (FSComp.SR.containerSigningUnsupportedOnThisPlatform () |> snd)
@@ -371,13 +356,6 @@ type ILStrongNameSigner =
371356
static member OpenKeyPairFile s = KeyPair(signerOpenKeyPairFile s)
372357
static member OpenKeyContainer s = KeyContainer s
373358

374-
member s.Close() =
375-
match s with
376-
| PublicKeySigner _
377-
| PublicKeyOptionsSigner _
378-
| KeyPair _ -> ()
379-
| KeyContainer _ -> failWithContainerSigningUnsupportedOnThisPlatform ()
380-
381359
member s.IsFullySigned =
382360
match s with
383361
| PublicKeySigner _ -> false
@@ -412,9 +390,9 @@ type ILStrongNameSigner =
412390
| KeyPair kp -> pkSignatureSize (signerGetPublicKeyForKeyPair kp)
413391
| KeyContainer _ -> failWithContainerSigningUnsupportedOnThisPlatform ()
414392

415-
member s.SignFile file =
393+
member s.SignStream stream =
416394
match s with
417395
| PublicKeySigner _ -> ()
418396
| PublicKeyOptionsSigner _ -> ()
419-
| KeyPair kp -> signerSignFileWithKeyPair file kp
397+
| KeyPair kp -> signerSignStreamWithKeyPair stream kp
420398
| KeyContainer _ -> failWithContainerSigningUnsupportedOnThisPlatform ()

src/Compiler/AbstractIL/ilsign.fsi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
88
module internal FSharp.Compiler.AbstractIL.StrongNameSign
99

10+
open System
11+
open System.IO
12+
1013
//---------------------------------------------------------------------
1114
// Strong name signing
1215
//---------------------------------------------------------------------
@@ -17,8 +20,7 @@ type ILStrongNameSigner =
1720
static member OpenPublicKey: byte[] -> ILStrongNameSigner
1821
static member OpenKeyPairFile: string -> ILStrongNameSigner
1922
static member OpenKeyContainer: string -> ILStrongNameSigner
20-
member Close: unit -> unit
2123
member IsFullySigned: bool
2224
member PublicKey: byte[]
2325
member SignatureSize: int
24-
member SignFile: string -> unit
26+
member SignStream: Stream -> unit

src/Compiler/AbstractIL/ilwrite.fs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3714,9 +3714,22 @@ let writePdb (
37143714
// Used to capture the pdb file bytes in the case we're generating in-memory
37153715
let mutable pdbBytes = None
37163716

3717+
let signImage () =
3718+
// Sign the binary. No further changes to binary allowed past this point!
3719+
match signer with
3720+
| None -> ()
3721+
| Some s ->
3722+
use fs = reopenOutput()
3723+
try
3724+
s.SignStream fs
3725+
with exn ->
3726+
failwith ($"Warning: A call to SignFile failed ({exn.Message})")
3727+
reportTime showTimes "Signing Image"
3728+
37173729
// Now we've done the bulk of the binary, do the PDB file and fixup the binary.
37183730
match pdbfile with
3719-
| None -> ()
3731+
| None -> signImage ()
3732+
37203733
| Some pdbfile ->
37213734
let idd =
37223735
match pdbInfoOpt with
@@ -3766,28 +3779,14 @@ let writePdb (
37663779
os2.BaseStream.Seek (int64 (textV2P i.iddChunk.addr), SeekOrigin.Begin) |> ignore
37673780
if i.iddChunk.size < i.iddData.Length then failwith "Debug data area is not big enough. Debug info may not be usable"
37683781
writeBytes os2 i.iddData
3782+
reportTime showTimes "Finalize PDB"
3783+
signImage ()
37693784
os2.Dispose()
37703785
with exn ->
37713786
failwith ("Error while writing debug directory entry: " + exn.Message)
37723787
(try os2.Dispose(); FileSystem.FileDeleteShim outfile with _ -> ())
37733788
reraise()
37743789

3775-
reportTime showTimes "Finalize PDB"
3776-
3777-
// Sign the binary. No further changes to binary allowed past this point!
3778-
match signer with
3779-
| None -> ()
3780-
| Some s ->
3781-
try
3782-
s.SignFile outfile
3783-
s.Close()
3784-
with exn ->
3785-
failwith ("Warning: A call to SignFile failed ("+exn.Message+")")
3786-
(try s.Close() with _ -> ())
3787-
(try FileSystem.FileDeleteShim outfile with _ -> ())
3788-
()
3789-
3790-
reportTime showTimes "Signing Image"
37913790
pdbBytes
37923791

37933792
type options =
@@ -4531,7 +4530,7 @@ let writeBinaryFiles (options: options, modul, normalizeAssemblyRefs) =
45314530
reraise()
45324531

45334532
let reopenOutput () =
4534-
FileSystem.OpenFileForWriteShim(options.outfile, FileMode.Open, FileAccess.Write, FileShare.Read)
4533+
FileSystem.OpenFileForWriteShim(options.outfile, FileMode.Open, FileAccess.ReadWrite, FileShare.Read)
45354534

45364535
writePdb (options.dumpDebugInfo,
45374536
options.showTimes,
@@ -4561,7 +4560,9 @@ let writeBinaryInMemory (options: options, modul, normalizeAssemblyRefs) =
45614560
let pdbData, pdbInfoOpt, debugDirectoryChunk, debugDataChunk, debugChecksumPdbChunk, debugEmbeddedPdbChunk, debugDeterministicPdbChunk, textV2P, _mappings =
45624561
writeBinaryAux(stream, options, modul, normalizeAssemblyRefs)
45634562

4564-
let reopenOutput () = stream
4563+
let reopenOutput () =
4564+
stream.Seek(0, SeekOrigin.Begin) |> ignore
4565+
stream
45654566

45664567
let pdbBytes =
45674568
writePdb (options.dumpDebugInfo,

0 commit comments

Comments
 (0)