internal static void Decode <T>(AsnReader reader, Asn1Tag expectedTag, out T decoded) where T : KrbSubjectPublicKeyInfo, new() { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new T(); AsnReader sequenceReader = reader.ReadSequence(expectedTag); KrbAlgorithmIdentifier.Decode <KrbAlgorithmIdentifier>(sequenceReader, out decoded.Algorithm); if (sequenceReader.TryReadPrimitiveBitStringValue(out _, out ReadOnlyMemory <byte> tmpSubjectPublicKey)) { decoded.SubjectPublicKey = tmpSubjectPublicKey; } else { decoded.SubjectPublicKey = sequenceReader.ReadBitString(out _); } sequenceReader.ThrowIfNotEmpty(); }
internal static void Decode <T>(AsnReader reader, Asn1Tag expectedTag, out T decoded) where T : KrbAuthPack, new() { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new T(); AsnReader sequenceReader = reader.ReadSequence(expectedTag); AsnReader explicitReader; AsnReader collectionReader; explicitReader = sequenceReader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 0)); KrbPKAuthenticator.Decode <KrbPKAuthenticator>(explicitReader, out KrbPKAuthenticator tmpPKAuthenticator); decoded.PKAuthenticator = tmpPKAuthenticator; explicitReader.ThrowIfNotEmpty(); if (sequenceReader.HasData && sequenceReader.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1))) { explicitReader = sequenceReader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 1)); KrbSubjectPublicKeyInfo.Decode <KrbSubjectPublicKeyInfo>(explicitReader, out KrbSubjectPublicKeyInfo tmpClientPublicValue); decoded.ClientPublicValue = tmpClientPublicValue; explicitReader.ThrowIfNotEmpty(); } if (sequenceReader.HasData && sequenceReader.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 2))) { explicitReader = sequenceReader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 2)); // Decode SEQUENCE OF for SupportedCMSTypes { collectionReader = explicitReader.ReadSequence(); var tmpList = new List <KrbAlgorithmIdentifier>(); KrbAlgorithmIdentifier tmpItem; while (collectionReader.HasData) { KrbAlgorithmIdentifier.Decode <KrbAlgorithmIdentifier>(collectionReader, out KrbAlgorithmIdentifier tmp); tmpItem = tmp; tmpList.Add(tmpItem); } decoded.SupportedCMSTypes = tmpList.ToArray(); } explicitReader.ThrowIfNotEmpty(); } if (sequenceReader.HasData && sequenceReader.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 3))) { explicitReader = sequenceReader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 3)); if (explicitReader.TryReadPrimitiveOctetStringBytes(out ReadOnlyMemory <byte> tmpClientDHNonce)) { decoded.ClientDHNonce = tmpClientDHNonce; } else { decoded.ClientDHNonce = explicitReader.ReadOctetString(); } explicitReader.ThrowIfNotEmpty(); } sequenceReader.ThrowIfNotEmpty(); }