Exemplo n.º 1
0
        public EncTicketPart(Asn1Element asn1Element)
        {
            var childNode = asn1Element[0];

            for (var i = 0; i < childNode.Count; i++)
            {
                var node = childNode[i];

                switch (node.ContextSpecificTag)
                {
                case 0:
                    TicketFlags = node[0].AsLong();
                    break;

                case 1:
                    EncryptionKey = node[0][1][0].Value;
                    break;

                case 2:
                    CRealm = node[0].AsString();
                    break;

                case 3:
                    CName = new PrincipalName(node);
                    break;

                case 4:
                    for (int l = 0; l < node.Count; l++)
                    {
                        var t = node[l];
                        Transited.Add(new TransitedEncoding(t));
                    }
                    break;

                case 5:
                    AuthTime = node[0].AsDateTimeOffset();
                    break;

                case 6:
                    StartTime = node[0].AsDateTimeOffset();
                    break;

                case 7:
                    EndTime = node[0].AsDateTimeOffset();
                    break;

                case 8:
                    RenewTill = node[0].AsDateTimeOffset();
                    break;

                case 9:
                    HostAddress = node[0].AsLong();
                    break;

                case 10:

                    var parent = node[0];

                    AuthorizationData = new AuthorizationData(parent);

                    break;
                }
            }
        }
        internal void Encode(AsnWriter writer, Asn1Tag tag)
        {
            writer.PushSequence(tag);

            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
            writer.WriteBitString(Flags.AsReadOnlySpan());
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
            Key?.Encode(writer);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 2));
            writer.WriteCharacterString(UniversalTagNumber.GeneralString, CRealm);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 2));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
            CName?.Encode(writer);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 4));
            Transited?.Encode(writer);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 4));
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 5));
            writer.WriteGeneralizedTime(AuthTime);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 5));

            if (Asn1Extension.HasValue(StartTime))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 6));
                writer.WriteGeneralizedTime(StartTime.Value);
                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 6));
            }
            writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 7));
            writer.WriteGeneralizedTime(EndTime);
            writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 7));

            if (Asn1Extension.HasValue(RenewTill))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 8));
                writer.WriteGeneralizedTime(RenewTill.Value);
                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 8));
            }

            if (Asn1Extension.HasValue(CAddr))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 9));
                writer.PushSequence();

                for (int i = 0; i < CAddr.Length; i++)
                {
                    CAddr[i]?.Encode(writer);
                }

                writer.PopSequence();

                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 9));
            }


            if (Asn1Extension.HasValue(AuthorizationData))
            {
                writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 10));
                writer.PushSequence();

                for (int i = 0; i < AuthorizationData.Length; i++)
                {
                    AuthorizationData[i]?.Encode(writer);
                }

                writer.PopSequence();

                writer.PopSequence(new Asn1Tag(TagClass.ContextSpecific, 10));
            }

            writer.PopSequence(tag);
        }
Exemplo n.º 3
0
        public EncTicketPart Decode(Asn1Element asn1Element)
        {
            var childNode = asn1Element[0];

            if (childNode == null)
            {
                return(null);
            }

            for (var i = 0; i < childNode.Count; i++)
            {
                var node = childNode[i];

                switch (node.ContextSpecificTag)
                {
                case 0:
                    TicketFlags = (TicketFlags)node[0].AsLong();
                    break;

                case 1:
                    Key = new EncryptionKey().Decode(node[0]);
                    break;

                case 2:
                    CRealm = node[0].AsString();
                    break;

                case 3:
                    CName = new PrincipalName().Decode(node[0], CRealm);
                    break;

                case 4:
                    for (int l = 0; l < node.Count; l++)
                    {
                        Transited.Add(new TransitedEncoding().Decode(node[l]));
                    }
                    break;

                case 5:
                    AuthTime = node[0].AsDateTimeOffset();
                    break;

                case 6:
                    StartTime = node[0].AsDateTimeOffset();
                    break;

                case 7:
                    EndTime = node[0].AsDateTimeOffset();
                    break;

                case 8:
                    RenewTill = node[0].AsDateTimeOffset();
                    break;

                case 9:
                    HostAddresses = node[0].AsLong();
                    break;

                case 10:
                    var parent = node[0];

                    var authorizations = new List <AuthorizationData>();

                    for (var p = 0; p < parent.Count; p++)
                    {
                        var azElements = AuthorizationDataElement.ParseElements(parent[p]);

                        authorizations.AddRange(azElements);
                    }

                    AuthorizationData = authorizations;
                    break;
                }
            }

            return(this);
        }