Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
elantiguamsft committed Oct 25, 2023
1 parent 42ff5b3 commit f2ad998
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions CoseSign1/DetachedSignatureFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private object CreateDetachedSignatureWithChecksInternal(
: bytePayload!.Value.ToArray();
try
{
HashAlgorithmName algoName = SizeToAlgorithm[hash.Length];
HashAlgorithmName algoName = SizeInBytesToAlgorithm[hash.Length];
extendedContentType = ExtendContentType(contentType, algoName);
}
catch (KeyNotFoundException e)
Expand All @@ -416,9 +416,9 @@ private object CreateDetachedSignatureWithChecksInternal(
}

/// <summary>
/// quick lookup of algorithm name based on hash size
/// quick lookup of algorithm name based on size of raw hash in bytes
/// </summary>
private static readonly ConcurrentDictionary<int, HashAlgorithmName> SizeToAlgorithm = new(
private static readonly ConcurrentDictionary<int, HashAlgorithmName> SizeInBytesToAlgorithm = new(
new Dictionary<int, HashAlgorithmName>()
{
{ 16, HashAlgorithmName.MD5 },
Expand Down Expand Up @@ -451,8 +451,9 @@ private object CreateDetachedSignatureWithChecksInternal(
/// Method which produces a mime type extension based on the given content type and hash algorithm name.
/// </summary>
/// <param name="contentType">The content type to append the hash value to if not already appended.</param>
/// <returns></returns>
private string ExtendContentType(string contentType, HashAlgorithmName algorithmName)
/// <param name="algorithmName">The "HashAlgorithmName" to append if not already appended.</param>
/// <returns>A string representing the content type with an appended hash algorithm</returns>
private static string ExtendContentType(string contentType, HashAlgorithmName algorithmName)
{
// extract from the string cache to keep string allocations down.
string extensionMapping = MimeExtensionMap.GetOrAdd(algorithmName.Name, (name) => $"+hash-{name.ToLowerInvariant()}");
Expand Down

0 comments on commit f2ad998

Please sign in to comment.