Skip to content

Commit

Permalink
Strong name sign assemblies
Browse files Browse the repository at this point in the history
closes #911
  • Loading branch information
belav committed Jun 13, 2023
1 parent 7e8b5e3 commit f9ec1cb
Show file tree
Hide file tree
Showing 13 changed files with 435 additions and 24 deletions.
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<PackageVersion Include="CliWrap" Version="3.3.3" />
<PackageVersion Include="DiffEngine" Version="6.5.7" />
<PackageVersion Include="FluentAssertions" Version="5.10.3" />
<PackageVersion Include="Ignore" Version="0.1.42" />
<PackageVersion Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.4.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
Expand Down
Binary file added Nuget/csharpier.snk
Binary file not shown.
2 changes: 2 additions & 0 deletions Src/CSharpier.Benchmarks/CSharpier.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<AssemblyOriginatorKeyFile>../../Nuget/csharpier.snk</AssemblyOriginatorKeyFile>
<SignAssembly>True</SignAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
Expand Down
2 changes: 2 additions & 0 deletions Src/CSharpier.Cli.Tests/CSharpier.Cli.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<AssemblyOriginatorKeyFile>../../Nuget/csharpier.snk</AssemblyOriginatorKeyFile>
<SignAssembly>True</SignAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CliWrap"/>
Expand Down
12 changes: 9 additions & 3 deletions Src/CSharpier.Cli/CSharpier.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
<AssemblyName>dotnet-csharpier</AssemblyName>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<PackAsTool>true</PackAsTool>
<AssemblyOriginatorKeyFile>../../Nuget/csharpier.snk</AssemblyOriginatorKeyFile>
<SignAssembly>True</SignAssembly>
<PublicKey>002400000480000094000000060200000024000052534131000400000100010049d266ea1aeae09c0abfce28b8728314d4e4807126ee8bc56155a7ddc765997ed3522908b469ae133fc49ef0bfa957df36082c1c2e0ec8cdc05a4ca4dbd4e1bea6c17fc1008555e15af13a8fc871a04ffc38f5e60e6203bfaf01d16a2a283b90572ade79135801c1675bf38b7a5a60ec8353069796eb53a26ffdddc9ee1273be</PublicKey>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Ignore" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="System.CommandLine" />
<PackageReference Include="System.IO.Abstractions" />
Expand All @@ -18,8 +20,12 @@
<PackageReference Include="YamlDotNet" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="CSharpier.Tests" />
<InternalsVisibleTo Include="CSharpier.Cli.Tests" />
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>CSharpier.Tests, PublicKey=$(PublicKey)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>CSharpier.Cli.Tests, PublicKey=$(PublicKey)</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<None Include="..\..\logo.png" Pack="true" PackagePath="">
Expand Down
99 changes: 99 additions & 0 deletions Src/CSharpier.Cli/Ignore/Ignore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
namespace Ignore
{
using System.Collections.Generic;
using System.Linq;

public class Ignore
{
private readonly List<IgnoreRule> rules;

/// <summary>
/// Initializes a new instance of the <see cref="Ignore"/> class.
/// </summary>
public Ignore()
{
rules = new List<IgnoreRule>();
OriginalRules = new List<string>();
}

/// <summary>
/// Gets the list of the original rules passed in to the class ctor.
/// </summary>
public List<string> OriginalRules { get; }

/// <summary>
/// Adds the given pattern to this <see cref="Ignore"/> instance.
/// </summary>
/// <param name="rule">Gitignore style pattern string.</param>
/// <returns>Current instance of <see cref="Ignore"/>.</returns>
public Ignore Add(string rule)
{
OriginalRules.Add(rule);
rules.Add(new IgnoreRule(rule));
return this;
}

/// <summary>
/// Adds the given pattern list to this <see cref="Ignore"/> instance.
/// </summary>
/// <param name="patterns">List of gitignore style pattern strings.</param>
/// <returns>Current instance of <see cref="Ignore"/>.</returns>
public Ignore Add(IEnumerable<string> patterns)
{
var patternList = patterns.ToList();
OriginalRules.AddRange(patternList);
patternList.ForEach(pattern => rules.Add(new IgnoreRule(pattern)));
return this;
}

/// <summary>
/// Test whether the input path is ignored as per the rules
/// specified in the class ctor.
/// </summary>
/// <param name="path">File path to consider.</param>
/// <returns>A boolean indicating if the path is ignored.</returns>
public bool IsIgnored(string path)
{
var ignore = IsPathIgnored(path);

return ignore;
}


public IEnumerable<string> Filter(IEnumerable<string> paths)
{
var filteredPaths = new List<string>();
foreach (var path in paths)
{
var ignore = IsPathIgnored(path);
if (ignore == false)
{
filteredPaths.Add(path);
}
}

return filteredPaths;
}

private bool IsPathIgnored(string path)
{
var ignore = false;
foreach (var rule in rules)
{
if (rule.Negate)
{
if (ignore && rule.IsMatch(path))
{
ignore = false;
}
}
else if (!ignore && rule.IsMatch(path))
{
ignore = true;
}
}

return ignore;
}
}
}
82 changes: 82 additions & 0 deletions Src/CSharpier.Cli/Ignore/IgnoreRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
namespace Ignore
{
using System.Collections.Generic;
using System.Text.RegularExpressions;

public class IgnoreRule
{
private static readonly List<Replacer> Replacers = new List<Replacer>
{
ReplacerStash.TrailingSpaces,
ReplacerStash.EscapedSpaces,
ReplacerStash.LiteralDot,
ReplacerStash.LiteralPlus,
// probably not needed
// ReplacerStash.Metacharacters,
ReplacerStash.QuestionMark,
ReplacerStash.NonLeadingSingleStar,
ReplacerStash.LeadingSingleStar,
ReplacerStash.LeadingDoubleStar,
// probably not needed
// ReplacerStash.MetacharacterSlashAfterLeadingSlash,
ReplacerStash.MiddleDoubleStar,
ReplacerStash.LeadingSlash,
ReplacerStash.TrailingDoubleStar,
ReplacerStash.OtherDoubleStar,
ReplacerStash.MiddleSlash,
ReplacerStash.TrailingSlash,
ReplacerStash.NoSlash,
ReplacerStash.NoTrailingSlash,
ReplacerStash.Ending
};

private readonly Regex? parsedRegex;

/// <summary>
/// Initializes a new instance of the <see cref="IgnoreRule"/> class.
/// Parses the given pattern as per .gitignore spec.
/// https://git-scm.com/docs/gitignore#_pattern_format.
/// </summary>
/// <param name="pattern">Pattern to parse.</param>
public IgnoreRule(string pattern)
{
// A blank line matches no files, so it can serve as a separator for readability.
if (string.IsNullOrEmpty(pattern.Trim()))
{
return;
}

// A line starting with # serves as a comment. Put a backslash ("\") in front of the first hash for patterns that begin with a hash.
if (pattern.StartsWith("#"))
{
return;
}

// Account for escaped # and !, remove the leading backslash.
// Also either a pattern will start with \ or with !
if (pattern.StartsWith("\\!") || pattern.StartsWith("\\#"))
{
pattern = pattern.Substring(1);
}
else if (pattern.StartsWith("!"))
{
Negate = true;
pattern = pattern.Substring(1);
}

foreach (var replacer in Replacers)
{
pattern = replacer.Invoke(pattern);
}

parsedRegex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
}

public bool Negate { get; }

public bool IsMatch(string input)
{
return parsedRegex != null && parsedRegex.IsMatch(input);
}
}
}
1 change: 1 addition & 0 deletions Src/CSharpier.Cli/Ignore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
From https://github.com/goelhardik/ignore because it was not strong name signed.
36 changes: 36 additions & 0 deletions Src/CSharpier.Cli/Ignore/Replacer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Ignore
{
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

/// <summary>
/// A holder for a regex and replacer function.
/// The function is invoked if the input matches the regex.
/// </summary>
public class Replacer
{
private readonly string name;

private readonly Regex regex;

private readonly MatchEvaluator matchEvaluator;

public Replacer(string name, Regex regex, Func<Match, string> replacer)
{
this.name = name;
this.regex = regex;
matchEvaluator = new MatchEvaluator(replacer);
}

public string Invoke(string pattern)
{
return regex.Replace(pattern, matchEvaluator);
}

public override string ToString()
{
return name;
}
}
}
Loading

0 comments on commit f9ec1cb

Please sign in to comment.