Respond to PR feedback

上级 b3511fcf
......@@ -3,6 +3,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection.PortableExecutable;
using Microsoft.CodeAnalysis.Interop;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
......@@ -16,7 +18,20 @@ public abstract partial class Compilation
internal enum EmitStreamSignKind
{
None,
/// <summary>
/// This form of signing occurs in memory using the <see cref="PEBuilder"/> APIs. This is the default
/// form of signing and will be used when a strong name key is provided in a file on disk.
/// </summary>
SignedWithBulider,
/// <summary>
/// This form of signing occurs using the <see cref="IClrStrongName"/> COM APIs. This form of signing
/// requires the unsigned PE to be written to disk before it can be signed (typically by writing it
/// out to the %TEMP% folder). This signing is used when the key in a key container, the signing
/// requires a counter signature or customers opted in via the UseLegacyStrongNameProvider feature
/// flag.
/// </summary>
SignedWithFile,
}
......@@ -34,7 +49,7 @@ internal sealed class EmitStream
/// <summary>
/// The <see cref="Stream"/> that is being emitted into. This value should _never_ be
/// Dispose. It is either returned from the <see cref="EmitStreamProvider"/> instance in
/// disposed. It is either returned from the <see cref="EmitStreamProvider"/> instance in
/// which case it is owned by that. Or it is just an alias for the value that is stored
/// in <see cref="_tempInfo"/> in which case it will be disposed from there.
/// </summary>
......@@ -83,7 +98,6 @@ private Stream CreateStream(DiagnosticBag diagnostics)
_stream = _emitStreamProvider.GetOrCreateStream(diagnostics);
if (_stream == null)
{
Debug.Assert(diagnostics.HasAnyErrors());
return null;
}
......@@ -95,22 +109,24 @@ private Stream CreateStream(DiagnosticBag diagnostics)
{
Debug.Assert(_strongNameProvider != null);
Stream tempStream;
string tempFilePath;
try
{
var fileSystem = _strongNameProvider.FileSystem;
Func<string, Stream> streamConstructor = path => fileSystem.CreateFileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
var tempDir = fileSystem.GetTempPath();
var tempFilePath = Path.Combine(tempDir, Guid.NewGuid().ToString("N"));
var tempStream = FileUtilities.CreateFileStreamChecked(streamConstructor, tempFilePath);
_tempInfo = (tempStream, tempFilePath);
return tempStream;
tempFilePath = Path.Combine(tempDir, Guid.NewGuid().ToString("N"));
tempStream = FileUtilities.CreateFileStreamChecked(streamConstructor, tempFilePath);
}
catch (IOException e)
{
throw new Cci.PeWritingException(e);
}
_tempInfo = (tempStream, tempFilePath);
return tempStream;
}
else
{
......@@ -121,11 +137,12 @@ private Stream CreateStream(DiagnosticBag diagnostics)
internal bool Complete(StrongNameKeys strongNameKeys, CommonMessageProvider messageProvider, DiagnosticBag diagnostics)
{
Debug.Assert(_stream != null);
Debug.Assert(_emitStreamSignKind != EmitStreamSignKind.SignedWithFile || _tempInfo.HasValue);
if (_tempInfo.HasValue)
{
Debug.Assert(_emitStreamSignKind == EmitStreamSignKind.SignedWithFile);
var (tempStream, tempFilePath) = _tempInfo.Value;
var (tempStream, tempFilePath) = _tempInfo.GetValueOrDefault();
try
{
......
......@@ -1658,7 +1658,7 @@ internal void SetupWin32Resources(CommonPEModuleBuilder moduleBeingBuilt, Stream
/// 2. Write the unsigned PE to disk and use CLR COM APIs to sign.
/// The preferred method is #1 as it's more efficient and more resilient (no reliance on %TEMP%). But
/// we must continue to support #2 as it's the only way to do the following:
/// - Access private keys stored in a key
/// - Access private keys stored in a key container
/// - Do proper counter signature verification for AssemblySignatureKey attributes
/// </summary>
internal bool SignUsingBuilder =>
......@@ -2732,11 +2732,9 @@ internal void EnsureAnonymousTypeTemplates(CancellationToken cancellationToken)
return false;
}
if (!emitPeStream.Complete(StrongNameKeys, MessageProvider, diagnostics) ||
emitMetadataStream?.Complete(StrongNameKeys, MessageProvider, diagnostics) == false)
{
return false;
}
return
emitPeStream.Complete(StrongNameKeys, MessageProvider, diagnostics) &&
(emitMetadataStream?.Complete(StrongNameKeys, MessageProvider, diagnostics) ?? true);
}
finally
{
......@@ -2746,8 +2744,6 @@ internal void EnsureAnonymousTypeTemplates(CancellationToken cancellationToken)
pdbBag?.Free();
metadataDiagnostics?.Free();
}
return true;
}
private static Stream ConditionalGetOrCreateStream(EmitStreamProvider metadataPEStreamProvider, DiagnosticBag metadataDiagnostics)
......
......@@ -29,7 +29,6 @@ public class DesktopStrongNameProvider : StrongNameProvider
// so there's no chance of an API consumer seeing it.
internal sealed class ClrStrongNameMissingException : Exception
{
}
private readonly ImmutableArray<string> _keyFileSearchPaths;
......@@ -37,7 +36,6 @@ internal sealed class ClrStrongNameMissingException : Exception
public DesktopStrongNameProvider(ImmutableArray<string> keyFileSearchPaths) : this(keyFileSearchPaths, StrongNameFileSystem.Instance)
{
}
/// <summary>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册