summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/uic/barcode/dynamicContent/fdc1/UicDynamicContentDataFDC1.java
blob: c658448ae0691b4a22b4ed7099f4485670d1266a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 * 
 */
package org.uic.barcode.dynamicContent.fdc1;

import java.io.UnsupportedEncodingException;
import org.uic.barcode.asn1.datatypes.Asn1Optional;
import org.uic.barcode.asn1.datatypes.CharacterRestriction;
import org.uic.barcode.asn1.datatypes.FieldOrder;
import org.uic.barcode.asn1.datatypes.HasExtensionMarker;
import org.uic.barcode.asn1.datatypes.RestrictedString;
import org.uic.barcode.asn1.datatypes.Sequence;
import org.uic.barcode.asn1.uper.UperEncoder;
import org.uic.barcode.dynamicFrame.DataType;


/**
 * The Class UicDynamicContentData.
 * 
 * The dynamic content for FDC1
 * 
 */




@Sequence
@HasExtensionMarker
public class UicDynamicContentDataFDC1  {
	
	

    /*
    -- The possible values are defined by the security provider
    --   (the security provider being UicBarcodeHeader.level2SignedData.level1Data.securityProviderNum/IA5)
    dynamicContentMobileAppId IA5String OPTIONAL,
    */
	//timestamp when the bar code was created
	@FieldOrder(order = 0)
	@RestrictedString(CharacterRestriction.IA5String)
	@Asn1Optional public String appId;	

	//timestamp when the bar code was created
	@FieldOrder(order = 1)	
	@Asn1Optional public TimeStamp timeStamp;
	

    //-- Coordinates of the place where the dynamic content has been generated
    // --   (same GeoCoordinateType type as in UicRailTicketData)
    /** The geo coordinate. */
    //dynamicContentGeoCoordinate GeoCoordinateType OPTIONAL,
	@FieldOrder(order = 2)	
	@Asn1Optional public GeoCoordinateType geoCoordinate;
    //-- Response from the mobile to any data received from the terminal.
    //--   The data received from the terminal may be a random number, or any other information.
    //--   The response may be the data itself, a hashing of this data, or any other response.
	// --   This response may be completed with other information: IMEI, mobile phone number...
    //-- The type used is ExtensionData, as it is fully adapted. 
	// -- extensionId shall be set to:
	// -- * "=" if the data included in extensionData is exactly the one that was transmitted by the terminal,
	// -- * any other value (chosen by the issuer) in other cases.
    /** The challenge response. */

	@FieldOrder(order = 3)
	@Asn1Optional public SequenceOfExtension extensions;


	
    //...



	/**
	 * Gets the geo coordinate.
	 *
	 * @return the geo coordinate
	 */
	public GeoCoordinateType getGeoCoordinate() {
		return geoCoordinate;
	}

	/**
	 * Sets the geo coordinate.
	 *
	 * @param geoCoordinate the new geo coordinate
	 */
	public void setGeoCoordinate(GeoCoordinateType geoCoordinate) {
		this.geoCoordinate = geoCoordinate;
	}
	
	public static String getFormat() {
		return "FDC1";
	}
	
	public DataType getDataType() {
		DataType data = new DataType();
		data.setFormat(getFormat());
		data.setByteData(UperEncoder.encode(this));
		return data;
	}

	public String getChallengeString() {
		if (this.extensions != null) {
			for (ExtensionData ed  : extensions) {
				if (ed.getExtensionId().equals("=")) {
					byte[] c = ed.getExtensionData();
					try {
						return new String(c,"UTF-8");
					} catch (UnsupportedEncodingException e) {
						return null;
					}
				}
			}
		}
		return null;
	}

	public void setChallengeString(String challengeString) {
		if (extensions == null) {
			extensions = new SequenceOfExtension();
		};
		ExtensionData ed = new ExtensionData();
		ed.setExtensionId("=");
		try {
			ed.setExtensionData(challengeString.getBytes("UTF-8"));
		} catch (UnsupportedEncodingException e) {
			return;
		}
		extensions.add(ed);
	}

	public byte[] getPhoneIdHash() {
		if (this.extensions != null) {
			for (ExtensionData ed  : extensions) {
				if (ed.getExtensionId().equals("phone")) {
					return ed.getExtensionData();
				}
			}
		}
		return null;
	}

	public void setPhoneIdHash(byte[] phoneIdHash) {
		if (extensions == null) {
			extensions = new SequenceOfExtension();
		};
		ExtensionData ed = new ExtensionData();
		ed.setExtensionId("phone");
		ed.setExtensionData(phoneIdHash);
		extensions.add(ed);
	}

	public byte[] getPassIdHash() {
		if (this.extensions != null) {
			for (ExtensionData ed  : extensions) {
				if (ed.getExtensionId().equals("pass")) {
					return ed.getExtensionData();
				}
			}
		}
		return null;
	}

	public void setPassIdHash(byte[] passIdHash) {
		if (extensions == null) {
			extensions = new SequenceOfExtension();
		};
		ExtensionData ed = new ExtensionData();
		ed.setExtensionId("pass");
		ed.setExtensionData(passIdHash);
		extensions.add(ed);
	}

	public TimeStamp getTimeStamp() {
		return timeStamp;
	}

	public void setTimeStamp(TimeStamp timeStamp) {
		this.timeStamp = timeStamp;
	}

	public SequenceOfExtension getExtensions() {
		return extensions;
	}

	public void setExtensions(SequenceOfExtension extensions) {
		this.extensions = extensions;
	}
	
	public byte[] encode() {
		return UperEncoder.encode(this);
	}

	public String getAppId() {
		return appId;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}

	
	
}