internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, CommonMessageProvider messageProvider) { var keyPair = default(ImmutableArray <byte>); var publicKey = default(ImmutableArray <byte>); string container = null; if (!string.IsNullOrEmpty(keyFilePath)) { return(CommonCreateKeys(FileSystem, keyFilePath, _keyFileSearchPaths, messageProvider)); } else if (!string.IsNullOrEmpty(keyContainerName)) { try { ReadKeysFromContainer(keyContainerName, out publicKey); container = keyContainerName; } catch (ClrStrongNameMissingException) { return(new StrongNameKeys(StrongNameKeys.GetContainerError(messageProvider, keyContainerName, new CodeAnalysisResourcesLocalizableErrorArgument(nameof(CodeAnalysisResources.AssemblySigningNotSupported))))); } catch (Exception ex) { return(new StrongNameKeys(StrongNameKeys.GetContainerError(messageProvider, keyContainerName, ex.Message))); } } return(new StrongNameKeys(keyPair, publicKey, null, container, keyFilePath)); }
internal override void SignFile(StrongNameKeys keys, string filePath) { Debug.Assert(string.IsNullOrEmpty(keys.KeyFilePath) != string.IsNullOrEmpty(keys.KeyContainer)); if (!string.IsNullOrEmpty(keys.KeyFilePath)) { Sign(filePath, keys.KeyPair); } else { Sign(filePath, keys.KeyContainer); } }
internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, CommonMessageProvider messageProvider) { ImmutableArray <byte> keyPair = default(ImmutableArray <byte>); ImmutableArray <byte> publicKey = default(ImmutableArray <byte>); string container = null; if (!string.IsNullOrEmpty(keyFilePath)) { try { string resolvedKeyFile = ResolveStrongNameKeyFile(keyFilePath); if (resolvedKeyFile == null) { throw new FileNotFoundException(CodeAnalysisResources.FileNotFound, keyFilePath); } Debug.Assert(PathUtilities.IsAbsolute(resolvedKeyFile)); ImmutableArray <byte> fileContent = ImmutableArray.Create(ReadAllBytes(resolvedKeyFile)); return(StrongNameKeys.CreateHelper(fileContent, keyFilePath)); } catch (Exception ex) { return(new StrongNameKeys(StrongNameKeys.GetKeyFileError(messageProvider, keyFilePath, ex.Message))); } // it turns out that we don't need IClrStrongName to retrieve a key file, // so there's no need for a catch of ClrStrongNameMissingException in this case } else if (!string.IsNullOrEmpty(keyContainerName)) { try { ReadKeysFromContainer(keyContainerName, out publicKey); container = keyContainerName; } catch (ClrStrongNameMissingException) { return(new StrongNameKeys(StrongNameKeys.GetContainerError(messageProvider, keyContainerName, new CodeAnalysisResourcesLocalizableErrorArgument(nameof(CodeAnalysisResources.AssemblySigningNotSupported))))); } catch (Exception ex) { return(new StrongNameKeys(StrongNameKeys.GetContainerError(messageProvider, keyContainerName, ex.Message))); } } return(new StrongNameKeys(keyPair, publicKey, container, keyFilePath)); }
internal bool Complete(StrongNameKeys strongNameKeys, CommonMessageProvider messageProvider, DiagnosticBag diagnostics) { RoslynDebug.Assert(_stream != null); RoslynDebug.Assert(_emitStreamSignKind != EmitStreamSignKind.SignedWithFile || _tempInfo.HasValue); try { if (_tempInfo.HasValue) { RoslynDebug.Assert(_emitStreamSignKind == EmitStreamSignKind.SignedWithFile); RoslynDebug.Assert(_strongNameProvider is object); var(tempStream, tempFilePath) = _tempInfo.GetValueOrDefault(); try { // Dispose the temp stream to ensure all of the contents are written to // disk. tempStream.Dispose(); _strongNameProvider.SignFile(strongNameKeys, tempFilePath); using (var tempFileStream = new FileStream(tempFilePath, FileMode.Open)) { tempFileStream.CopyTo(_stream); } } catch (DesktopStrongNameProvider.ClrStrongNameMissingException) { diagnostics.Add(StrongNameKeys.GetError(strongNameKeys.KeyFilePath, strongNameKeys.KeyContainer, new CodeAnalysisResourcesLocalizableErrorArgument(nameof(CodeAnalysisResources.AssemblySigningNotSupported)), messageProvider)); return(false); } catch (IOException ex) { diagnostics.Add(StrongNameKeys.GetError(strongNameKeys.KeyFilePath, strongNameKeys.KeyContainer, ex.Message, messageProvider)); return(false); } } } finally { Close(); } return(true); }
internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, bool hasCounterSignature, CommonMessageProvider messageProvider) { var keyPair = default(ImmutableArray <byte>); var publicKey = default(ImmutableArray <byte>); string container = null; if (!string.IsNullOrEmpty(keyFilePath)) { try { string resolvedKeyFile = ResolveStrongNameKeyFile(keyFilePath, FileSystem, _keyFileSearchPaths); if (resolvedKeyFile == null) { return(new StrongNameKeys(StrongNameKeys.GetKeyFileError(messageProvider, keyFilePath, CodeAnalysisResources.FileNotFound))); } Debug.Assert(PathUtilities.IsAbsolute(resolvedKeyFile)); var fileContent = ImmutableArray.Create(FileSystem.ReadAllBytes(resolvedKeyFile)); return(StrongNameKeys.CreateHelper(fileContent, keyFilePath, hasCounterSignature)); } catch (Exception ex) { return(new StrongNameKeys(StrongNameKeys.GetKeyFileError(messageProvider, keyFilePath, ex.Message))); } } else if (!string.IsNullOrEmpty(keyContainerName)) { try { ReadKeysFromContainer(keyContainerName, out publicKey); container = keyContainerName; } catch (ClrStrongNameMissingException) { return(new StrongNameKeys(StrongNameKeys.GetContainerError(messageProvider, keyContainerName, new CodeAnalysisResourcesLocalizableErrorArgument(nameof(CodeAnalysisResources.AssemblySigningNotSupported))))); } catch (Exception ex) { return(new StrongNameKeys(StrongNameKeys.GetContainerError(messageProvider, keyContainerName, ex.Message))); } } return(new StrongNameKeys(keyPair, publicKey, privateKey: null, container, keyFilePath, hasCounterSignature)); }
internal StrongNameKeys CommonCreateKeys(StrongNameFileSystem fileSystem, string keyFilePath, ImmutableArray <string> keyFileSearchPaths, CommonMessageProvider messageProvider) { try { string resolvedKeyFile = fileSystem.ResolveStrongNameKeyFile(keyFilePath, keyFileSearchPaths); if (resolvedKeyFile == null) { return(new StrongNameKeys(StrongNameKeys.GetKeyFileError(messageProvider, keyFilePath, CodeAnalysisResources.FileNotFound))); } Debug.Assert(PathUtilities.IsAbsolute(resolvedKeyFile)); var fileContent = ImmutableArray.Create(fileSystem.ReadAllBytes(resolvedKeyFile)); return(StrongNameKeys.CreateHelper(fileContent, keyFilePath)); } catch (Exception ex) { return(new StrongNameKeys(StrongNameKeys.GetKeyFileError(messageProvider, keyFilePath, ex.Message))); } }
internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, CommonMessageProvider messageProvider) { var keyPair = default(ImmutableArray <byte>); var publicKey = default(ImmutableArray <byte>); string container = null; if (!string.IsNullOrEmpty(keyFilePath)) { try { string resolvedKeyFile = ResolveStrongNameKeyFile(keyFilePath); if (resolvedKeyFile == null) { throw new FileNotFoundException(CodeAnalysisResources.FileNotFound, keyFilePath); } Debug.Assert(PathUtilities.IsAbsolute(resolvedKeyFile)); var fileContent = ImmutableArray.Create(ReadAllBytes(resolvedKeyFile)); return(StrongNameKeys.CreateHelper(fileContent, keyFilePath)); } catch (IOException ex) { return(new StrongNameKeys(StrongNameKeys.GetKeyFileError(messageProvider, keyFilePath, ex.Message))); } } else if (!string.IsNullOrEmpty(keyContainerName)) { try { ReadKeysFromContainer(keyContainerName, out publicKey); container = keyContainerName; } catch (IOException ex) { return(new StrongNameKeys(StrongNameKeys.GetContainerError(messageProvider, keyContainerName, ex.Message))); } } return(new StrongNameKeys(keyPair, publicKey, container, keyFilePath)); }
/// <exception cref="IOException"></exception> internal override void SignAssembly(StrongNameKeys keys, Stream inputStream, Stream outputStream) { Debug.Assert(inputStream is TempFileStream); var tempStream = (TempFileStream)inputStream; string assemblyFilePath = tempStream.Path; tempStream.DisposeUnderlyingStream(); if (keys.KeyContainer != null) { Sign(assemblyFilePath, keys.KeyContainer); } else { Sign(assemblyFilePath, keys.KeyPair); } using (var fileToSign = PortableShim.FileStream.Create(assemblyFilePath, PortableShim.FileMode.Open)) { fileToSign.CopyTo(outputStream); } }
internal virtual void SignStream(StrongNameKeys keys, Stream inputStream, Stream outputStream) { throw new NotSupportedException(); }
/// <exception cref="IOException"></exception> internal override void SignAssembly(StrongNameKeys keys, Stream inputStream, Stream outputStream) { Debug.Assert(inputStream is TempFileStream); var tempStream = (TempFileStream)inputStream; string assemblyFilePath = tempStream.Name; tempStream.DisposeUnderlyingStream(); if (keys.KeyContainer != null) { Sign(assemblyFilePath, keys.KeyContainer); } else { Sign(assemblyFilePath, keys.KeyPair); } using (var fileToSign = new FileStream(assemblyFilePath, FileMode.Open)) { fileToSign.CopyTo(outputStream); } }
internal abstract void SignAssembly(StrongNameKeys keys, Stream inputStream, Stream outputStream);
/// <summary> /// Signs the <paramref name="filePath"/> value using <paramref name="keys"/>. /// </summary> internal abstract void SignFile(StrongNameKeys keys, string filePath);