internal static void Decode(AsnReader reader, Asn1Tag expectedTag, out Asn1Filter decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } reader.ReadNull(expectedTag); Decode(reader, out decoded); }
internal static void Decode(AsnReader reader, out Asn1Filter decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new Asn1Filter(); Asn1Tag tag = reader.PeekTag(); AsnReader explicitReader; AsnReader collectionReader; if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { // Decode SEQUENCE OF for And { collectionReader = reader.ReadSetOf(new Asn1Tag(TagClass.ContextSpecific, 0)); var tmpList = new List <Asn1Filter>(); Asn1Filter tmpItem; while (collectionReader.HasData) { Asn1Filter.Decode(collectionReader, out tmpItem); tmpList.Add(tmpItem); } decoded.And = tmpList.ToArray(); } } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1))) { // Decode SEQUENCE OF for Or { collectionReader = reader.ReadSetOf(new Asn1Tag(TagClass.ContextSpecific, 1)); var tmpList = new List <Asn1Filter>(); Asn1Filter tmpItem; while (collectionReader.HasData) { Asn1Filter.Decode(collectionReader, out tmpItem); tmpList.Add(tmpItem); } decoded.Or = tmpList.ToArray(); } } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 2))) { explicitReader = reader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 2)); Asn1Filter tmpNot; Asn1Filter.Decode(explicitReader, out tmpNot); decoded.Not = tmpNot; explicitReader.ThrowIfNotEmpty(); } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 3))) { Asn1AttributeValueAssertion tmpEqualityMatch; Asn1AttributeValueAssertion.Decode(reader, new Asn1Tag(TagClass.ContextSpecific, 3), out tmpEqualityMatch); decoded.EqualityMatch = tmpEqualityMatch; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 4))) { Asn1SubstringFilter tmpSubstrings; Asn1SubstringFilter.Decode(reader, new Asn1Tag(TagClass.ContextSpecific, 4), out tmpSubstrings); decoded.Substrings = tmpSubstrings; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 5))) { Asn1AttributeValueAssertion tmpGreaterOrEqual; Asn1AttributeValueAssertion.Decode(reader, new Asn1Tag(TagClass.ContextSpecific, 5), out tmpGreaterOrEqual); decoded.GreaterOrEqual = tmpGreaterOrEqual; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 6))) { Asn1AttributeValueAssertion tmpLessOrEqual; Asn1AttributeValueAssertion.Decode(reader, new Asn1Tag(TagClass.ContextSpecific, 6), out tmpLessOrEqual); decoded.LessOrEqual = tmpLessOrEqual; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 7))) { if (reader.TryGetPrimitiveOctetStringBytes(new Asn1Tag(TagClass.ContextSpecific, 7), out ReadOnlyMemory <byte> tmpPresent)) { decoded.Present = tmpPresent; } else { decoded.Present = reader.ReadOctetString(new Asn1Tag(TagClass.ContextSpecific, 7)); } } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 8))) { Asn1AttributeValueAssertion tmpApproxMatch; Asn1AttributeValueAssertion.Decode(reader, new Asn1Tag(TagClass.ContextSpecific, 8), out tmpApproxMatch); decoded.ApproxMatch = tmpApproxMatch; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 9))) { Asn1MatchingRuleAssertion tmpExtensibleMatch; Asn1MatchingRuleAssertion.Decode(reader, new Asn1Tag(TagClass.ContextSpecific, 9), out tmpExtensibleMatch); decoded.ExtensibleMatch = tmpExtensibleMatch; } else { throw new CryptographicException(); } }
internal static void Decode(AsnReader reader, Asn1Tag expectedTag, out Asn1SearchRequest decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new Asn1SearchRequest(); AsnReader sequenceReader = reader.ReadSequence(expectedTag); AsnReader collectionReader; if (sequenceReader.TryGetPrimitiveOctetStringBytes(out ReadOnlyMemory <byte> tmpBaseObject)) { decoded.BaseObject = tmpBaseObject; } else { decoded.BaseObject = sequenceReader.ReadOctetString(); } decoded.Scope = sequenceReader.GetEnumeratedValue <SearchScope>(); decoded.DerefAliases = sequenceReader.GetEnumeratedValue <DerefAliases>(); if (!sequenceReader.TryReadInt32(out decoded.SizeLimit)) { sequenceReader.ThrowIfNotEmpty(); } if (!sequenceReader.TryReadInt32(out decoded.TimeLimit)) { sequenceReader.ThrowIfNotEmpty(); } decoded.TypesOnly = sequenceReader.ReadBoolean(); Asn1Filter.Decode(sequenceReader, out decoded.Filter); // Decode SEQUENCE OF for Attributes { collectionReader = sequenceReader.ReadSequence(); var tmpList = new List <ReadOnlyMemory <byte> >(); ReadOnlyMemory <byte> tmpItem; while (collectionReader.HasData) { if (collectionReader.TryGetPrimitiveOctetStringBytes(out ReadOnlyMemory <byte> tmp)) { tmpItem = tmp; } else { tmpItem = collectionReader.ReadOctetString(); } tmpList.Add(tmpItem); } decoded.Attributes = tmpList.ToArray(); } sequenceReader.ThrowIfNotEmpty(); }