package org.irmacard.idemix.util;

public class IdemixFlags {

	private short pinProtectionMask;
	private byte RFU;
	
	public IdemixFlags(byte[] flags) {
		pinProtectionMask = getShortAt(flags, 0);
		RFU = flags[2];
	}
	
	public IdemixFlags() {
		pinProtectionMask = 0;
		RFU = 0;
	}
	
	public IdemixFlags(short pinProtectionMask) {
		this.pinProtectionMask = pinProtectionMask;
		RFU = 0;
	}
	
	public IdemixFlags(short pinProtectionMask, byte RFU) {
		this.pinProtectionMask = pinProtectionMask;
		this.RFU = RFU;
	}

	public byte[] getFlagBytes() {
		byte[] flags = new byte[3];
		flags = putShortAt(flags, 0, pinProtectionMask);
		flags[2] = RFU;
		return flags;
	}
	
	public short getPinProtectionMask() {
		return pinProtectionMask;
	}
	
	public byte getRFU() {
		return RFU;
	}
	
	private static short getShortAt(byte[] array, int idx) {
		return (short) ((array[idx] << 8) + array[idx + 1]);
	}
	
	private static byte[] putShortAt(byte[] array, int idx, int value) {
		array[idx] = (byte) (value >> 8);
		array[idx + 1] = (byte) (value & 0xff);
		return array;
	}
}

@@ -28,16 +28,17 @@
 .util;%0A%0A
+%0A
 public c
@@ -112,16 +112,52 @@
  RFU;%0A%09%0A
+%09public static final int SIZE = 3;%0A%0A
 %09public 
@@ -894,16 +894,17 @@
 hort) ((
+(
 array%5Bid
@@ -909,17 +909,26 @@
 idx%5D
+ & 0xff)
  %3C%3C 8) 
-+ 
+%7C (
 arra
@@ -937,16 +937,24 @@
 idx + 1%5D
+ & 0xff)
 );%0A%09%7D%0A%09%0A

Fix bug in getShortAt function