PDIRTY_ASN1_SEQUENCE_EASY kuhl_m_kerberos_ticket_createAppKrbCred(PKIWI_KERBEROS_TICKET ticket, BOOL valueIsTicket)
{
	PDIRTY_ASN1_SEQUENCE_EASY App_KrbCred, Seq_KrbCred/*, Ctx_KrbCred*/, Seq_Root, App_EncKrbCredPart, App_Ticket;
	UCHAR integer1;
	
	if(App_KrbCred = KULL_M_ASN1_CREATE_APP(ID_APP_KRB_CRED))
	{
		if(Seq_KrbCred = KULL_M_ASN1_CREATE_SEQ())
		{
			integer1 = KERBEROS_VERSION;
			kull_m_asn1_append_ctx_and_data_to_seq(&Seq_KrbCred, ID_CTX_KRB_CRED_PVNO, kull_m_asn1_create(DIRTY_ASN1_ID_INTEGER, &integer1, sizeof(UCHAR), NULL));
			integer1 = ID_APP_KRB_CRED;
			kull_m_asn1_append_ctx_and_data_to_seq(&Seq_KrbCred, ID_CTX_KRB_CRED_MSG_TYPE, kull_m_asn1_create(DIRTY_ASN1_ID_INTEGER, &integer1, sizeof(UCHAR), NULL));
			if(Seq_Root = KULL_M_ASN1_CREATE_SEQ())
			{
				if(valueIsTicket)
				{
					if(App_Ticket = (PDIRTY_ASN1_SEQUENCE_EASY) LocalAlloc(LPTR, ticket->Ticket.Length))
						RtlCopyMemory(App_Ticket, ticket->Ticket.Value, ticket->Ticket.Length);
				}
				else App_Ticket = kuhl_m_kerberos_ticket_createAppTicket(ticket);
				kull_m_asn1_append(&Seq_Root, App_Ticket);
				kull_m_asn1_append_ctx_and_data_to_seq(&Seq_KrbCred, ID_CTX_KRB_CRED_TICKETS, Seq_Root);
			}
			if(App_EncKrbCredPart = kuhl_m_kerberos_ticket_createAppEncKrbCredPart(ticket))
			{
				kull_m_asn1_append_ctx_and_data_to_seq(&Seq_KrbCred, ID_CTX_KRB_CRED_ENC_PART, kuhl_m_kerberos_ticket_createSequenceEncryptedData(KERB_ETYPE_NULL, 0, App_EncKrbCredPart, kull_m_asn1_getSize(App_EncKrbCredPart)));
				LocalFree(App_EncKrbCredPart);
			}
			kull_m_asn1_append(&App_KrbCred, Seq_KrbCred);
		}
	}
	return App_KrbCred;
}
PDIRTY_ASN1_SEQUENCE_EASY kuhl_m_kerberos_ticket_createAppKrbCred(PKIWI_KERBEROS_TICKET ticket)
{
	PDIRTY_ASN1_SEQUENCE_EASY App_KrbCred, Seq_KrbCred, Ctx_KrbCred, Seq_Root, App_EncKrbCredPart;
	UCHAR integer1;
	
	if(App_KrbCred = KULL_M_ASN1_CREATE_APP(ID_APP_KRB_CRED))
	{
		if(Seq_KrbCred = KULL_M_ASN1_CREATE_SEQ())
		{
			if(Ctx_KrbCred = KULL_M_ASN1_CREATE_CTX(ID_CTX_KRB_CRED_PVNO))
			{
				integer1 = KERBEROS_VERSION;
				kull_m_asn1_create(DIRTY_ASN1_ID_INTEGER, &integer1, sizeof(UCHAR), &Ctx_KrbCred);
				kull_m_asn1_append(&Seq_KrbCred, Ctx_KrbCred);
			}
			if(Ctx_KrbCred = KULL_M_ASN1_CREATE_CTX(ID_CTX_KRB_CRED_MSG_TYPE))
			{
				integer1 = ID_APP_KRB_CRED;
				kull_m_asn1_create(DIRTY_ASN1_ID_INTEGER, &integer1, sizeof(UCHAR), &Ctx_KrbCred);
				kull_m_asn1_append(&Seq_KrbCred, Ctx_KrbCred);
			}
			if(Ctx_KrbCred = KULL_M_ASN1_CREATE_CTX(ID_CTX_KRB_CRED_TICKETS))
			{
				if(Seq_Root = KULL_M_ASN1_CREATE_SEQ())
				{
					kull_m_asn1_append(&Seq_Root, kuhl_m_kerberos_ticket_createAppTicket(ticket));
					kull_m_asn1_append(&Ctx_KrbCred, Seq_Root);
				}
				kull_m_asn1_append(&Seq_KrbCred, Ctx_KrbCred);
			}
			if(Ctx_KrbCred = KULL_M_ASN1_CREATE_CTX(ID_CTX_KRB_CRED_ENC_PART))
			{
				if(App_EncKrbCredPart = kuhl_m_kerberos_ticket_createAppEncKrbCredPart(ticket))
				{
					kull_m_asn1_append(&Ctx_KrbCred, kuhl_m_kerberos_ticket_createSequenceEncryptedData(KERB_ETYPE_NULL, 0, App_EncKrbCredPart, kull_m_asn1_getSize(App_EncKrbCredPart)));
					LocalFree(App_EncKrbCredPart);
				}
				kull_m_asn1_append(&Seq_KrbCred, Ctx_KrbCred);
			}

			kull_m_asn1_append(&App_KrbCred, Seq_KrbCred);
		}
	}
	return App_KrbCred;
}
PDIRTY_ASN1_SEQUENCE_EASY kuhl_m_kerberos_ticket_createAppTicket(PKIWI_KERBEROS_TICKET ticket)
{
	PDIRTY_ASN1_SEQUENCE_EASY App_Ticket, Seq_Ticket/*, Ctx_Ticket*/;
	UCHAR integer1 = KERBEROS_VERSION;
	
	if(App_Ticket = KULL_M_ASN1_CREATE_APP(ID_APP_TICKET))
	{
		if(Seq_Ticket = KULL_M_ASN1_CREATE_SEQ())
		{
			kull_m_asn1_append_ctx_and_data_to_seq(&Seq_Ticket, ID_CTX_TICKET_TKT_VNO, kull_m_asn1_create(DIRTY_ASN1_ID_INTEGER, &integer1, sizeof(UCHAR), NULL));
			kull_m_asn1_append_ctx_and_data_to_seq(&Seq_Ticket, ID_CTX_TICKET_REALM, kull_m_asn1_GenString(&ticket->DomainName));
			kull_m_asn1_append_ctx_and_data_to_seq(&Seq_Ticket, ID_CTX_TICKET_SNAME, kuhl_m_kerberos_ticket_createSequencePrimaryName(ticket->ServiceName));
			kull_m_asn1_append_ctx_and_data_to_seq(&Seq_Ticket, ID_CTX_TICKET_ENC_PART, kuhl_m_kerberos_ticket_createSequenceEncryptedData((UCHAR) ticket->TicketEncType, (UCHAR) ticket->TicketKvno, ticket->Ticket.Value, ticket->Ticket.Length));
			kull_m_asn1_append(&App_Ticket, Seq_Ticket);
		}
	}
	return App_Ticket;
}