// Path: animamea/src/de/tsenger/animamea/asn1/CertificateHolderAuthorizationTemplate.java
// public class CertificateHolderAuthorizationTemplate extends ASN1Object{
// 
// 	private ASN1ObjectIdentifier terminalType = null;
// 	private DiscretionaryData auth = null;
// 	private byte role;
// 	
// 	/** Constructor for Encoding a CHAT
// 	 * @param terminalType OID for the terminal type to use
// 	 * @param disData
// 	 */
// 	public CertificateHolderAuthorizationTemplate(ASN1ObjectIdentifier terminalType,	DiscretionaryData disData) {
// 		this.terminalType = terminalType;
// 		this.auth = disData;		 
// 	}
// 	
// 	/** Constructor for Decoding CHAT from SEQUENCE
// 	 * @param chatSeq
// 	 * @throws IOException
// 	 */
// 	public CertificateHolderAuthorizationTemplate(ASN1Sequence chatSeq) throws IOException {
// 		this.terminalType = (ASN1ObjectIdentifier) chatSeq.getObjectAt(0);
// 		
// 		DEROctetString oct = (DEROctetString) ((DERApplicationSpecific) chatSeq.getObjectAt(1)).getObject(BERTags.OCTET_STRING);
// 		this.auth = new DiscretionaryData(oct.getOctets());
// 		
// 	}
// 
// 
// 	
// 	public byte getRole(){
// 		this.role = (byte) (auth.getData()[0] & 0xc0);
// 		return role;
// 	}
// 
// 	/* (non-Javadoc)
// 	 * @see org.bouncycastle.asn1.ASN1Object#toASN1Primitive()
// 	 */
// 	@Override
// 	public ASN1Primitive toASN1Primitive() {
// 		ASN1EncodableVector v = new ASN1EncodableVector();
// 		v.add(terminalType);
// 		v.add(auth);
//  
// 		return new DERApplicationSpecific(0x4c, v);
// 	}
// 
// 
// }


import de.tsenger.animamea.asn1.CertificateHolderAuthorizationTemplate;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.smartcardio.CommandAPDU;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERTaggedObject;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public void setAuxiliaryAuthenticatedData() throws UnsupportedOperationException {
		// TODO noch zu implementieren, Tag 0x67
		throw new UnsupportedOperationException("setAuxiliaryAuthenticationData not yet implemented!");
	}

	/**
	 * Setzt das Tag 0x91 (Ephemeral Public Key). Der PK muss bereits komprimiert 
	 * (siehe comp()-Funktion in TR-03110) sein.
	 * @param pubKey comp(ephemeral PK_PCD) -> TR-03110 A.2.2.3
	 */
	public void setEphemeralPublicKey(byte[] pubKey) {
		DERTaggedObject to = new DERTaggedObject(false, 0x11, new DEROctetString(pubKey));
		try {
			do91EphemeralPublicKEy = to.getEncoded(ASN1Encoding.DER);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @param chat
	 */
// Path: animamea/src/de/tsenger/animamea/asn1/CertificateHolderAuthorizationTemplate.java
// public class CertificateHolderAuthorizationTemplate extends ASN1Object{
// 
// 	private ASN1ObjectIdentifier terminalType = null;
// 	private DiscretionaryData auth = null;
// 	private byte role;
// 	
// 	/** Constructor for Encoding a CHAT
// 	 * @param terminalType OID for the terminal type to use
// 	 * @param disData
// 	 */
// 	public CertificateHolderAuthorizationTemplate(ASN1ObjectIdentifier terminalType,	DiscretionaryData disData) {
// 		this.terminalType = terminalType;
// 		this.auth = disData;		 
// 	}
// 	
// 	/** Constructor for Decoding CHAT from SEQUENCE
// 	 * @param chatSeq
// 	 * @throws IOException
// 	 */
// 	public CertificateHolderAuthorizationTemplate(ASN1Sequence chatSeq) throws IOException {
// 		this.terminalType = (ASN1ObjectIdentifier) chatSeq.getObjectAt(0);
// 		
// 		DEROctetString oct = (DEROctetString) ((DERApplicationSpecific) chatSeq.getObjectAt(1)).getObject(BERTags.OCTET_STRING);
// 		this.auth = new DiscretionaryData(oct.getOctets());
// 		
// 	}
// 
// 
// 	
// 	public byte getRole(){
// 		this.role = (byte) (auth.getData()[0] & 0xc0);
// 		return role;
// 	}
// 
// 	/* (non-Javadoc)
// 	 * @see org.bouncycastle.asn1.ASN1Object#toASN1Primitive()
// 	 */
// 	@Override
// 	public ASN1Primitive toASN1Primitive() {
// 		ASN1EncodableVector v = new ASN1EncodableVector();
// 		v.add(terminalType);
// 		v.add(auth);
//  
// 		return new DERApplicationSpecific(0x4c, v);
// 	}
// 
// 
// }


// Path: animamea/src/de/tsenger/animamea/iso7816/MSESetAT.java
import de.tsenger.animamea.asn1.CertificateHolderAuthorizationTemplate;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.smartcardio.CommandAPDU;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERTaggedObject;

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public void setAuxiliaryAuthenticatedData() throws UnsupportedOperationException {
		// TODO noch zu implementieren, Tag 0x67
		throw new UnsupportedOperationException("setAuxiliaryAuthenticationData not yet implemented!");
	}

	/**
	 * Setzt das Tag 0x91 (Ephemeral Public Key). Der PK muss bereits komprimiert 
	 * (siehe comp()-Funktion in TR-03110) sein.
	 * @param pubKey comp(ephemeral PK_PCD) -> TR-03110 A.2.2.3
	 */
	public void setEphemeralPublicKey(byte[] pubKey) {
		DERTaggedObject to = new DERTaggedObject(false, 0x11, new DEROctetString(pubKey));
		try {
			do91EphemeralPublicKEy = to.getEncoded(ASN1Encoding.DER);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @param chat
	 */
	public void setCHAT(CertificateHolderAuthorizationTemplate chat) {