6
6
import java .nio .ByteBuffer ;
7
7
import javax .microedition .rms .*;
8
8
import java .util .Hashtable ;
9
- import util .IntToBytes ;
10
9
11
10
public class Configuration {
12
11
private RecordStore recordStore ;
@@ -15,7 +14,7 @@ public class Configuration {
15
14
public static final byte TOTP = 1 ;
16
15
public static final byte HOTP = 2 ;
17
16
public static final byte TimeConfig = 3 ;
18
- private int timeOffset = 0 ;
17
+ private byte timeOffset = 0 ;
19
18
private int offsetRecordId = -1 ;
20
19
21
20
public Configuration () {
@@ -25,9 +24,7 @@ public Configuration() {
25
24
recordStore .setMode (RecordStore .AUTHMODE_PRIVATE , false );
26
25
RecordEnumeration re = recordStore .enumerateRecords (null , null , false );
27
26
while (re .hasNextElement ()) {
28
- int recId = re .nextRecordId ();
29
- byte [] record = recordStore .getRecord (recId );
30
- record [record .length -1 ] = (byte )recId ;
27
+ byte [] record = re .nextRecord ();
31
28
int type = getEntryTypeFromRecordBytes (record );
32
29
if (Configuration .TOTP == type ) {
33
30
TotpEntry e = TotpEntry .fromBytes (record );
@@ -46,23 +43,13 @@ public Configuration() {
46
43
}
47
44
48
45
private void setTimeOffset (byte [] record ) {
49
- ByteArrayOutputStream b_id_baos = new ByteArrayOutputStream ();
50
- DataOutputStream b_id = new DataOutputStream (b_id_baos );
51
- ByteArrayOutputStream b_sec_baos = new ByteArrayOutputStream ();
52
- DataOutputStream b_sec = new DataOutputStream (b_sec_baos );
53
- int section = 0 ;
54
- for (int i = 0 ; i < record .length ; i ++) {
55
- if (Configuration .DELIM == record [i ]) {
56
- section ++;
57
- }
58
- switch (section ) {
59
- case 3 :
60
- timeOffset = record [i ] - 120 ;
61
- break ;
62
- case 4 :
63
- offsetRecordId = record [i ];
64
- }
46
+ if (record .length != 9 ) {
47
+ System .err .println ("Corrupt time offset configuration entry." );
48
+ return ;
65
49
}
50
+ timeOffset = record [6 ];
51
+ offsetRecordId = record [8 ];
52
+ System .out .println ("Time offset from config: " + timeOffset );
66
53
}
67
54
68
55
private int getEntryTypeFromRecordBytes (byte [] record ) {
@@ -114,7 +101,6 @@ public void updateOffsetSeconds(byte seconds) {
114
101
try {
115
102
timeOffset = seconds ;
116
103
byte [] record = new byte [9 ];
117
-
118
104
recordStore = RecordStore .openRecordStore ("Hotpants" ,true );
119
105
recordStore .setMode (RecordStore .AUTHMODE_PRIVATE , true );
120
106
boolean isNew = offsetRecordId == -1 ;
@@ -127,7 +113,7 @@ public void updateOffsetSeconds(byte seconds) {
127
113
record [3 ] = DELIM ;
128
114
record [4 ] = TimeConfig ;
129
115
record [5 ] = DELIM ;
130
- record [6 ] = ( byte )( seconds + 120 ) ;
116
+ record [6 ] = seconds ;
131
117
record [7 ] = DELIM ;
132
118
record [8 ] = (byte )offsetRecordId ;
133
119
@@ -141,7 +127,7 @@ public void updateOffsetSeconds(byte seconds) {
141
127
}
142
128
}
143
129
144
- public int getOffsetSeconds () {
130
+ public byte getOffsetSeconds () {
145
131
return timeOffset ;
146
132
}
147
133
0 commit comments