提交 440b3961 编写于 作者: A Andy Gocke

Respond to PR comments

上级 5811385c
......@@ -7216,6 +7216,15 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to Public sign was specified and requires a public key, but no public key was specified.
/// </summary>
internal static string ERR_PublicSignNoKey {
get {
return ResourceManager.GetString("ERR_PublicSignNoKey", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The range variable &apos;{0}&apos; has already been declared.
/// </summary>
......
......@@ -3794,6 +3794,9 @@ You should consider suppressing the warning only if you're sure that you don't w
<data name="ERR_SignButNoPrivateKey" xml:space="preserve">
<value>Key file '{0}' is missing the private key needed for signing</value>
</data>
<data name="ERR_PublicSignNoKey" xml:space="preserve">
<value>Public sign was specified and requires a public key, but no public key was specified</value>
</data>
<data name="WRN_DelaySignButNoKey" xml:space="preserve">
<value>Delay signing was specified and requires a public key, but no public key was specified</value>
</data>
......
......@@ -420,6 +420,24 @@ public class C {}
Assert.Equal(CorFlags.ILOnly | CorFlags.StrongNameSigned, metadata.Module.PEReaderOpt.PEHeaders.CorHeader.Flags);
}
private void VerifySignedBitSetAfterEmit(Compilation comp)
{
var outStrm = new MemoryStream();
var emitResult = comp.Emit(outStrm);
Assert.True(emitResult.Success);
outStrm.Position = 0;
// Verify that the sign bit is set
using (var reader = new PEReader(outStrm))
{
Assert.True(reader.HasMetadata);
var flags = reader.PEHeaders.CorHeader.Flags;
Assert.True(flags.HasFlag(CorFlags.StrongNameSigned));
}
}
[Fact]
public void SnkFile_PublicSign()
{
......@@ -437,20 +455,7 @@ public void SnkFile_PublicSign()
Assert.False(comp.IsRealSigned);
Assert.NotNull(comp.Options.CryptoKeyFile);
var outStrm = new MemoryStream();
var emitResult = comp.Emit(outStrm);
Assert.True(emitResult.Success);
outStrm.Position = 0;
// Verify that the sign bit is set
using (var reader = new PEReader(outStrm))
{
Assert.True(reader.HasMetadata);
var flags = reader.PEHeaders.CorHeader.Flags;
Assert.True(flags.HasFlag(CorFlags.StrongNameSigned));
}
VerifySignedBitSetAfterEmit(comp);
}
[Fact]
......@@ -470,20 +475,7 @@ public void PublicKeyFile_PublicSign()
Assert.False(comp.IsRealSigned);
Assert.NotNull(comp.Options.CryptoKeyFile);
var outStrm = new MemoryStream();
var emitResult = comp.Emit(outStrm);
Assert.True(emitResult.Success);
outStrm.Position = 0;
// Verify that the sign bit is set
using (var reader = new PEReader(outStrm))
{
Assert.True(reader.HasMetadata);
var flags = reader.PEHeaders.CorHeader.Flags;
Assert.True(flags.HasFlag(CorFlags.StrongNameSigned));
}
VerifySignedBitSetAfterEmit(comp);
}
[Fact]
......@@ -507,23 +499,9 @@ public class C {}",
Assert.False(comp.IsRealSigned);
Assert.NotNull(comp.Options.CryptoKeyFile);
var outStrm = new MemoryStream();
var emitResult = comp.Emit(outStrm);
Assert.True(emitResult.Success);
outStrm.Position = 0;
// Verify that the sign bit is set
using (var reader = new PEReader(outStrm))
{
Assert.True(reader.HasMetadata);
var flags = reader.PEHeaders.CorHeader.Flags;
Assert.True(flags.HasFlag(CorFlags.StrongNameSigned));
}
VerifySignedBitSetAfterEmit(comp);
}
[Fact]
public void KeyContainerNoSNProvider_PublicSign()
{
......@@ -555,20 +533,7 @@ public void KeyContainerDesktopProvider_PublicSign()
Assert.False(comp.IsRealSigned);
Assert.NotNull(comp.Options.CryptoKeyContainer);
var outStrm = new MemoryStream();
var emitResult = comp.Emit(outStrm);
Assert.True(emitResult.Success);
outStrm.Position = 0;
// Verify that the sign bit is set
using (var reader = new PEReader(outStrm))
{
Assert.True(reader.HasMetadata);
var flags = reader.PEHeaders.CorHeader.Flags;
Assert.True(flags.HasFlag(CorFlags.StrongNameSigned));
}
VerifySignedBitSetAfterEmit(comp);
}
[Fact]
......@@ -585,8 +550,24 @@ public void PublicSignAndDelaySign()
comp.VerifyDiagnostics(
// error CS7102: Compilation options 'PublicSign' and 'DelaySign' can't both be specified at the same time.
Diagnostic(ErrorCode.ERR_MutuallyExclusiveOptions).WithArguments("PublicSign", "DelaySign").WithLocation(1, 1));
Assert.True(comp.Options.PublicSign);
Assert.True(comp.Options.DelaySign);
}
[Fact]
public void PublicSignNoKey()
{
var comp = CreateCompilationWithMscorlib("public class C {}",
options: TestOptions.ReleaseDll
.WithPublicSign(true));
comp.VerifyDiagnostics(
// error CS8102: Public signing was specified and requires a public key, but no public key was specified.
Diagnostic(ErrorCode.ERR_PublicSignButNoKey).WithLocation(1, 1) );
Assert.True(comp.Options.PublicSign);
Assert.True(comp.Assembly.PublicKey.IsDefaultOrEmpty);
}
[Fact]
public void PublicKeyFromOptions_InvalidCompilationOptions()
......
......@@ -1680,6 +1680,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
ERR_InterpolatedStringFactoryError = 37251
ERR_DebugEntryPointNotSourceMethodDefinition = 37252
ERR_InvalidPathMap = 37253
ERR_PublicSignNoKey = 37254
ERR_LastPlusOne
......
......@@ -1184,6 +1184,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
diagnostics.Add(ERRID.WRN_DelaySignButNoKey, NoLocation.Singleton)
End If
If DeclaringCompilation.Options.PublicSign AndAlso Not Identity.HasPublicKey Then
diagnostics.Add(ERRID.ERR_PublicSignNoKey, NoLocation.Singleton)
End If
' If the options and attributes applied on the compilation imply real signing,
' but we have no private key to sign it with report an error.
' Note that if public key is set and delay sign is off we do OSS signing, which doesn't require private key.
......
......@@ -1664,7 +1664,9 @@ End Class
</file>
</compilation>, options:=options
)
comp.VerifyDiagnostics()
comp.VerifyDiagnostics(Diagnostic(ERRID.ERR_PublicSignNoKey).WithLocation(1, 1))
Assert.True(comp.Options.PublicSign)
Assert.True(comp.Assembly.PublicKey.IsDefaultOrEmpty)
End Sub
<Fact>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册