internal TFlagsEnum ReadNamedBitListValue <TFlagsEnum>(Asn1Tag?expectedTag = default) where TFlagsEnum : Enum { TFlagsEnum ret = AsnDecoder.ReadNamedBitListValue <TFlagsEnum>(_span, _ruleSet, out int consumed, expectedTag); _span = _span.Slice(consumed); return(ret); }
/// <summary> /// Reads the next value as a NamedBitList with a specified tag, converting it to the /// [<see cref="FlagsAttribute"/>] enum specified by <typeparamref name="TFlagsEnum"/>. /// </summary> /// <param name="expectedTag">The tag to check for before reading.</param> /// <typeparam name="TFlagsEnum">Destination enum type</typeparam> /// <returns> /// The NamedBitList value converted to a <typeparamref name="TFlagsEnum"/>. /// </returns> /// <exception cref="AsnContentException"> /// 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 <typeparamref name="TFlagsEnum"/> value. /// </exception> /// <exception cref="ArgumentException"> /// <typeparamref name="TFlagsEnum"/> is not an enum type. /// /// -or- /// /// <typeparamref name="TFlagsEnum"/> was not declared with <see cref="FlagsAttribute"/> /// /// -or- /// /// <paramref name="expectedTag"/>.<see cref="Asn1Tag.TagClass"/> is /// <see cref="TagClass.Universal"/>, but /// <paramref name="expectedTag"/>.<see cref="Asn1Tag.TagValue"/> is not correct for /// the method. /// </exception> /// <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 <typeparamref name="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: /// /// <code> /// KeyUsage ::= BIT STRING { /// digitalSignature (0), /// nonRepudiation (1), /// keyEncipherment (2), /// dataEncipherment (3), /// keyAgreement (4), /// keyCertSign (5), /// cRLSign (6), /// encipherOnly (7), /// decipherOnly (8) } /// </code> /// /// <code> /// [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), /// } /// </code> /// /// Note that while the example here uses the KeyUsage NamedBitList from /// <a href="https://tools.ietf.org/html/rfc3280#section-4.2.1.3">RFC 3280 (4.2.1.3)</a>, /// the example enum uses values thar are different from /// System.Security.Cryptography.X509Certificates.X509KeyUsageFlags. /// </remarks> public TFlagsEnum ReadNamedBitListValue <TFlagsEnum>(Asn1Tag?expectedTag = null) where TFlagsEnum : Enum { TFlagsEnum ret = AsnDecoder.ReadNamedBitListValue <TFlagsEnum>( _data.Span, RuleSet, out int consumed, expectedTag); _data = _data.Slice(consumed); return(ret); }
/// <summary> /// Reads the next value as a NamedBitList with a specified tag, converting it to the /// [<see cref="FlagsAttribute"/>] enum specified by <paramref name="flagsEnumType"/>. /// </summary> /// <param name="expectedTag">The tag to check for before reading.</param> /// <param name="flagsEnumType">Type object representing the destination type.</param> /// <returns> /// The NamedBitList value converted to a <paramref name="flagsEnumType"/>. /// </returns> /// <exception cref="AsnContentException"> /// 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 <paramref name="flagsEnumType"/> value. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="flagsEnumType"/> is not an enum type. /// /// -or- /// /// <paramref name="flagsEnumType"/> was not declared with <see cref="FlagsAttribute"/> /// /// -or- /// /// <paramref name="expectedTag"/>.<see cref="Asn1Tag.TagClass"/> is /// <see cref="TagClass.Universal"/>, but /// <paramref name="expectedTag"/>.<see cref="Asn1Tag.TagValue"/> is not correct for /// the method. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="flagsEnumType"/> is <see langword="null" /> /// </exception> /// <seealso cref="ReadNamedBitListValue{TFlagsEnum}"/> public Enum ReadNamedBitListValue(Type flagsEnumType, Asn1Tag?expectedTag = null) { Enum ret = AsnDecoder.ReadNamedBitListValue( _data.Span, RuleSet, flagsEnumType, out int consumed, expectedTag); _data = _data.Slice(consumed); return(ret); }