<commit_before>/**
 * IdemixCredentials.java
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 * Copyright (C) <NAME>, <NAME>, May 2012.
 */

package credentials.idemix;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.ru.irma.api.tests.idemix.TestSetup;

import net.sourceforge.scuba.smartcards.CardService;
import net.sourceforge.scuba.smartcards.CardServiceException;
import service.IdemixService;
import service.IdemixSmartcard;
import service.ProtocolCommand;
import service.ProtocolResponses;

import com.ibm.zurich.idmx.issuance.Issuer;
import com.ibm.zurich.idmx.issuance.Message;
import com.ibm.zurich.idmx.showproof.Proof;
import com.ibm.zurich.idmx.showproof.Verifier;
import com.ibm.zurich.idmx.utils.SystemParameters;

import credentials.Attributes;
import credentials.BaseCredentials;
import credentials.CredentialsException;
import credentials.Nonce;
import credentials.idemix.spec.IdemixIssueSpecification;
import credentials.idemix.spec.IdemixVerifySpecification;
import credentials.keys.PrivateKey;
import credentials.spec.IssueSpecification;
import credentials.spec.VerifySpecification;

/**
 * An Idemix specific implementation of the credentials interface.
 */
public class IdemixCredentials extends BaseCredentials {
	IdemixService service = null;

	public IdemixCredentials() {
		// TODO
	}

	public IdemixCredentials(CardService cs) {
		super(cs);
	}

	/**
	 * Issue a credential to the user according to the provided specification
	 * containing the specified values.
	 *
	 * @param specification
	 *            of the issuer and the credential to be issued.
	 * @param values
	 *            to be stored in the credential.
	 * @throws CredentialsException
	 *             if the issuance process fails.
	 */
	@Override
	public void issue(IssueSpecification specification, PrivateKey sk,
			Attributes values) throws CredentialsException {
		IdemixIssueSpecification spec = castIssueSpecification(specification);
		IdemixPrivateKey isk = castIdemixPrivateKey(sk);

		setupService(spec);

		// Initialise the issuer
		Issuer issuer = new Issuer(isk.getIssuerKeyPair(), spec.getIssuanceSpec(),
				null, null, spec.getValues(values));

		// Initialise the recipient
		try {
			service.open();
			service.sendPin(TestSetup.DEFAULT_PIN);
			service.setIssuanceSpecification(spec.getIssuanceSpec());
			service.setAttributes(spec.getIssuanceSpec(),
					spec.getValues(values));
		} catch (CardServiceException e) {
			throw new CredentialsException(
					"Failed to issue the credential (SCUBA)");
		}

		// Issue the credential
		Message msgToRecipient1 = issuer.round0();
		if (msgToRecipient1 == null) {
			throw new CredentialsException("Failed to issue the credential (0)");
		}

		Message msgToIssuer1 = service.round1(msgToRecipient1);
		if (msgToIssuer1 == null) {
			throw new CredentialsException("Failed to issue the credential (1)");<commit_msg>Note: credentials api uses default pin to issue<commit_after>/**
 * IdemixCredentials.java
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 * Copyright (C) <NAME>, <NAME>, May 2012.
 */

package credentials.idemix;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.ru.irma.api.tests.idemix.TestSetup;

import net.sourceforge.scuba.smartcards.CardService;
import net.sourceforge.scuba.smartcards.CardServiceException;
import service.IdemixService;
import service.IdemixSmartcard;
import service.ProtocolCommand;
import service.ProtocolResponses;

import com.ibm.zurich.idmx.issuance.Issuer;
import com.ibm.zurich.idmx.issuance.Message;
import com.ibm.zurich.idmx.showproof.Proof;
import com.ibm.zurich.idmx.showproof.Verifier;
import com.ibm.zurich.idmx.utils.SystemParameters;

import credentials.Attributes;
import credentials.BaseCredentials;
import credentials.CredentialsException;
import credentials.Nonce;
import credentials.idemix.spec.IdemixIssueSpecification;
import credentials.idemix.spec.IdemixVerifySpecification;
import credentials.keys.PrivateKey;
import credentials.spec.IssueSpecification;
import credentials.spec.VerifySpecification;

/**
 * An Idemix specific implementation of the credentials interface.
 */
public class IdemixCredentials extends BaseCredentials {
	IdemixService service = null;

	public IdemixCredentials() {
		// TODO
	}

	public IdemixCredentials(CardService cs) {
		super(cs);
	}

	/**
	 * Issue a credential to the user according to the provided specification
	 * containing the specified values.
	 *
	 * @param specification
	 *            of the issuer and the credential to be issued.
	 * @param values
	 *            to be stored in the credential.
	 * @throws CredentialsException
	 *             if the issuance process fails.
	 */
	@Override
	public void issue(IssueSpecification specification, PrivateKey sk,
			Attributes values) throws CredentialsException {
		IdemixIssueSpecification spec = castIssueSpecification(specification);
		IdemixPrivateKey isk = castIdemixPrivateKey(sk);

		setupService(spec);

		// Initialise the issuer
		Issuer issuer = new Issuer(isk.getIssuerKeyPair(), spec.getIssuanceSpec(),
				null, null, spec.getValues(values));

		// Initialise the recipient
		try {
			service.open();
			// FIXME: Change this!
			service.sendPin(TestSetup.DEFAULT_PIN);
			service.setIssuanceSpecification(spec.getIssuanceSpec());
			service.setAttributes(spec.getIssuanceSpec(),
					spec.getValues(values));
		} catch (CardServiceException e) {
			throw new CredentialsException(
					"Failed to issue the credential (SCUBA)");
		}

		// Issue the credential
		Message msgToRecipient1 = issuer.round0();
		if (msgToRecipient1 == null) {
			throw new CredentialsException("Failed to issue the credential (0)");
		}

		Message msgToIssuer1 = service.round1(msgToRecipient1);
		if (msgToIssuer1 == null) {
			throw new CredentialsException("Failed to issue the credential (1)");
{'fraction_non_alphanumeric': 0.08737191913597342, 'fraction_numerical': 0.003877042370534478, 'mean_word_length': 4.484434320425208, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6098241', 'n_tokens_mistral': 2227, 'n_tokens_neox': 2045, 'n_words': 621}