Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
#pragma warning disable SA1028 // ignore whitespace warnings for generated code
using System;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Cryptography.Asn1;

#nullable enable
namespace System.Security.Cryptography.Asn1
{
[StructLayout(LayoutKind.Sequential)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
#pragma warning disable SA1028 // ignore whitespace warnings for generated code
using System;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Cryptography.Asn1;

#nullable enable
namespace System.Security.Cryptography.Asn1
{
[StructLayout(LayoutKind.Sequential)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Security.Cryptography.Asn1;
using System.Text;
Expand All @@ -25,7 +24,7 @@ internal class AppleAsnFormatter : AsnFormatter
{
if (oid == null || string.IsNullOrEmpty(oid.Value))
{
return EncodeHexString(rawData, true);
return EncodeSpaceSeparatedHexString(rawData);
}

switch (oid.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics;
using System.Security.Cryptography;

namespace Internal.Cryptography
Expand All @@ -19,31 +19,19 @@ public string Format(Oid? oid, byte[] rawData, bool multiLine)

protected abstract string? FormatNative(Oid? oid, byte[] rawData, bool multiLine);

protected static string EncodeHexString(byte[] sArray, bool spaceSeparated = false)
protected static string EncodeSpaceSeparatedHexString(byte[] sArray)
{
return EncodeHexString(sArray, 0, (uint)sArray.Length, spaceSeparated);
}
Debug.Assert(sArray != null && sArray.Length != 0);

[return: NotNullIfNotNull("sArray")]
private static string? EncodeHexString(byte[]? sArray, uint start, uint end, bool spaceSeparated)
{
string? result = null;
int length = (sArray.Length * 3) - 1; // two chars per byte, plus 1 space between each

if (sArray != null)
return string.Create(length, sArray, (hexOrder, sArray) =>
{
uint len = (end - start) * 2;
int j = 0;

if (spaceSeparated)
for (int i = 0; i < sArray.Length; i++)
{
// There will be n-1 spaces between n bytes.
len += (end - start - 1);
}

char[] hexOrder = new char[len];

for (uint i = start, j = 0; i < end; i++)
{
if (spaceSeparated && i > start)
if (i != 0)
{
hexOrder[j++] = ' ';
}
Expand All @@ -53,10 +41,8 @@ protected static string EncodeHexString(byte[] sArray, bool spaceSeparated = fal
hexOrder[j++] = HexConverter.ToCharUpper(digit);
}

result = new string(hexOrder);
}

return result;
Debug.Assert(j == hexOrder.Length);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Security.Cryptography;
using System.Text;

Expand All @@ -16,7 +15,7 @@ internal sealed class OpenSslAsnFormatter : AsnFormatter
{
if (oid == null || string.IsNullOrEmpty(oid.Value))
{
return EncodeHexString(rawData, true);
return EncodeSpaceSeparatedHexString(rawData);
}

// The established behavior for this method is to return the native answer, if possible,
Expand Down