public static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, ReadOnlyMemory<byte> rebind, out X509ExtensionAsn decoded) { decoded = default; AsnValueReader sequenceReader = reader.ReadSequence(expectedTag); AsnValueReader defaultReader; ReadOnlySpan<byte> rebindSpan = rebind.Span; int offset; ReadOnlySpan<byte> tmpSpan; decoded.ExtnId = sequenceReader.ReadObjectIdentifier(); if (sequenceReader.HasData && sequenceReader.PeekTag().HasSameClassAndValue(Asn1Tag.Boolean)) { decoded.Critical = sequenceReader.ReadBoolean(); } else { defaultReader = new AsnValueReader(DefaultCritical, AsnEncodingRules.DER); decoded.Critical = defaultReader.ReadBoolean(); } if (sequenceReader.TryReadPrimitiveOctetStringBytes(out tmpSpan)) { decoded.ExtnValue = rebindSpan.Overlaps(tmpSpan, out offset) ? rebind.Slice(offset, tmpSpan.Length) : tmpSpan.ToArray(); } else { decoded.ExtnValue = sequenceReader.ReadOctetString(); } sequenceReader.ThrowIfNotEmpty(); }
public bool ReadBoolean(Asn1Tag expectedTag) { AsnValueReader valueReader = OpenValueReader(); bool ret = valueReader.ReadBoolean(expectedTag); valueReader.MatchSlice(ref _data); return(ret); }
static X509ExtensionAsn() { X509ExtensionAsn decoded = default; AsnValueReader reader; reader = new AsnValueReader(DefaultCritical, AsnEncodingRules.DER); decoded.Critical = reader.ReadBoolean(); reader.ThrowIfNotEmpty(); }