[Impressum] [E-Mail]

package generated.javacard.copycardMoneySecure.copycard;

import javacard.security.RandomData;
import javacard.framework.*;

/**
 * generated Nonce class for random numbers
 */
public class Nonce implements Codeable, HashData {

	public byte[] nonce;
	private static RandomData rd = RandomData
			.getInstance(RandomData.ALG_SECURE_RANDOM);

	public Nonce() {
		nonce = new byte[Store.LENGTHOFNONCE];
		rd.generateData(nonce, (short) 0, (short) nonce.length);
	}

	public void copy(Nonce o) {
		Arrays.copy(o.nonce, nonce);
	}

	public byte getCode() {
		return Code.NONCE;
	}

	public boolean equals(Codeable other) {
		if (getCode() != other.getCode())
			return false;
		return Arrays.equals(nonce, ((Nonce) other).nonce);
	}

	/**
	 * creates new random values in the nonce field
	 * 
	 * @return a new nonce object (from the store)
	 */
	public static Nonce generateNonce() {
		return Store.newNonce().instGenerateNonce();
	}

	private Nonce instGenerateNonce() {
		rd.generateData(nonce, (short) 0, (short) nonce.length);
		return this;
	}
}