-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add special handeling of too long path's
- Loading branch information
Showing
5 changed files
with
117 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma warning disable SA1512,SA1124 // Single-line comments should not be followed by blank line | ||
|
||
#region No ReShaper | ||
|
||
using System; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using JetBrains.Annotations; | ||
|
||
// ReSharper disable All | ||
// needed because 'JetBrains.Annotations.NotNull' and 'System.Diagnostics.CodeAnalysis.NotNull' collide if this file is compiled with a never version of Unity / C# | ||
using SuppressMessageAttribute = System.Diagnostics.CodeAnalysis.SuppressMessageAttribute; | ||
|
||
// ReSharper restore All | ||
|
||
#endregion | ||
|
||
#pragma warning restore SA1512,SA1124 // Single-line comments should not be followed by blank line | ||
|
||
namespace NugetForUnity.Helper | ||
{ | ||
/// <summary> | ||
/// Helper class for MD5 hashing. | ||
/// </summary> | ||
internal static class Md5HashHelper | ||
{ | ||
/// <summary> | ||
/// Computes the MD5 hash of <paramref name="value" /> and returns it as Base64 string with all chars that are not allowed on file-paths replaced. | ||
/// </summary> | ||
/// <param name="value">The string that is hashed.</param> | ||
/// <returns>The MD5 has of <paramref name="value" /> as a Base64 string with all chars that are not allowed on file-paths replaced.</returns> | ||
/// <exception cref="ArgumentNullException">If <paramref name="value" /> is null or a empty string.</exception> | ||
[SuppressMessage("Design", "CA5351", Justification = "Only use MD5 hash as cache key / not security relevant.")] | ||
[NotNull] | ||
public static string GetFileNameSafeHash([NotNull] string value) | ||
{ | ||
if (string.IsNullOrEmpty(value)) | ||
{ | ||
throw new ArgumentNullException(nameof(value)); | ||
} | ||
|
||
using (var md5 = new MD5CryptoServiceProvider()) | ||
Check warning on line 42 in src/NuGetForUnity/Editor/Helper/Md5HashHelper.cs GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI
Check warning on line 42 in src/NuGetForUnity/Editor/Helper/Md5HashHelper.cs GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI
Check warning on line 42 in src/NuGetForUnity/Editor/Helper/Md5HashHelper.cs GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI
|
||
{ | ||
var data = md5.ComputeHash(Encoding.Default.GetBytes(value)); | ||
return Convert.ToBase64String(data).Replace('+', '-').Replace('/', '_').TrimEnd('='); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters