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))); } // 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 (IOException ex) { return(new StrongNameKeys(StrongNameKeys.GetContainerError(messageProvider, keyContainerName, ex.Message))); } } return(new StrongNameKeys(keyPair, publicKey, container, keyFilePath)); }
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)); }