internal static void Decode(AsnReader reader, out KeyAgreeRecipientIdentifierAsn decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = default; Asn1Tag tag = reader.PeekTag(); if (tag.HasSameClassAndValue(Asn1Tag.Sequence)) { System.Security.Cryptography.Pkcs.Asn1.IssuerAndSerialNumberAsn tmpIssuerAndSerialNumber; System.Security.Cryptography.Pkcs.Asn1.IssuerAndSerialNumberAsn.Decode(reader, out tmpIssuerAndSerialNumber); decoded.IssuerAndSerialNumber = tmpIssuerAndSerialNumber; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { System.Security.Cryptography.Pkcs.Asn1.RecipientKeyIdentifier tmpRKeyId; System.Security.Cryptography.Pkcs.Asn1.RecipientKeyIdentifier.Decode(reader, new Asn1Tag(TagClass.ContextSpecific, 0), out tmpRKeyId); decoded.RKeyId = tmpRKeyId; } else { throw new CryptographicException(); } }
internal static void Decode <T>(AsnReader reader, out T decoded) where T : NegotiationToken, new() { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new T(); Asn1Tag tag = reader.PeekTag(); AsnReader explicitReader; if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { explicitReader = reader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 0)); NegTokenInit.Decode <NegTokenInit>(explicitReader, out NegTokenInit tmpInitialToken); decoded.InitialToken = tmpInitialToken; explicitReader.ThrowIfNotEmpty(); } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1))) { explicitReader = reader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 1)); NegTokenResp.Decode <NegTokenResp>(explicitReader, out NegTokenResp tmpResponseToken); decoded.ResponseToken = tmpResponseToken; explicitReader.ThrowIfNotEmpty(); } else { throw new CryptographicException(); } }
internal static void Decode(ref AsnValueReader reader, ReadOnlyMemory <byte> rebind, out RecipientInfoAsn decoded) { decoded = default; Asn1Tag tag = reader.PeekTag(); if (tag.HasSameClassAndValue(Asn1Tag.Sequence)) { KeyTransRecipientInfoAsn tmpKtri; KeyTransRecipientInfoAsn.Decode(ref reader, rebind, out tmpKtri); decoded.Ktri = tmpKtri; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1))) { KeyAgreeRecipientInfoAsn tmpKari; KeyAgreeRecipientInfoAsn.Decode(ref reader, new Asn1Tag(TagClass.ContextSpecific, 1), rebind, out tmpKari); decoded.Kari = tmpKari; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 2))) { KEKRecipientInfoAsn kekRecipientInfo; KEKRecipientInfoAsn.Decode(ref reader, new Asn1Tag(TagClass.ContextSpecific, 2), rebind, out kekRecipientInfo); decoded.KrecipientInfo = kekRecipientInfo; } else { throw new CryptographicException(); } }
internal static void Decode(AsnReader reader, out RecipientInfoAsn decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = default; Asn1Tag tag = reader.PeekTag(); if (tag.HasSameClassAndValue(Asn1Tag.Sequence)) { System.Security.Cryptography.Pkcs.Asn1.KeyTransRecipientInfoAsn tmpKtri; System.Security.Cryptography.Pkcs.Asn1.KeyTransRecipientInfoAsn.Decode(reader, out tmpKtri); decoded.Ktri = tmpKtri; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1))) { System.Security.Cryptography.Pkcs.Asn1.KeyAgreeRecipientInfoAsn tmpKari; System.Security.Cryptography.Pkcs.Asn1.KeyAgreeRecipientInfoAsn.Decode(reader, new Asn1Tag(TagClass.ContextSpecific, 1), out tmpKari); decoded.Kari = tmpKari; } else { throw new CryptographicException(); } }
internal static void Decode(AsnReader reader, out SignerIdentifierAsn decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = default; Asn1Tag tag = reader.PeekTag(); if (tag.HasSameClassAndValue(Asn1Tag.Sequence)) { System.Security.Cryptography.Pkcs.Asn1.IssuerAndSerialNumberAsn tmpIssuerAndSerialNumber; System.Security.Cryptography.Pkcs.Asn1.IssuerAndSerialNumberAsn.Decode(reader, out tmpIssuerAndSerialNumber); decoded.IssuerAndSerialNumber = tmpIssuerAndSerialNumber; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { if (reader.TryReadPrimitiveOctetStringBytes(new Asn1Tag(TagClass.ContextSpecific, 0), out ReadOnlyMemory <byte> tmpSubjectKeyIdentifier)) { decoded.SubjectKeyIdentifier = tmpSubjectKeyIdentifier; } else { decoded.SubjectKeyIdentifier = reader.ReadOctetString(new Asn1Tag(TagClass.ContextSpecific, 0)); } } else { throw new CryptographicException(); } }
internal static void Decode(AsnReader reader, out Asn1AuthenticationChoice decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new Asn1AuthenticationChoice(); Asn1Tag tag = reader.PeekTag(); if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { if (reader.TryGetPrimitiveOctetStringBytes(new Asn1Tag(TagClass.ContextSpecific, 0), out ReadOnlyMemory <byte> tmpSimple)) { decoded.Simple = tmpSimple; } else { decoded.Simple = reader.ReadOctetString(new Asn1Tag(TagClass.ContextSpecific, 0)); } } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 3))) { Asn1SaslCredentials tmpSasl; Asn1SaslCredentials.Decode(reader, new Asn1Tag(TagClass.ContextSpecific, 3), out tmpSasl); decoded.Sasl = tmpSasl; } else { throw new CryptographicException(); } }
internal static void Decode(ref AsnValueReader reader, ReadOnlyMemory <byte> rebind, out SignerIdentifierAsn decoded) { decoded = default; Asn1Tag tag = reader.PeekTag(); ReadOnlySpan <byte> rebindSpan = rebind.Span; int offset; ReadOnlySpan <byte> tmpSpan; if (tag.HasSameClassAndValue(Asn1Tag.Sequence)) { System.Security.Cryptography.Pkcs.Asn1.IssuerAndSerialNumberAsn tmpIssuerAndSerialNumber; System.Security.Cryptography.Pkcs.Asn1.IssuerAndSerialNumberAsn.Decode(ref reader, rebind, out tmpIssuerAndSerialNumber); decoded.IssuerAndSerialNumber = tmpIssuerAndSerialNumber; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { if (reader.TryReadPrimitiveOctetStringBytes(new Asn1Tag(TagClass.ContextSpecific, 0), out tmpSpan)) { decoded.SubjectKeyIdentifier = rebindSpan.Overlaps(tmpSpan, out offset) ? rebind.Slice(offset, tmpSpan.Length) : tmpSpan.ToArray(); } else { decoded.SubjectKeyIdentifier = reader.ReadOctetString(new Asn1Tag(TagClass.ContextSpecific, 0)); } } else { throw new CryptographicException(); } }
internal static void Decode(AsnReader reader, out Asn1Substring decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new Asn1Substring(); Asn1Tag tag = reader.PeekTag(); if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { if (reader.TryGetPrimitiveOctetStringBytes(new Asn1Tag(TagClass.ContextSpecific, 0), out ReadOnlyMemory <byte> tmpInitial)) { decoded.Initial = tmpInitial; } else { decoded.Initial = reader.ReadOctetString(new Asn1Tag(TagClass.ContextSpecific, 0)); } } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1))) { if (reader.TryGetPrimitiveOctetStringBytes(new Asn1Tag(TagClass.ContextSpecific, 1), out ReadOnlyMemory <byte> tmpAny)) { decoded.Any = tmpAny; } else { decoded.Any = reader.ReadOctetString(new Asn1Tag(TagClass.ContextSpecific, 1)); } } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 2))) { if (reader.TryGetPrimitiveOctetStringBytes(new Asn1Tag(TagClass.ContextSpecific, 2), out ReadOnlyMemory <byte> tmpFinal)) { decoded.Final = tmpFinal; } else { decoded.Final = reader.ReadOctetString(new Asn1Tag(TagClass.ContextSpecific, 2)); } } else { throw new CryptographicException(); } }
internal static void Decode <T>(AsnReader reader, out T decoded) where T : KrbMethodData, new() { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new T(); Asn1Tag tag = reader.PeekTag(); AsnReader collectionReader; if (tag.HasSameClassAndValue(Asn1Tag.Sequence)) { // Decode SEQUENCE OF for MethodData { collectionReader = reader.ReadSequence(); var tmpList = new List <KrbPaData>(); KrbPaData tmpItem; while (collectionReader.HasData) { KrbPaData.Decode <KrbPaData>(collectionReader, out tmpItem); tmpList.Add(tmpItem); } decoded.MethodData = tmpList.ToArray(); } } else { throw new CryptographicException(); } }
internal static void Decode(ref AsnValueReader reader, ReadOnlyMemory <byte> rebind, out SignedAttributesSet decoded) { decoded = default; Asn1Tag tag = reader.PeekTag(); AsnValueReader collectionReader; if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { // Decode SEQUENCE OF for SignedAttributes { collectionReader = reader.ReadSetOf(new Asn1Tag(TagClass.ContextSpecific, 0)); var tmpList = new List <System.Security.Cryptography.Asn1.AttributeAsn>(); System.Security.Cryptography.Asn1.AttributeAsn tmpItem; while (collectionReader.HasData) { System.Security.Cryptography.Asn1.AttributeAsn.Decode(ref collectionReader, rebind, out tmpItem); tmpList.Add(tmpItem); } decoded.SignedAttributes = tmpList.ToArray(); } } else { throw new CryptographicException(); } }
internal static void Decode(AsnReader reader, out SignedAttributesSet decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = default; Asn1Tag tag = reader.PeekTag(); AsnReader collectionReader; if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { // Decode SEQUENCE OF for SignedAttributes { collectionReader = reader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 0)); var tmpList = new List <System.Security.Cryptography.Asn1.AttributeAsn>(); System.Security.Cryptography.Asn1.AttributeAsn tmpItem; while (collectionReader.HasData) { System.Security.Cryptography.Asn1.AttributeAsn.Decode(collectionReader, out tmpItem); tmpList.Add(tmpItem); } decoded.SignedAttributes = tmpList.ToArray(); } } else { throw new CryptographicException(); } }
internal static void Decode <T>(AsnReader reader, out T decoded) where T : KrbPaFxFastRequest, new() { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new T(); Asn1Tag tag = reader.PeekTag(); AsnReader explicitReader; if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { explicitReader = reader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 0)); KrbFastArmoredReq.Decode <KrbFastArmoredReq>(explicitReader, out KrbFastArmoredReq tmpArmoredData); decoded.ArmoredData = tmpArmoredData; explicitReader.ThrowIfNotEmpty(); } else { throw new CryptographicException(); } }
internal static void Decode(ref AsnValueReader reader, ReadOnlyMemory <byte> rebind, out TimeAsn decoded) { decoded = default; Asn1Tag tag = reader.PeekTag(); if (tag.HasSameClassAndValue(Asn1Tag.UtcTime)) { decoded.UtcTime = reader.ReadUtcTime(); } else if (tag.HasSameClassAndValue(Asn1Tag.GeneralizedTime)) { decoded.GeneralTime = reader.ReadGeneralizedTime(disallowFractions: true); } else { throw new CryptographicException(); } }
internal static void Decode <T>(AsnReader reader, out T decoded) where T : KrbPaPkAsRep, new() { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new T(); Asn1Tag tag = reader.PeekTag(); AsnReader explicitReader; if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { explicitReader = reader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 0)); KrbDHReplyInfo tmpDHInfo; KrbDHReplyInfo.Decode <KrbDHReplyInfo>(explicitReader, out tmpDHInfo); decoded.DHInfo = tmpDHInfo; explicitReader.ThrowIfNotEmpty(); } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1))) { explicitReader = reader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 1)); if (explicitReader.TryReadPrimitiveOctetStringBytes(out ReadOnlyMemory <byte> tmpEncKeyPack)) { decoded.EncKeyPack = tmpEncKeyPack; } else { decoded.EncKeyPack = explicitReader.ReadOctetString(); } explicitReader.ThrowIfNotEmpty(); } else { throw new CryptographicException(); } }
private static void DecodeCore(ref AsnValueReader reader, ReadOnlyMemory <byte> rebind, out KeyAgreeRecipientIdentifierAsn decoded) { decoded = default; Asn1Tag tag = reader.PeekTag(); if (tag.HasSameClassAndValue(Asn1Tag.Sequence)) { System.Security.Cryptography.Pkcs.Asn1.IssuerAndSerialNumberAsn tmpIssuerAndSerialNumber; System.Security.Cryptography.Pkcs.Asn1.IssuerAndSerialNumberAsn.Decode(ref reader, rebind, out tmpIssuerAndSerialNumber); decoded.IssuerAndSerialNumber = tmpIssuerAndSerialNumber; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { System.Security.Cryptography.Pkcs.Asn1.RecipientKeyIdentifier tmpRKeyId; System.Security.Cryptography.Pkcs.Asn1.RecipientKeyIdentifier.Decode(ref reader, new Asn1Tag(TagClass.ContextSpecific, 0), rebind, out tmpRKeyId); decoded.RKeyId = tmpRKeyId; } else { throw new CryptographicException(); } }
private static void DecodeCore(ref AsnValueReader reader, ReadOnlyMemory <byte> rebind, out RecipientInfoAsn decoded) { decoded = default; Asn1Tag tag = reader.PeekTag(); if (tag.HasSameClassAndValue(Asn1Tag.Sequence)) { System.Security.Cryptography.Pkcs.Asn1.KeyTransRecipientInfoAsn tmpKtri; System.Security.Cryptography.Pkcs.Asn1.KeyTransRecipientInfoAsn.Decode(ref reader, rebind, out tmpKtri); decoded.Ktri = tmpKtri; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1))) { System.Security.Cryptography.Pkcs.Asn1.KeyAgreeRecipientInfoAsn tmpKari; System.Security.Cryptography.Pkcs.Asn1.KeyAgreeRecipientInfoAsn.Decode(ref reader, new Asn1Tag(TagClass.ContextSpecific, 1), rebind, out tmpKari); decoded.Kari = tmpKari; } else { throw new CryptographicException(); } }
private static void DecodeCore(ref AsnValueReader reader, ReadOnlyMemory <byte> rebind, out CertificateChoiceAsn decoded) { decoded = default; Asn1Tag tag = reader.PeekTag(); ReadOnlySpan <byte> rebindSpan = rebind.Span; int offset; ReadOnlySpan <byte> tmpSpan; if (tag.HasSameClassAndValue(new Asn1Tag((UniversalTagNumber)16))) { tmpSpan = reader.ReadEncodedValue(); decoded.Certificate = rebindSpan.Overlaps(tmpSpan, out offset) ? rebind.Slice(offset, tmpSpan.Length) : tmpSpan.ToArray(); } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { tmpSpan = reader.ReadEncodedValue(); decoded.ExtendedCertificate = rebindSpan.Overlaps(tmpSpan, out offset) ? rebind.Slice(offset, tmpSpan.Length) : tmpSpan.ToArray(); } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1))) { tmpSpan = reader.ReadEncodedValue(); decoded.AttributeCertificateV1 = rebindSpan.Overlaps(tmpSpan, out offset) ? rebind.Slice(offset, tmpSpan.Length) : tmpSpan.ToArray(); } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 2))) { tmpSpan = reader.ReadEncodedValue(); decoded.AttributeCertificateV2 = rebindSpan.Overlaps(tmpSpan, out offset) ? rebind.Slice(offset, tmpSpan.Length) : tmpSpan.ToArray(); } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 3))) { System.Security.Cryptography.Pkcs.Asn1.OtherCertificateFormat tmpOtherCertificateFormat; System.Security.Cryptography.Pkcs.Asn1.OtherCertificateFormat.Decode(ref reader, new Asn1Tag(TagClass.ContextSpecific, 3), rebind, out tmpOtherCertificateFormat); decoded.OtherCertificateFormat = tmpOtherCertificateFormat; } else { throw new CryptographicException(); } }
internal static void Decode(AsnReader reader, out TimeAsn decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = default; Asn1Tag tag = reader.PeekTag(); if (tag.HasSameClassAndValue(Asn1Tag.UtcTime)) { decoded.UtcTime = reader.GetUtcTime(); } else if (tag.HasSameClassAndValue(Asn1Tag.GeneralizedTime)) { decoded.GeneralTime = reader.GetGeneralizedTime(); } else { throw new CryptographicException(); } }
private static void DecodeCore(ref AsnValueReader reader, ReadOnlyMemory <byte> rebind, out TimeAsn decoded) { decoded = default; Asn1Tag tag = reader.PeekTag(); if (tag.HasSameClassAndValue(Asn1Tag.UtcTime)) { decoded.UtcTime = reader.ReadUtcTime(); } else if (tag.HasSameClassAndValue(Asn1Tag.GeneralizedTime)) { decoded.GeneralTime = reader.ReadGeneralizedTime(); if (decoded.GeneralTime !.Value.Ticks % TimeSpan.TicksPerSecond != 0) { throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding); } } else { throw new CryptographicException(); } }
internal static void Decode(AsnReader reader, out DistributionPointNameAsn decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = default; Asn1Tag tag = reader.PeekTag(); AsnReader collectionReader; if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { // Decode SEQUENCE OF for FullName { collectionReader = reader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 0)); var tmpList = new List <System.Security.Cryptography.Asn1.GeneralNameAsn>(); System.Security.Cryptography.Asn1.GeneralNameAsn tmpItem; while (collectionReader.HasData) { System.Security.Cryptography.Asn1.GeneralNameAsn.Decode(collectionReader, out tmpItem); tmpList.Add(tmpItem); } decoded.FullName = tmpList.ToArray(); } } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1))) { decoded.NameRelativeToCRLIssuer = reader.GetEncodedValue(); } else { throw new CryptographicException(); } }
internal static void Decode(ref AsnValueReader reader, ReadOnlyMemory <byte> rebind, out DistributionPointNameAsn decoded) { decoded = default; Asn1Tag tag = reader.PeekTag(); AsnValueReader collectionReader; ReadOnlySpan <byte> rebindSpan = rebind.Span; int offset; ReadOnlySpan <byte> tmpSpan; if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { // Decode SEQUENCE OF for FullName { collectionReader = reader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 0)); var tmpList = new List <System.Security.Cryptography.Asn1.GeneralNameAsn>(); System.Security.Cryptography.Asn1.GeneralNameAsn tmpItem; while (collectionReader.HasData) { System.Security.Cryptography.Asn1.GeneralNameAsn.Decode(ref collectionReader, rebind, out tmpItem); tmpList.Add(tmpItem); } decoded.FullName = tmpList.ToArray(); } } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1))) { tmpSpan = reader.ReadEncodedValue(); decoded.NameRelativeToCRLIssuer = rebindSpan.Overlaps(tmpSpan, out offset) ? rebind.Slice(offset, tmpSpan.Length) : tmpSpan.ToArray(); } else { throw new CryptographicException(); } }
internal static void Decode(ref AsnValueReader reader, ReadOnlyMemory <byte> rebind, out CertificateChoiceAsn decoded) { decoded = default; Asn1Tag tag = reader.PeekTag(); ReadOnlySpan <byte> rebindSpan = rebind.Span; int offset; ReadOnlySpan <byte> tmpSpan; if (tag.HasSameClassAndValue(new Asn1Tag((UniversalTagNumber)16))) { tmpSpan = reader.ReadEncodedValue(); decoded.Certificate = rebindSpan.Overlaps(tmpSpan, out offset) ? rebind.Slice(offset, tmpSpan.Length) : tmpSpan.ToArray(); } else { throw new CryptographicException(); } }
internal static void Decode(AsnReader reader, out CertificateChoiceAsn decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = default; Asn1Tag tag = reader.PeekTag(); if (tag.HasSameClassAndValue(new Asn1Tag((UniversalTagNumber)16))) { decoded.Certificate = reader.ReadEncodedValue(); } else { throw new CryptographicException(); } }
internal static void Decode <T>(AsnReader reader, out T decoded) where T : KrbETypeList, new() { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new T(); Asn1Tag tag = reader.PeekTag(); AsnReader collectionReader; if (tag.HasSameClassAndValue(Asn1Tag.Sequence)) { // Decode SEQUENCE OF for List { collectionReader = reader.ReadSequence(); var tmpList = new List <EncryptionType>(); EncryptionType tmpItem; while (collectionReader.HasData) { if (!collectionReader.TryReadInt32(out EncryptionType tmp)) { collectionReader.ThrowIfNotEmpty(); } tmpItem = tmp; tmpList.Add(tmpItem); } decoded.List = tmpList.ToArray(); } } else { throw new CryptographicException(); } }
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, out Asn1ProtocolOp decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new Asn1ProtocolOp(); Asn1Tag tag = reader.PeekTag(); AsnReader collectionReader; if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 0))) { Asn1BindRequest tmpBindRequest; Asn1BindRequest.Decode(reader, new Asn1Tag(TagClass.Application, 0), out tmpBindRequest); decoded.BindRequest = tmpBindRequest; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 1))) { Asn1BindResponse tmpBindResponse; Asn1BindResponse.Decode(reader, new Asn1Tag(TagClass.Application, 1), out tmpBindResponse); decoded.BindResponse = tmpBindResponse; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 2))) { reader.ReadNull(new Asn1Tag(TagClass.Application, 2)); decoded.UnbindRequest = true; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 3))) { Asn1SearchRequest tmpSearchRequest; Asn1SearchRequest.Decode(reader, new Asn1Tag(TagClass.Application, 3), out tmpSearchRequest); decoded.SearchRequest = tmpSearchRequest; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 4))) { Asn1SearchResultEntry tmpSearchResEntry; Asn1SearchResultEntry.Decode(reader, new Asn1Tag(TagClass.Application, 4), out tmpSearchResEntry); decoded.SearchResEntry = tmpSearchResEntry; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 5))) { Asn1LDAPResult tmpSearchResultDone; Asn1LDAPResult.Decode(reader, new Asn1Tag(TagClass.Application, 5), out tmpSearchResultDone); decoded.SearchResultDone = tmpSearchResultDone; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 19))) { // Decode SEQUENCE OF for SearchResultReference { collectionReader = reader.ReadSequence(new Asn1Tag(TagClass.Application, 19)); 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.SearchResultReference = tmpList.ToArray(); } } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 6))) { Asn1ModifyRequest tmpModifyRequest; Asn1ModifyRequest.Decode(reader, new Asn1Tag(TagClass.Application, 6), out tmpModifyRequest); decoded.ModifyRequest = tmpModifyRequest; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 7))) { Asn1LDAPResult tmpModifyResponse; Asn1LDAPResult.Decode(reader, new Asn1Tag(TagClass.Application, 7), out tmpModifyResponse); decoded.ModifyResponse = tmpModifyResponse; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 8))) { Asn1AddRequest tmpAddRequest; Asn1AddRequest.Decode(reader, new Asn1Tag(TagClass.Application, 8), out tmpAddRequest); decoded.AddRequest = tmpAddRequest; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 9))) { Asn1LDAPResult tmpAddResponse; Asn1LDAPResult.Decode(reader, new Asn1Tag(TagClass.Application, 9), out tmpAddResponse); decoded.AddResponse = tmpAddResponse; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 10))) { if (reader.TryGetPrimitiveOctetStringBytes(new Asn1Tag(TagClass.Application, 10), out ReadOnlyMemory <byte> tmpDelRequest)) { decoded.DelRequest = tmpDelRequest; } else { decoded.DelRequest = reader.ReadOctetString(new Asn1Tag(TagClass.Application, 10)); } } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 11))) { Asn1LDAPResult tmpDelResponse; Asn1LDAPResult.Decode(reader, new Asn1Tag(TagClass.Application, 11), out tmpDelResponse); decoded.DelResponse = tmpDelResponse; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 12))) { Asn1ModifyDNRequest tmpModifyDNRequest; Asn1ModifyDNRequest.Decode(reader, new Asn1Tag(TagClass.Application, 12), out tmpModifyDNRequest); decoded.ModifyDNRequest = tmpModifyDNRequest; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 13))) { Asn1LDAPResult tmpModifyDNResponse; Asn1LDAPResult.Decode(reader, new Asn1Tag(TagClass.Application, 13), out tmpModifyDNResponse); decoded.ModifyDNResponse = tmpModifyDNResponse; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 14))) { Asn1CompareRequest tmpCompareRequest; Asn1CompareRequest.Decode(reader, new Asn1Tag(TagClass.Application, 14), out tmpCompareRequest); decoded.CompareRequest = tmpCompareRequest; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 15))) { Asn1LDAPResult tmpCompareResponse; Asn1LDAPResult.Decode(reader, new Asn1Tag(TagClass.Application, 15), out tmpCompareResponse); decoded.CompareResponse = tmpCompareResponse; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 16))) { if (reader.TryReadInt32(new Asn1Tag(TagClass.Application, 16), out int tmpAbandonRequest)) { decoded.AbandonRequest = tmpAbandonRequest; } else { reader.ThrowIfNotEmpty(); } } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 23))) { Asn1ExtendedRequest tmpExtendedRequest; Asn1ExtendedRequest.Decode(reader, new Asn1Tag(TagClass.Application, 23), out tmpExtendedRequest); decoded.ExtendedRequest = tmpExtendedRequest; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 24))) { Asn1ExtendedResponse tmpExtendedResponse; Asn1ExtendedResponse.Decode(reader, new Asn1Tag(TagClass.Application, 24), out tmpExtendedResponse); decoded.ExtendedResponse = tmpExtendedResponse; } else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.Application, 25))) { Asn1IntermediateResponse tmpIntermediateResponse; Asn1IntermediateResponse.Decode(reader, new Asn1Tag(TagClass.Application, 25), out tmpIntermediateResponse); decoded.IntermediateResponse = tmpIntermediateResponse; } else { throw new CryptographicException(); } }
private void Decode(ReadOnlySpan <byte> rawData) { _keyIdentifier = null; _simpleIssuer = null; _rawIssuer = null; _serialNumber = null; // https://datatracker.ietf.org/doc/html/rfc3280#section-4.2.1.1 // AuthorityKeyIdentifier ::= SEQUENCE { // keyIdentifier[0] KeyIdentifier OPTIONAL, // authorityCertIssuer[1] GeneralNames OPTIONAL, // authorityCertSerialNumber[2] CertificateSerialNumber OPTIONAL } // // KeyIdentifier::= OCTET STRING try { AsnValueReader reader = new AsnValueReader(rawData, AsnEncodingRules.DER); AsnValueReader aki = reader.ReadSequence(); reader.ThrowIfNotEmpty(); Asn1Tag nextTag = default; if (aki.HasData) { nextTag = aki.PeekTag(); } if (nextTag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0))) { _keyIdentifier = aki.ReadOctetString(nextTag); if (aki.HasData) { nextTag = aki.PeekTag(); } } if (nextTag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1))) { byte[] rawIssuer = aki.PeekEncodedValue().ToArray(); _rawIssuer = rawIssuer; AsnValueReader generalNames = aki.ReadSequence(nextTag); bool foundIssuer = false; // Walk all of the entities to make sure they decode legally, so no early abort. while (generalNames.HasData) { GeneralNameAsn.Decode(ref generalNames, rawIssuer, out GeneralNameAsn decoded); if (decoded.DirectoryName.HasValue) { if (!foundIssuer) { // Only ever try reading the first one. // Don't just use a null check or we would load the last of an odd number. foundIssuer = true; _simpleIssuer = new X500DistinguishedName( decoded.DirectoryName.GetValueOrDefault().Span); } else { _simpleIssuer = null; } } } if (aki.HasData) { nextTag = aki.PeekTag(); } } if (nextTag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 2))) { _serialNumber = aki.ReadIntegerBytes(nextTag).ToArray(); } aki.ThrowIfNotEmpty(); } catch (AsnContentException e) { throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding, e); } _decoded = true; }