-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch DirectoryControl to use AsnWriter, AsnDecoder (#101512)
- Loading branch information
1 parent
2300123
commit b5ea456
Showing
26 changed files
with
990 additions
and
532 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
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
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
18 changes: 0 additions & 18 deletions
18
...Services.Protocols/src/System/DirectoryServices/Protocols/Interop/SortKeyInterop.Linux.cs
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
...rvices.Protocols/src/System/DirectoryServices/Protocols/Interop/SortKeyInterop.Windows.cs
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
...ectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/SortKeyInterop.cs
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...ryServices.Protocols/src/System/DirectoryServices/Protocols/common/AsnWriterExtensions.cs
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,36 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Formats.Asn1; | ||
using System.Text; | ||
|
||
namespace System.DirectoryServices.Protocols | ||
{ | ||
internal static class AsnWriterExtensions | ||
{ | ||
public static void WriteStringAsOctetString(this AsnWriter writer, string value, Encoding stringEncoding, Asn1Tag? tag = null) | ||
{ | ||
// A typical stack allocation threshold would be 256 bytes. A higher threshold has been chosen because an LdapString can be | ||
// used to serialize server names. A server name is defined by RF1035, which specifies that a label in a domain name should | ||
// be < 64 characters. If a server name is specified as an FQDN, this will be at least three labels in an AD environment - | ||
// up to 192 characters. Doubling this to allow for Unicode encoding, then rounding to the nearest power of two yields 512. | ||
const int StackAllocationThreshold = 512; | ||
|
||
if (!string.IsNullOrEmpty(value)) | ||
{ | ||
int octetStringLength = stringEncoding.GetByteCount(value); | ||
// Allocate space on the stack. There's a modest codegen advantage to a constant-value stackalloc. | ||
Span<byte> tmpValue = octetStringLength <= StackAllocationThreshold | ||
? stackalloc byte[StackAllocationThreshold].Slice(0, octetStringLength) | ||
: new byte[octetStringLength]; | ||
|
||
stringEncoding.GetBytes(value, tmpValue); | ||
writer.WriteOctetString(tmpValue, tag); | ||
} | ||
else | ||
{ | ||
writer.WriteOctetString([], tag); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.