/**
 * Attributes.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) Pim Vullers, Radboud University Nijmegen, May 2012,
 * Copyright (C) Wouter Lueks, Radboud University Nijmegen, August 2012.
 */

package org.irmacard.credentials;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * A generic container class for attributes. Possibly this will just manage 
 * attribute id and value pairs.
 */
public class Attributes implements Serializable {
	private static final long serialVersionUID = 1L;
	
	// TODO: provide an implementation for attribute storage.
	private Map<String, byte[]> attributes;
	
	public Attributes() {
		attributes = new HashMap<String, byte[]>();
	}
	
	public void add(String id, byte[] value) {
		attributes.put(id, value);
	}
	
	public byte[] get(String id) {
		return attributes.get(id);
	}

	public Set<String> getIdentifiers() {
		return attributes.keySet();
	}

	public void print() {
		for(String k : attributes.keySet() ) {
			System.out.println(k + ": " + new String(get(k)));
		}
	}
	
	public String toString() {
		String res = "[";
		for(String k : attributes.keySet() ) {
			res += k + ": " + new String(get(k)) + ", ";
		}
		res += "]";
		return res;
	}
}

@@ -882,16 +882,95 @@
 izable;%0A
+import java.math.BigInteger;%0Aimport java.util.Calendar;%0Aimport java.util.Date;%0A
 import j
@@ -983,24 +983,24 @@
 il.HashMap;%0A
-
 import java.
@@ -1250,17 +1250,168 @@
 D = 1L;%0A
-%09
+%0A%09/**%0A%09 * Precision factor for the expiry attribute, 1 means millisecond precision.%0A%09 */%0A%09public final static long EXPIRY_FACTOR = 1000 * 60 * 60 * 24;%0A
 %0A%09// TOD
@@ -1573,16 +1573,88 @@
 te%5B%5D%3E();
+%0A%0A%09%09// Set expiry attribute to default value%0A%09%09setExpiryAttribute(null);
 %0A%09%7D%0A%09%0A%09p
@@ -2149,16 +2149,16 @@
 += %22%5D%22;%0A
-
 %09%09return
@@ -2165,11 +2165,1241 @@
  res;%0A%09%7D
+%0A%0A%09/**%0A%09 * Set the expiry attribute. This attribute is mandatory,%0A%09 * if no Date is specified (i.e. expiry == null) then the default expiry time%0A%09 * of six monts is used. Note that the granularity of the expiry time is set%0A%09 * by EXPIRY_FACTOR.%0A%09 * @param values the standard set of attributes%0A%09 * @param expiry optional expiry date, if null, default is used.%0A%09 */%0A%09public void setExpiryAttribute(Date expiry) %7B%0A%09%09Calendar expires = Calendar.getInstance();%0A%09%09if (expiry != null) %7B%0A%09%09%09expires.setTime(expiry);%0A%09%09%7D else %7B%0A%09%09%09expires.add(Calendar.MONTH, 6);%0A%09%09%7D%0A        add(%22expiry%22, BigInteger.valueOf(%0A        %09%09expires.getTimeInMillis() / EXPIRY_FACTOR).toByteArray());%0A%09%7D%0A%0A%09/**%0A%09 * Test whether the the credential containing these attributes is still valid%0A%09 * on the given date.%0A%09 * @return validity%0A%09 */%0A%09public boolean isValidOn(Date date) %7B%0A%09%09Calendar expires = Calendar.getInstance();%0A%09%09expires.setTimeInMillis((new BigInteger(get(%22expiry%22))).longValue()%0A%09%09%09%09* EXPIRY_FACTOR);%0A%0A%09%09return date.before(expires.getTime());%0A%09%7D%0A%0A%09/**%0A%09 * Test whether the credential containing these attributes is currently still valid.%0A%09 * @return validity%0A%09 */%0A%09public boolean isValid() %7B%0A%09%09return isValidOn(Calendar.getInstance().getTime());%0A%09%7D
 %0A%7D%0A

Check validity on attributes