package mixconfig.tools.dataretention.smartcard.commands;

import java.math.BigInteger;

import anon.crypto.MyRSAPublicKey;
import mixconfig.tools.dataretention.smartcard.ApduConstants;
import mixconfig.tools.dataretention.smartcard.Helpers;

public class GetPublicKeyCommand extends AbstractCommand {

	public GetPublicKeyCommand() {
		instruction = ApduConstants.INSTRUCTION_GET_PUBLIC_KEY;
		expectedReturnDataLength = 2;
	}

	public MyRSAPublicKey getPublicKey(byte[] response) {
		BigInteger exponent = new BigInteger(Helpers.copyOfRange(response, 1, rawResponse[0]));
		BigInteger modulus = new BigInteger(Helpers.copyOfRange(response, rawResponse[0] + 1, response.length));
		return new MyRSAPublicKey(modulus, exponent);
	}

	public int size() {
		return Helpers.bytesToShort(rawResponse);
	}

}
