@@ -58,14 +58,15 @@ private static void WritePEImage(
5858 BlobBuilder ilBuilder ,
5959 MethodDefinitionHandle entryPointHandle ,
6060 Blob mvidFixup = default ( Blob ) ,
61- byte [ ] privateKeyOpt = null )
61+ byte [ ] privateKeyOpt = null ,
62+ bool publicSigned = false )
6263 {
6364 var peBuilder = new ManagedPEBuilder (
6465 entryPointHandle . IsNil ? PEHeaderBuilder . CreateLibraryHeader ( ) : PEHeaderBuilder . CreateExecutableHeader ( ) ,
6566 new MetadataRootBuilder ( metadataBuilder ) ,
6667 ilBuilder ,
6768 entryPoint : entryPointHandle ,
68- flags : CorFlags . ILOnly | ( privateKeyOpt != null ? CorFlags . StrongNameSigned : 0 ) ,
69+ flags : CorFlags . ILOnly | ( privateKeyOpt != null || publicSigned ? CorFlags . StrongNameSigned : 0 ) ,
6970 deterministicIdProvider : content => s_contentId ) ;
7071
7172 var peBlob = new BlobBuilder ( ) ;
@@ -108,7 +109,11 @@ public void BasicValidation()
108109 var ilBuilder = new BlobBuilder ( ) ;
109110 var metadataBuilder = new MetadataBuilder ( ) ;
110111 var entryPoint = BasicValidationEmit ( metadataBuilder , ilBuilder ) ;
111- WritePEImage ( peStream , metadataBuilder , ilBuilder , entryPoint ) ;
112+ WritePEImage ( peStream , metadataBuilder , ilBuilder , entryPoint , publicSigned : true ) ;
113+
114+ peStream . Position = 0 ;
115+ var actualChecksum = new PEHeaders ( peStream ) . PEHeader . CheckSum ;
116+ Assert . Equal ( 0U , actualChecksum ) ;
112117
113118 VerifyPE ( peStream ) ;
114119 }
@@ -124,6 +129,14 @@ public void BasicValidationSigned()
124129 var entryPoint = BasicValidationEmit ( metadataBuilder , ilBuilder ) ;
125130 WritePEImage ( peStream , metadataBuilder , ilBuilder , entryPoint , privateKeyOpt : Misc . KeyPair ) ;
126131
132+ // The expected checksum can be determined by saving the PE stream to a file,
133+ // running "sn -R test.dll KeyPair.snk" and inspecting the resulting binary.
134+ // The re-signed binary should be the same as the original one.
135+ // See https://github.com/dotnet/corefx/issues/25829.
136+ peStream . Position = 0 ;
137+ var actualChecksum = new PEHeaders ( peStream ) . PEHeader . CheckSum ;
138+ Assert . Equal ( 0x0000319cU , actualChecksum ) ;
139+
127140 VerifyPE ( peStream , expectedSignature : new byte [ ]
128141 {
129142 0x58 , 0xD4 , 0xD7 , 0x88 , 0x3B , 0xF9 , 0x19 , 0x9F , 0x3A , 0x55 , 0x8F , 0x1B , 0x88 , 0xBE , 0xA8 , 0x42 ,
0 commit comments