Repository navigation
Expand file tree
/
Copy pathCVMResults.java
More file actions
98 lines (84 loc) · 2.87 KB
/
Copy pathCVMResults.java
File metadata and controls
98 lines (84 loc) · 2.87 KB
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
/*
* Copyright 2010 sasc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sasc.emv;
import java.io.PrintWriter;
import java.io.StringWriter;
import sasc.util.Log;
import sasc.util.Util;
/**
* Transaction Status Information (TSI)
*
* @author sasc
*/
public class CVMResults {
private byte firstByte;
private byte secondByte;
private byte thirdByte;
public CVMResults() {
this((byte) 0x00, (byte) 0x00, (byte) 0x00); //Initialize with all bits unset
}
public CVMResults(byte firstByte, byte secondByte, byte thirdByte) {
this.firstByte = firstByte;
this.secondByte = secondByte;
this.thirdByte = thirdByte;
}
public void setCVMResults(byte first, byte second, byte third) {
this.firstByte = first;
this.secondByte = second;
this.thirdByte = third;
}
public String getCVMResults() {
if (thirdByte == 0x00) {
return "CVM Result: Unknown";
} else if (thirdByte == 0x01) {
return "CVM Result: Fail/No CVM Condition Code was satisfied/CVM Code was not recognized or not supported";
} else {
return "CVM Result: Success";
}
}
public String getCVMValue() {
return "CVM Value: " + Util.prettyPrintHex(getBytes());
}
public void reset() {
firstByte = 0x00;
secondByte = 0x00;
thirdByte = 0x00;
}
public byte[] getBytes() {
return new byte[]{firstByte, secondByte, thirdByte};
}
@Override
public String toString() {
StringWriter sw = new StringWriter();
dump(new PrintWriter(sw), 0);
return sw.toString();
}
public void dump(PrintWriter pw, int indent) {
pw.println(Util.getSpaces(indent) + "CVM Results:");
String indentStr = Util.getSpaces(indent + Log.INDENT_SIZE);
pw.println(indentStr + getCVMValue());
pw.println(indentStr + getCVMResults());
}
public static void main(String[] args) {
CVMResults cvmr;
cvmr = new CVMResults((byte) 0x68, (byte) 0x00, (byte) 0x00);
System.out.println(cvmr.toString());
/*tsi = new CVMResults((byte)0xE8, (byte)0x00);
System.out.println(tsi.toString()); //VISA Comfort Hotel
tsi = new CVMResults((byte)0xF8, (byte)0x00);
System.out.println(tsi.toString()); //VISA Inside premium hotel (DE)*/
}
}