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 bool Complete(StrongNameKeys strongNameKeys, CommonMessageProvider messageProvider, DiagnosticBag diagnostics) { Debug.Assert(_stream != null); Debug.Assert(_emitStreamSignKind != EmitStreamSignKind.SignedWithFile || _tempInfo.HasValue); try { if (_tempInfo.HasValue) { Debug.Assert(_emitStreamSignKind == EmitStreamSignKind.SignedWithFile); 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)); }
/// <summary> /// Signs the <paramref name="filePath"/> value using <paramref name="keys"/>. /// </summary> internal abstract void SignFile(StrongNameKeys keys, string filePath);