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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }