AsnDecoder.ReadNamedBitListValue Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
ReadNamedBitListValue(ReadOnlySpan<Byte>, AsnEncodingRules, Type, Int32, Nullable<Asn1Tag>) |
Reads a NamedBitList from |
ReadNamedBitListValue<TFlagsEnum>(ReadOnlySpan<Byte>, AsnEncodingRules, Int32, Nullable<Asn1Tag>) |
Reads a NamedBitList from |
ReadNamedBitListValue(ReadOnlySpan<Byte>, AsnEncodingRules, Type, Int32, Nullable<Asn1Tag>)
- Source:
- AsnDecoder.NamedBitList.cs
- Source:
- AsnDecoder.NamedBitList.cs
- Source:
- AsnDecoder.NamedBitList.cs
Reads a NamedBitList from source
with a specified tag under the specified encoding rules, converting it to the [FlagsAttribute] enum specified by flagsEnumType
.
public static Enum ReadNamedBitListValue (ReadOnlySpan<byte> source, System.Formats.Asn1.AsnEncodingRules ruleSet, Type flagsEnumType, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default);
static member ReadNamedBitListValue : ReadOnlySpan<byte> * System.Formats.Asn1.AsnEncodingRules * Type * int * Nullable<System.Formats.Asn1.Asn1Tag> -> Enum
Public Shared Function ReadNamedBitListValue (source As ReadOnlySpan(Of Byte), ruleSet As AsnEncodingRules, flagsEnumType As Type, ByRef bytesConsumed As Integer, Optional expectedTag As Nullable(Of Asn1Tag) = Nothing) As Enum
Parameters
- source
- ReadOnlySpan<Byte>
The buffer containing encoded data.
- ruleSet
- AsnEncodingRules
The encoding constraints to use when interpreting the data.
- flagsEnumType
- Type
Type object representing the destination type.
- bytesConsumed
- Int32
When this method returns, the total number of bytes for the encoded value. This parameter is treated as uninitialized.
The tag to check for before reading, or null
for the default tag (Universal 3).
Returns
The NamedBitList value converted to a flagsEnumType
.
Exceptions
ruleSet
is not defined.
The next value does not have the correct tag.
-or-
The length encoding is not valid under the current encoding rules.
-or-
The contents are not valid under the current encoding rules.
-or-
The encoded value is too big to fit in a flagsEnumType
value.
flagsEnumType
is not an enum type.
-or-
flagsEnumType
was not declared with FlagsAttribute
-or-
expectedTag
.TagClass is Universal, but expectedTag
.TagValue is not correct for the method.
flagsEnumType
is null
Applies to
ReadNamedBitListValue<TFlagsEnum>(ReadOnlySpan<Byte>, AsnEncodingRules, Int32, Nullable<Asn1Tag>)
- Source:
- AsnDecoder.NamedBitList.cs
- Source:
- AsnDecoder.NamedBitList.cs
- Source:
- AsnDecoder.NamedBitList.cs
Reads a NamedBitList from source
with a specified tag under the specified encoding rules, converting it to the [FlagsAttribute] enum specified by TFlagsEnum
.
public static TFlagsEnum ReadNamedBitListValue<TFlagsEnum> (ReadOnlySpan<byte> source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default) where TFlagsEnum : Enum;
static member ReadNamedBitListValue : ReadOnlySpan<byte> * System.Formats.Asn1.AsnEncodingRules * int * Nullable<System.Formats.Asn1.Asn1Tag> -> 'FlagsEnum (requires 'FlagsEnum :> Enum)
Public Shared Function ReadNamedBitListValue(Of TFlagsEnum As Enum) (source As ReadOnlySpan(Of Byte), ruleSet As AsnEncodingRules, ByRef bytesConsumed As Integer, Optional expectedTag As Nullable(Of Asn1Tag) = Nothing) As TFlagsEnum
Type Parameters
- TFlagsEnum
Destination enum type.
Parameters
- source
- ReadOnlySpan<Byte>
The buffer containing encoded data.
- ruleSet
- AsnEncodingRules
The encoding constraints to use when interpreting the data.
- bytesConsumed
- Int32
When this method returns, the total number of bytes for the encoded value. This parameter is treated as uninitialized.
The tag to check for before reading, or null
for the default tag (Universal 3).
Returns
The NamedBitList value converted to a TFlagsEnum
.
Exceptions
ruleSet
is not defined.
The next value does not have the correct tag.
-or-
The length encoding is not valid under the current encoding rules.
-or-
The contents are not valid under the current encoding rules.
-or-
The encoded value is too big to fit in a TFlagsEnum
value.
TFlagsEnum
is not an enum type.
-or-
TFlagsEnum
was not declared with FlagsAttribute
-or-
expectedTag
.TagClass is Universal, but expectedTag
.TagValue is not correct for the method.
Remarks
The bit alignment performed by this method is to interpret the most significant bit in the first byte of the value as the least significant bit in TFlagsEnum
, with bits increasing in value until the least significant bit of the first byte, proceeding with the most significant bit of the second byte, and so on. Under this scheme, the following ASN.1 type declaration and C# enumeration can be used together:
KeyUsage ::= BIT STRING {
digitalSignature (0),
nonRepudiation (1),
keyEncipherment (2),
dataEncipherment (3),
keyAgreement (4),
keyCertSign (5),
cRLSign (6),
encipherOnly (7),
decipherOnly (8) }
[Flags]
enum KeyUsage
{
None = 0, DigitalSignature = 1 << (0),
NonRepudiation = 1 << (1),
KeyEncipherment = 1 << (2),
DataEncipherment = 1 << (3),
KeyAgreement = 1 << (4),
KeyCertSign = 1 << (5),
CrlSign = 1 << (6),
EncipherOnly = 1 << (7),
DecipherOnly = 1 << (8),
}
While the example here uses the KeyUsage NamedBitList from RFC 3280 (4.2.1.3), the example enum uses values that are different from X509KeyUsageFlags.