Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Compilers/CSharp/Portable/CSharpCompilationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ public CSharpCompilationOptions WithCryptoKeyFile(string path)

public CSharpCompilationOptions WithCryptoPublicKey(ImmutableArray<byte> value)
{
if (value.IsDefault)
{
value = ImmutableArray<byte>.Empty;
}

if (value == this.CryptoPublicKey)
{
return this;
Expand Down Expand Up @@ -526,7 +531,7 @@ internal override void ValidateOptions(ArrayBuilder<Diagnostic> builder)
// (kind == 'arm' || kind == 'appcontainer' || kind == 'winmdobj') &&
// (version >= "6.2")

if (!CryptoPublicKey.IsDefault)
if (!CryptoPublicKey.IsEmpty)
{
if (CryptoKeyFile != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal SourceAssemblySymbol(

_modules = moduleBuilder.ToImmutableAndFree();

if (!compilation.Options.CryptoPublicKey.IsDefault)
if (!compilation.Options.CryptoPublicKey.IsEmpty)
{
_lazyStrongNameKeys = StrongNameKeys.Create(compilation.Options.CryptoPublicKey, MessageProvider.Instance);
}
Expand Down Expand Up @@ -551,7 +551,7 @@ private void ValidateAttributeSemantics(DiagnosticBag diagnostics)
// Consider: should we allow to OSS sign if the key file only contains public key?

if (DeclaringCompilation.Options.OutputKind != OutputKind.NetModule &&
DeclaringCompilation.Options.CryptoPublicKey.IsDefault&&
DeclaringCompilation.Options.CryptoPublicKey.IsEmpty &&
Identity.HasPublicKey&&
!IsDelaySigned &&
!StrongNameKeys.CanSign&&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,17 @@ public void Serializability2()
Assert.Equal(compilationOptions.ConcurrentBuild, deserializedCompilationOptions.ConcurrentBuild);
Assert.Equal(compilationOptions.ExtendedCustomDebugInformation, deserializedCompilationOptions.ExtendedCustomDebugInformation);
}

[Fact]
public void WithCryptoPublicKey()
{
var options = new CSharpCompilationOptions(OutputKind.ConsoleApplication);

Assert.Equal(ImmutableArray<byte>.Empty, options.CryptoPublicKey);
Assert.Equal(ImmutableArray<byte>.Empty, options.WithCryptoPublicKey(default(ImmutableArray<byte>)).CryptoPublicKey);

Assert.Same(options, options.WithCryptoPublicKey(default(ImmutableArray<byte>)));
Assert.Same(options, options.WithCryptoPublicKey(ImmutableArray<byte>.Empty));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected static void CommonGetObjectData(CompilationOptions options, Serializat
info.AddValue(ScriptClassNameString, options.ScriptClassName);
info.AddValue(CryptoKeyContainerString, options.CryptoKeyContainer);
info.AddValue(CryptoKeyFileString, options.CryptoKeyFile);
info.AddValue(CryptoPublicKeyString, options.CryptoPublicKey.IsDefault ? null : options.CryptoPublicKey.ToArray());
info.AddValue(CryptoPublicKeyString, options.CryptoPublicKey.ToArray());
info.AddValue(DelaySignString, options.DelaySign);
info.AddValue(CheckOverflowString, options.CheckOverflow);
info.AddValue(PlatformString, (int)options.Platform);
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/Core/Portable/Compilation/Compilation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal static void CheckSubmissionOptions(CompilationOptions options)
throw new ArgumentException(CodeAnalysisResources.InvalidOutputKindForSubmission, "options");
}

if (options.CryptoKeyContainer != null || options.CryptoKeyFile != null || options.DelaySign != null || !options.CryptoPublicKey.IsDefault)
if (options.CryptoKeyContainer != null || options.CryptoKeyFile != null || options.DelaySign != null || !options.CryptoPublicKey.IsEmpty)
{
throw new ArgumentException(CodeAnalysisResources.InvalidCompilationOptions, "options");
}
Expand Down
9 changes: 6 additions & 3 deletions src/Compilers/Core/Portable/Compilation/CompilationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ public abstract class CompilationOptions
/// </summary>
public string MainTypeName { get; protected set; }

// Note that we avoid using default(ImmutableArray<byte>) for unspecified value since
// such value is currently not serializable by JSON serializer.

/// <summary>
/// Specifies public key used to generate strong name for the compilation assembly, or null of not specified.
/// Specifies public key used to generate strong name for the compilation assembly, or empty of not specified.
/// </summary>
/// <remarks>
/// If specified the values of <see cref="CryptoKeyFile"/> and <see cref="CryptoKeyContainer"/> must be null.
Expand Down Expand Up @@ -220,7 +223,7 @@ internal CompilationOptions(
this.ScriptClassName = scriptClassName ?? WellKnownMemberNames.DefaultScriptClassName;
this.CryptoKeyContainer = cryptoKeyContainer;
this.CryptoKeyFile = cryptoKeyFile;
this.CryptoPublicKey = cryptoPublicKey;
this.CryptoPublicKey = cryptoPublicKey.NullToEmpty();
this.DelaySign = delaySign;
this.CheckOverflow = checkOverflow;
this.Platform = platform;
Expand Down Expand Up @@ -404,7 +407,7 @@ protected bool EqualsHelper(CompilationOptions other)
this.ExtendedCustomDebugInformation == other.ExtendedCustomDebugInformation &&
string.Equals(this.CryptoKeyContainer, other.CryptoKeyContainer, StringComparison.Ordinal) &&
string.Equals(this.CryptoKeyFile, other.CryptoKeyFile, StringComparison.Ordinal) &&
(this.CryptoPublicKey.IsDefault && other.CryptoPublicKey.IsDefault || !this.CryptoPublicKey.IsDefault && !other.CryptoPublicKey.IsDefault && this.CryptoPublicKey.SequenceEqual(other.CryptoPublicKey)) &&
this.CryptoPublicKey.SequenceEqual(other.CryptoPublicKey) &&
this.DelaySign == other.DelaySign &&
this.GeneralDiagnosticOption == other.GeneralDiagnosticOption &&
string.Equals(this.MainTypeName, other.MainTypeName, StringComparison.Ordinal) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols

m_Modules = moduleBuilder.ToImmutableAndFree()

If Not compilation.Options.CryptoPublicKey.IsDefault Then
If Not compilation.Options.CryptoPublicKey.IsEmpty Then
m_lazyStrongNameKeys = StrongNameKeys.Create(compilation.Options.CryptoPublicKey, MessageProvider.Instance)
End If
End Sub
Expand Down Expand Up @@ -1185,7 +1185,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
' Consider: should we allow to OSS sign if the key file only contains public key?

If DeclaringCompilation.Options.OutputKind <> OutputKind.NetModule AndAlso
DeclaringCompilation.Options.CryptoPublicKey.IsDefault AndAlso
DeclaringCompilation.Options.CryptoPublicKey.IsEmpty AndAlso
Identity.HasPublicKey AndAlso
Not IsDelaySigned AndAlso
Not StrongNameKeys.CanSign Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
''' <param name="value">The cryptography key file path. </param>
''' <returns>A new instance of VisualBasicCompilationOptions, if the public key is different; otherwise current instance.</returns>
Public Shadows Function WithCryptoPublicKey(value As ImmutableArray(Of Byte)) As VisualBasicCompilationOptions
If value.IsDefault Then
value = ImmutableArray(Of Byte).Empty
End If

If value = Me.CryptoPublicKey Then
Return Me
End If
Expand Down Expand Up @@ -839,7 +843,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' (kind == 'arm' || kind == 'appcontainer' || kind == 'winmdobj') &&
' (version >= "6.2")

If Not CryptoPublicKey.IsDefault Then
If Not CryptoPublicKey.IsEmpty Then
If CryptoKeyFile IsNot Nothing Then
builder.Add(Diagnostic.Create(MessageProvider.Instance, ERRID.ERR_MutuallyExclusiveOptions, NameOf(CryptoPublicKey), NameOf(CryptoKeyFile)))
End If
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,5 +558,16 @@ BC2042: The options /vbruntime* and /target:module cannot be combined.
deserializedCompilationOptions.ExtendedCustomDebugInformation)
End Sub

<Fact>
Public Sub WithCryptoPublicKey()
Dim options = New VisualBasicCompilationOptions(OutputKind.ConsoleApplication)

Assert.Equal(ImmutableArray(Of Byte).Empty, options.CryptoPublicKey)
Assert.Equal(ImmutableArray(Of Byte).Empty, options.WithCryptoPublicKey(Nothing).CryptoPublicKey)

Assert.Same(options, options.WithCryptoPublicKey(Nothing))
Assert.Same(options, options.WithCryptoPublicKey(ImmutableArray(Of Byte).Empty))
End Sub

End Class
End Namespace