@regulaforensics/cordova-plugin-document-reader-api 5.7.0 → 6.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -42,7 +42,7 @@ If you have issues with license verification when running the application, pleas
42
42
  6. You placed the `license` into the correct folder as described [here](#how-to-build-demo-application).
43
43
 
44
44
  ## Documentation
45
- You can find documentation on API [here](https://docs.regulaforensics.com/cordova).
45
+ You can find documentation on API [here](https://docs.regulaforensics.com/develop/doc-reader-sdk/mobile/cordova).
46
46
 
47
47
  ## Additional information
48
48
  If you have any technical questions, feel free to [contact](mailto:cordova.support@regulaforensics.com) us or create issue [here](https://github.com/regulaforensics/DocumentReader-Cordova-Plugin/issues).
@@ -16,11 +16,12 @@
16
16
  "cordova-android": "^9.0.0",
17
17
  "cordova-ios": "^6.1.1",
18
18
  "cordova-plugin-add-swift-support": "^2.0.2",
19
- "@regulaforensics/cordova-plugin-document-reader-api": "^5.7.0",
20
- "@regulaforensics/cordova-plugin-document-reader-core-fullrfid": "^5.7.0",
19
+ "@regulaforensics/cordova-plugin-document-reader-api": "^6.1.2",
20
+ "@regulaforensics/cordova-plugin-document-reader-core-fullrfid": "^6.1.0",
21
21
  "cordova-plugin-file": "^6.0.2",
22
22
  "cordova-plugin-image-picker": "^1.1.3",
23
- "cordova-plugin-android-permissions": "1.1.0"
23
+ "cordova-plugin-android-permissions": "1.1.0",
24
+ "cordova-plugin-advanced-http": "3.2.1"
24
25
  },
25
26
  "cordova": {
26
27
  "plugins": {
@@ -34,7 +35,8 @@
34
35
  "PHOTO_LIBRARY_USAGE_DESCRIPTION": " "
35
36
  },
36
37
  "cordova-plugin-whitelist": {},
37
- "cordova-plugin-android-permissions": {}
38
+ "cordova-plugin-android-permissions": {},
39
+ "cordova-plugin-advanced-http": {}
38
40
  },
39
41
  "platforms": [
40
42
  "android",
@@ -43,7 +43,7 @@
43
43
 
44
44
  <div>
45
45
  <div id="scenariosRadioGroup"
46
- style="position: absolute; bottom: 100px; top: 225px; left: 75px; width:225px; padding: 5px; text-align:left; overflow: auto"/>
46
+ style="position: absolute; bottom: 140px; top: 225px; left: 75px; width:225px; padding: 5px; text-align:left; overflow: auto"/>
47
47
  </div>
48
48
 
49
49
  <div style="position: absolute; bottom: 10px; width: 100%; text-align: center; align-items: center">
@@ -52,6 +52,11 @@
52
52
  id="rfidCheckboxText"
53
53
  style="color: lightgrey"> Process rfid reading(unavailable)</span><br>
54
54
  </div>
55
+ <div id="encryptionDiv" style="flex-direction: row; padding: 5px">
56
+ <input id="encryptionCheckbox" type="checkbox" name="rfid" disabled><span
57
+ id="encryptionCheckboxText"
58
+ style="color: lightgrey"> Data encryption(unavailable)</span><br>
59
+ </div>
55
60
  <div style="flex-direction: row; padding: 10px">
56
61
  <button id="showScannerButton" style="margin-right: 20px">scan doc</button>
57
62
  <button id="showImagePicker" style="margin-left: 20px">scan image</button>
@@ -7,10 +7,13 @@ var app = {
7
7
  this.receivedEvent('deviceready')
8
8
  document.getElementById("status").innerHTML = "loading......"
9
9
  document.getElementById("status").style.backgroundColor = "grey"
10
+ var http = cordova.plugin.http
10
11
  var DocumentReaderResults = DocumentReader.DocumentReaderResults
11
12
  var DocumentReaderScenario = DocumentReader.DocumentReaderScenario
12
13
  var Enum = DocumentReader.Enum
13
14
  var doRfid = false
15
+ var encryption = false
16
+ const ENCRYPTED_RESULT_SERVICE = "https://api.regulaforensics.com/api/process"
14
17
  var isReadingRfid = false
15
18
  var rfidUIHeader = "Reading RFID"
16
19
  var rfidUIHeaderColor = "black"
@@ -47,10 +50,15 @@ var app = {
47
50
  if (canRfid) {
48
51
  document.getElementById("rfidCheckbox").disabled = false
49
52
  document.getElementById("rfidCheckboxText").style.color = "black"
50
- document.getElementById("rfidCheckboxText").innerHTML = "Process rfid reading"
53
+ document.getElementById("rfidCheckboxText").innerHTML = " Process rfid reading"
51
54
  document.getElementById("rfidCheckboxText").onclick = function () { document.getElementById("rfidCheckbox").click() }
52
55
  document.getElementById("rfidCheckbox").onchange = function () { doRfid = this.checked }
53
56
  }
57
+ document.getElementById("encryptionCheckbox").disabled = false
58
+ document.getElementById("encryptionCheckboxText").style.color = "black"
59
+ document.getElementById("encryptionCheckboxText").innerHTML = " Data encryption"
60
+ document.getElementById("encryptionCheckboxText").onclick = function () { document.getElementById("encryptionCheckbox").click() }
61
+ document.getElementById("encryptionCheckbox").onchange = function () { encryption = this.checked }
54
62
  }
55
63
 
56
64
  function scan() {
@@ -173,16 +181,16 @@ var app = {
173
181
  var taCert = "taCertificateCompletionEvent"
174
182
  var taSig = "taSignatureCompletionEvent"
175
183
  DocumentReader.startRFIDReader(function (m) {
176
- if(m.substring(0, notification.length) === notification) {
184
+ if (m.substring(0, notification.length) === notification) {
177
185
  m = m.substring(notification.length, m.length)
178
186
  console.log(notification + ": " + m)
179
- } else if(m.substring(0, paCert.length) === paCert) {
187
+ } else if (m.substring(0, paCert.length) === paCert) {
180
188
  m = m.substring(paCert.length, m.length)
181
189
  console.log(paCert + ": " + m)
182
- } else if(m.substring(0, taCert.length) === taCert) {
190
+ } else if (m.substring(0, taCert.length) === taCert) {
183
191
  m = m.substring(taCert.length, m.length)
184
192
  console.log(taCert + ": " + m)
185
- } else if(m.substring(0, taSig.length) === taSig) {
193
+ } else if (m.substring(0, taSig.length) === taSig) {
186
194
  m = m.substring(taSig.length, m.length)
187
195
  console.log(taSig + ": " + m)
188
196
  } else
@@ -205,7 +213,33 @@ var app = {
205
213
  //customRFID()
206
214
  usualRFID()
207
215
  } else
208
- displayResults(results)
216
+ if (encryption) {
217
+ var input = JSON.parse(results.rawResult)
218
+ var processParam = {
219
+ alreadyCropped: true,
220
+ scenario: "FullProcess"
221
+ }
222
+ var body = {
223
+ List: input["ContainerList"]["List"],
224
+ processParam: processParam
225
+ }
226
+ postRequest(body)
227
+ } else
228
+ displayResults(results)
229
+ }
230
+
231
+ function postRequest(body) {
232
+ document.getElementById("status").innerHTML = "Getting results from server......"
233
+ document.getElementById("status").style.backgroundColor = "grey"
234
+ http.setDataSerializer('utf8')
235
+ http.post(ENCRYPTED_RESULT_SERVICE, JSON.stringify(body), { "content-type": "application/json; utf-8" }, function (response) {
236
+ DocumentReader.parseCoreResults(response.data, function (m) {
237
+ displayResults(DocumentReader.DocumentReaderResults.fromJson(JSON.parse(m))) }, function (e) { })
238
+ }, function (response) {
239
+ console.error(response.error)
240
+ document.getElementById("status").innerHTML = "Something went wrong!"
241
+ document.getElementById("status").style.backgroundColor = "red"
242
+ })
209
243
  }
210
244
 
211
245
  function displayResults(results) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regulaforensics/cordova-plugin-document-reader-api",
3
- "version": "5.7.0",
3
+ "version": "6.1.2",
4
4
  "description": "Cordova plugin for reading and validation of identification documents (API framework)",
5
5
  "cordova": {
6
6
  "id": "@regulaforensics/cordova-plugin-document-reader-api",
package/plugin.xml CHANGED
@@ -1,5 +1,5 @@
1
1
  <?xml version='1.0' encoding='utf-8'?>
2
- <plugin id="cordova-plugin-document-reader-api" version="5.7.0"
2
+ <plugin id="cordova-plugin-document-reader-api" version="6.1.2"
3
3
  xmlns="http://apache.org/cordova/ns/plugins/1.0">
4
4
  <name>DocumentReaderApi</name>
5
5
  <description>Cordova plugin Document reader api</description>
@@ -25,7 +25,7 @@
25
25
  <podspec>
26
26
  <config/>
27
27
  <pods>
28
- <pod name="DocumentReader" spec="~> 5.7.2075" />
28
+ <pod name="DocumentReader" spec="~> 6.1.2374" />
29
29
  </pods>
30
30
  </podspec>
31
31
  </platform>
@@ -1,5 +1,6 @@
1
1
  package cordova.plugin.documentreader;
2
2
 
3
+ import android.annotation.SuppressLint;
3
4
  import android.app.Activity;
4
5
  import android.app.PendingIntent;
5
6
  import android.content.Context;
@@ -8,22 +9,26 @@ import android.content.IntentFilter;
8
9
  import android.graphics.Bitmap;
9
10
  import android.nfc.NfcAdapter;
10
11
  import android.nfc.tech.IsoDep;
12
+ import android.support.annotation.NonNull;
13
+ import android.os.Bundle;
11
14
  import android.util.Base64;
12
15
 
13
16
  import com.regula.documentreader.api.completions.IDocumentReaderCompletion;
14
17
  import com.regula.documentreader.api.completions.IDocumentReaderInitCompletion;
15
18
  import com.regula.documentreader.api.completions.IDocumentReaderPrepareCompletion;
16
- import com.regula.documentreader.api.completions.IRfidNotificationCompletion;
17
19
  import com.regula.documentreader.api.completions.IRfidPKDCertificateCompletion;
18
20
  import com.regula.documentreader.api.completions.IRfidReaderRequest;
19
21
  import com.regula.documentreader.api.completions.IRfidTASignatureCompletion;
20
22
  import com.regula.documentreader.api.enums.DocReaderAction;
21
23
  import com.regula.documentreader.api.errors.DocumentReaderException;
24
+ import com.regula.documentreader.api.internal.core.CoreScenarioUtil;
25
+ import com.regula.documentreader.api.params.DocReaderConfig;
22
26
  import com.regula.documentreader.api.params.ImageInputParam;
23
27
  import com.regula.documentreader.api.params.rfid.PKDCertificate;
24
28
  import com.regula.documentreader.api.params.rfid.authorization.PAResourcesIssuer;
25
29
  import com.regula.documentreader.api.params.rfid.authorization.TAChallenge;
26
30
  import com.regula.documentreader.api.results.DocumentReaderResults;
31
+ import com.regula.documentreader.api.parser.DocReaderResultsJsonParser;
27
32
 
28
33
  import org.apache.cordova.CallbackContext;
29
34
  import org.apache.cordova.CordovaPlugin;
@@ -33,6 +38,8 @@ import org.json.JSONObject;
33
38
  import org.json.JSONException;
34
39
 
35
40
  import java.io.File;
41
+ import java.io.IOException;
42
+ import java.io.InputStream;
36
43
  import java.util.ArrayList;
37
44
  import java.util.List;
38
45
 
@@ -108,8 +115,8 @@ public class DocumentReader extends CordovaPlugin {
108
115
  callbackContext.sendPluginResult(pluginResult);
109
116
  }
110
117
 
111
- private void sendIRfidNotificationCompletion(int notification) {
112
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, rfidNotificationCompletionEvent + notification);
118
+ private void sendIRfidNotificationCompletion(int notification, Bundle value) {
119
+ PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, rfidNotificationCompletionEvent + JSONConstructor.generateRfidNotificationCompletion(notification, value).toString());
113
120
  pluginResult.setKeepCallback(true);
114
121
  callbackContext.sendPluginResult(pluginResult);
115
122
  }
@@ -156,6 +163,9 @@ public class DocumentReader extends CordovaPlugin {
156
163
  };
157
164
  try {
158
165
  switch (action) {
166
+ case "initializeReaderAutomatically":
167
+ initializeReaderAutomatically(callback);
168
+ break;
159
169
  case "getAPIVersion":
160
170
  getAPIVersion(callback);
161
171
  break;
@@ -312,6 +322,9 @@ public class DocumentReader extends CordovaPlugin {
312
322
  case "provideTASignature":
313
323
  provideTASignature(callback, args(0));
314
324
  break;
325
+ case "parseCoreResults":
326
+ parseCoreResults(callback, args(0));
327
+ break;
315
328
  case "initializeReaderWithDatabasePath":
316
329
  initializeReaderWithDatabasePath(callback, args(0), args(1));
317
330
  break;
@@ -352,6 +365,7 @@ public class DocumentReader extends CordovaPlugin {
352
365
  };
353
366
  Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
354
367
  intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
368
+ @SuppressLint("UnspecifiedImmutableFlag")
355
369
  PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
356
370
  NfcAdapter.getDefaultAdapter(getActivity()).enableForegroundDispatch(activity, pendingIntent, filters, techList);
357
371
  }
@@ -363,10 +377,32 @@ public class DocumentReader extends CordovaPlugin {
363
377
  backgroundRFIDEnabled = false;
364
378
  }
365
379
 
380
+ private void initializeReaderAutomatically(Callback callback) {
381
+ if (!Instance().isReady())
382
+ try {
383
+ InputStream is = getContext().getAssets().open("regula.license");
384
+ byte[] license = new byte[is.available()];
385
+ //noinspection ResultOfMethodCallIgnored
386
+ is.read(license);
387
+ Instance().initializeReader(getContext(), new DocReaderConfig(license), getInitCompletion(callback));
388
+ is.close();
389
+ } catch (IOException e) {
390
+ e.printStackTrace();
391
+ callback.error("problem reading license(see logs)");
392
+ }
393
+ else
394
+ callback.success("already initialized");
395
+ }
396
+
366
397
  private void getAvailableScenarios(Callback callback) throws JSONException {
367
398
  callback.success(JSONConstructor.generateList(Instance().availableScenarios, JSONConstructor::generateDocumentReaderScenario).toString());
368
399
  }
369
400
 
401
+ private void parseCoreResults(Callback callback, String json) {
402
+ DocumentReaderResults results = (DocumentReaderResults) DocReaderResultsJsonParser.parseCoreResults(json).get("docReaderResults");
403
+ callback.success(JSONConstructor.generateDocumentReaderResults(results, getContext()).toString());
404
+ }
405
+
370
406
  private void getAPIVersion(Callback callback) {
371
407
  callback.success(Instance().version.api);
372
408
  }
@@ -421,11 +457,11 @@ public class DocumentReader extends CordovaPlugin {
421
457
  }
422
458
 
423
459
  private void selectedScenario(Callback callback) {
424
- callback.success(JSONConstructor.generateDocumentReaderScenarioFull(Instance().getScenario(Instance().processParams().getScenario())).toString());
460
+ callback.success(JSONConstructor.generateCoreDetailedScenario(CoreScenarioUtil.getScenario(Instance().processParams().getScenario())).toString());
425
461
  }
426
462
 
427
463
  private void getScenario(Callback callback, String scenario) {
428
- callback.success(JSONConstructor.generateDocumentReaderScenarioFull(Instance().getScenario(scenario)).toString());
464
+ callback.success(JSONConstructor.generateCoreDetailedScenario(CoreScenarioUtil.getScenario(scenario)).toString());
429
465
  }
430
466
 
431
467
  private void getLicenseExpiryDate(Callback callback) {
@@ -447,11 +483,11 @@ public class DocumentReader extends CordovaPlugin {
447
483
  }
448
484
 
449
485
  private void getDocumentReaderIsReady(Callback callback) {
450
- callback.success(Instance().getDocumentReaderIsReady());
486
+ callback.success(Instance().isReady());
451
487
  }
452
488
 
453
489
  private void getDocumentReaderStatus(Callback callback) {
454
- callback.success(Instance().getDocumentReaderStatus());
490
+ callback.success(Instance().isReady());
455
491
  }
456
492
 
457
493
  private void isRFIDAvailableForUse(Callback callback) {
@@ -459,15 +495,15 @@ public class DocumentReader extends CordovaPlugin {
459
495
  }
460
496
 
461
497
  private void initializeReader(Callback callback, Object license) {
462
- if (!Instance().getDocumentReaderIsReady())
463
- Instance().initializeReader(getContext(), Base64.decode(license.toString(), Base64.DEFAULT), getInitCompletion(callback));
498
+ if (!Instance().isReady())
499
+ Instance().initializeReader(getContext(), new DocReaderConfig(Base64.decode(license.toString(), Base64.DEFAULT)), getInitCompletion(callback));
464
500
  else
465
501
  callback.success("already initialized");
466
502
  }
467
503
 
468
504
  private void initializeReaderWithDatabase(Callback callback, Object license, Object db) {
469
- if (!Instance().getDocumentReaderIsReady())
470
- Instance().initializeReader(getContext(), Base64.decode(license.toString(), Base64.DEFAULT), Base64.decode(db.toString(), Base64.DEFAULT), getInitCompletion(callback));
505
+ if (!Instance().isReady())
506
+ Instance().initializeReader(getContext(), new DocReaderConfig(Base64.decode(license.toString(), Base64.DEFAULT), Base64.decode(db.toString(), Base64.DEFAULT)), getInitCompletion(callback));
471
507
  else
472
508
  callback.success("already initialized");
473
509
  }
@@ -569,11 +605,11 @@ public class DocumentReader extends CordovaPlugin {
569
605
  private void startRFIDReader(@SuppressWarnings("unused") Callback callback) {
570
606
  stopBackgroundRFID();
571
607
  IRfidReaderRequest delegate = null;
572
- if(rfidDelegate == RFIDDelegate.NO_PA)
608
+ if (rfidDelegate == RFIDDelegate.NO_PA)
573
609
  delegate = getIRfidReaderRequestNoPA();
574
- if(rfidDelegate == RFIDDelegate.FULL)
610
+ if (rfidDelegate == RFIDDelegate.FULL)
575
611
  delegate = getIRfidReaderRequest();
576
- Instance().startRFIDReader(getContext(), getCompletion(), delegate, getIRfidNotificationCompletion());
612
+ Instance().startRFIDReader(getContext(), getCompletion(), delegate, this::sendIRfidNotificationCompletion);
577
613
  }
578
614
 
579
615
  private void stopRFIDReader(Callback callback) {
@@ -681,7 +717,7 @@ public class DocumentReader extends CordovaPlugin {
681
717
  private IDocumentReaderCompletion getCompletion() {
682
718
  return (action, results, error) -> {
683
719
  sendCompletion(action, results, error);
684
- if (action == DocReaderAction.ERROR || action == DocReaderAction.CANCEL || (action == DocReaderAction.COMPLETE && results.rfidResult == 1))
720
+ if (action == DocReaderAction.ERROR || action == DocReaderAction.CANCEL || (action == DocReaderAction.COMPLETE && results != null && results.rfidResult == 1))
685
721
  stopBackgroundRFID();
686
722
  };
687
723
  }
@@ -719,20 +755,20 @@ public class DocumentReader extends CordovaPlugin {
719
755
  private IRfidReaderRequest getIRfidReaderRequest() {
720
756
  return new IRfidReaderRequest() {
721
757
  @Override
722
- public void onRequestPACertificates(byte[] serialNumber, PAResourcesIssuer issuer, IRfidPKDCertificateCompletion completion) {
758
+ public void onRequestPACertificates(byte[] serialNumber, PAResourcesIssuer issuer, @NonNull IRfidPKDCertificateCompletion completion) {
723
759
  paCertificateCompletion = completion;
724
760
  completion.onCertificatesReceived(new PKDCertificate[0]);
725
761
  sendPACertificateCompletion(serialNumber, issuer);
726
762
  }
727
763
 
728
764
  @Override
729
- public void onRequestTACertificates(String keyCAR, IRfidPKDCertificateCompletion completion) {
765
+ public void onRequestTACertificates(String keyCAR, @NonNull IRfidPKDCertificateCompletion completion) {
730
766
  taCertificateCompletion = completion;
731
767
  sendTACertificateCompletion(keyCAR);
732
768
  }
733
769
 
734
770
  @Override
735
- public void onRequestTASignature(TAChallenge challenge, IRfidTASignatureCompletion completion) {
771
+ public void onRequestTASignature(TAChallenge challenge, @NonNull IRfidTASignatureCompletion completion) {
736
772
  taSignatureCompletion = completion;
737
773
  sendTASignatureCompletion(challenge);
738
774
  }
@@ -742,19 +778,19 @@ public class DocumentReader extends CordovaPlugin {
742
778
  private IRfidReaderRequest getIRfidReaderRequestNoPA() {
743
779
  return new IRfidReaderRequest() {
744
780
  @Override
745
- public void onRequestPACertificates(byte[] serialNumber, PAResourcesIssuer issuer, IRfidPKDCertificateCompletion completion) {
781
+ public void onRequestPACertificates(byte[] serialNumber, PAResourcesIssuer issuer, @NonNull IRfidPKDCertificateCompletion completion) {
746
782
  paCertificateCompletion = null;
747
783
  completion.onCertificatesReceived(new PKDCertificate[0]);
748
784
  }
749
785
 
750
786
  @Override
751
- public void onRequestTACertificates(String keyCAR, IRfidPKDCertificateCompletion completion) {
787
+ public void onRequestTACertificates(String keyCAR, @NonNull IRfidPKDCertificateCompletion completion) {
752
788
  taCertificateCompletion = completion;
753
789
  sendTACertificateCompletion(keyCAR);
754
790
  }
755
791
 
756
792
  @Override
757
- public void onRequestTASignature(TAChallenge challenge, IRfidTASignatureCompletion completion) {
793
+ public void onRequestTASignature(TAChallenge challenge, @NonNull IRfidTASignatureCompletion completion) {
758
794
  taSignatureCompletion = completion;
759
795
  sendTASignatureCompletion(challenge);
760
796
  }
@@ -768,9 +804,4 @@ public class DocumentReader extends CordovaPlugin {
768
804
  public static final int NO_PA = 1;
769
805
  public static final int FULL = 2;
770
806
  }
771
-
772
-
773
- private IRfidNotificationCompletion getIRfidNotificationCompletion() {
774
- return (notificationType, value) -> sendIRfidNotificationCompletion(notificationType);
775
- }
776
807
  }
@@ -24,9 +24,7 @@ import java.util.List;
24
24
  class Helpers {
25
25
  static Bitmap bitmapFromBase64(String base64) {
26
26
  byte[] decodedString = Base64.decode(base64, Base64.DEFAULT);
27
- BitmapFactory.Options options = new BitmapFactory.Options();
28
- options.inPreferredConfig = Bitmap.Config.RGB_565;
29
- Bitmap result = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length, options);
27
+ Bitmap result = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
30
28
  int sizeMultiplier = result.getByteCount() / 5000000;
31
29
  if (result.getByteCount() > 5000000)
32
30
  result = Bitmap.createScaledBitmap(result, result.getWidth() / (int) Math.sqrt(sizeMultiplier), result.getHeight() / (int) Math.sqrt(sizeMultiplier), false);
@@ -136,4 +134,11 @@ class Helpers {
136
134
  result.add(jsonArray.optString(i));
137
135
  return result;
138
136
  }
137
+
138
+ static String[] stringArrayFromJson(JSONArray jsonArray) {
139
+ String[] result = new String[jsonArray.length()];
140
+ for (int i = 0; i < jsonArray.length(); i++)
141
+ result[i] = jsonArray.optString(i);
142
+ return result;
143
+ }
139
144
  }
@@ -1,9 +1,12 @@
1
1
  package cordova.plugin.documentreader;
2
2
 
3
+ import static com.regula.documentreader.api.completions.IRfidNotificationCompletion.RFID_EXTRA_ERROR_CODE;
4
+
3
5
  import android.content.Context;
4
6
  import android.graphics.Bitmap;
5
7
  import android.graphics.BitmapFactory;
6
8
  import android.graphics.Rect;
9
+ import android.os.Bundle;
7
10
  import android.util.Base64;
8
11
 
9
12
  import com.regula.documentreader.api.enums.DocReaderAction;
@@ -11,11 +14,13 @@ import com.regula.documentreader.api.enums.PDF417Info;
11
14
  import com.regula.documentreader.api.enums.eGraphicFieldType;
12
15
  import com.regula.documentreader.api.enums.eRPRM_Lights;
13
16
  import com.regula.documentreader.api.errors.DocumentReaderException;
17
+ import com.regula.documentreader.api.internal.core.CoreDetailedScenario;
14
18
  import com.regula.documentreader.api.params.FaceMetaData;
15
19
  import com.regula.documentreader.api.params.rfid.authorization.PAAttribute;
16
20
  import com.regula.documentreader.api.params.rfid.authorization.PAResourcesIssuer;
17
21
  import com.regula.documentreader.api.params.rfid.authorization.TAChallenge;
18
22
  import com.regula.documentreader.api.results.Bounds;
23
+ import com.regula.documentreader.api.results.BytesData;
19
24
  import com.regula.documentreader.api.results.Coordinate;
20
25
  import com.regula.documentreader.api.results.DocReaderFieldRect;
21
26
  import com.regula.documentreader.api.results.DocumentReaderBarcodeField;
@@ -25,14 +30,15 @@ import com.regula.documentreader.api.results.DocumentReaderGraphicField;
25
30
  import com.regula.documentreader.api.results.DocumentReaderGraphicResult;
26
31
  import com.regula.documentreader.api.results.DocumentReaderNotification;
27
32
  import com.regula.documentreader.api.results.DocumentReaderResults;
33
+ import com.regula.documentreader.api.results.DocumentReaderResultsStatus;
28
34
  import com.regula.documentreader.api.results.DocumentReaderScenario;
29
- import com.regula.documentreader.api.results.DocumentReaderScenarioFull;
30
35
  import com.regula.documentreader.api.results.DocumentReaderTextField;
31
36
  import com.regula.documentreader.api.results.DocumentReaderTextResult;
32
37
  import com.regula.documentreader.api.results.DocumentReaderValue;
33
38
  import com.regula.documentreader.api.results.ElementPosition;
34
39
  import com.regula.documentreader.api.results.ImageQuality;
35
40
  import com.regula.documentreader.api.results.ImageQualityGroup;
41
+ import com.regula.documentreader.api.results.VDSNCData;
36
42
  import com.regula.documentreader.api.results.authenticity.DocumentReaderAuthenticityCheck;
37
43
  import com.regula.documentreader.api.results.authenticity.DocumentReaderAuthenticityElement;
38
44
  import com.regula.documentreader.api.results.authenticity.DocumentReaderAuthenticityResult;
@@ -294,6 +300,18 @@ class JSONConstructor {
294
300
  return result;
295
301
  }
296
302
 
303
+ static JSONObject generateRfidNotificationCompletion(int notification, Bundle value) {
304
+ JSONObject result = new JSONObject();
305
+ try {
306
+ result.put("notification", notification);
307
+ if(value != null)
308
+ result.put("value", value.get(RFID_EXTRA_ERROR_CODE));
309
+ } catch (JSONException ignored) {
310
+ }
311
+
312
+ return result;
313
+ }
314
+
297
315
  static JSONObject generatePACertificateCompletion(byte[] serialNumber, PAResourcesIssuer issuer) {
298
316
  JSONObject result = new JSONObject();
299
317
  try {
@@ -335,8 +353,6 @@ class JSONConstructor {
335
353
  JSONObject result = new JSONObject();
336
354
  if (input == null) return result;
337
355
  try {
338
- result.put("uvTorch", input.uvTorch);
339
- result.put("seriesProcessMode", input.seriesProcessMode);
340
356
  result.put("name", input.name);
341
357
  result.put("caption", input.caption);
342
358
  result.put("description", input.description);
@@ -346,7 +362,7 @@ class JSONConstructor {
346
362
  return result;
347
363
  }
348
364
 
349
- static JSONObject generateDocumentReaderScenarioFull(DocumentReaderScenarioFull input) {
365
+ static JSONObject generateCoreDetailedScenario(CoreDetailedScenario input) {
350
366
  JSONObject result = new JSONObject();
351
367
  if (input == null) return result;
352
368
  try {
@@ -1039,6 +1055,92 @@ class JSONConstructor {
1039
1055
  return result;
1040
1056
  }
1041
1057
 
1058
+ static JSONObject generateDocumentReaderResultsStatus(DocumentReaderResultsStatus input) {
1059
+ JSONObject result = new JSONObject();
1060
+ if (input == null) return result;
1061
+ try {
1062
+ result.put("overallStatus", input.getOverallStatus());
1063
+ result.put("optical", input.getOptical());
1064
+ result.put("detailsOptical", generateDetailsOptical(input.getDetailsOptical()));
1065
+ result.put("rfid", input.getRfid());
1066
+ result.put("detailsRFID", generateDetailsRFID(input.getDetailsRFID()));
1067
+ result.put("portrait", input.getPortrait());
1068
+ result.put("stopList", input.getStopList());
1069
+ } catch (JSONException e) {
1070
+ e.printStackTrace();
1071
+ }
1072
+ return result;
1073
+ }
1074
+
1075
+ static JSONObject generateDetailsOptical(DocumentReaderResultsStatus.DetailsOptical input) {
1076
+ JSONObject result = new JSONObject();
1077
+ if (input == null) return result;
1078
+ try {
1079
+ result.put("overallStatus", input.getOverallStatus());
1080
+ result.put("mrz", input.getMrz());
1081
+ result.put("text", input.getText());
1082
+ result.put("docType", input.getDocType());
1083
+ result.put("security", input.getSecurity());
1084
+ result.put("imageQA", input.getImageQA());
1085
+ result.put("expiry", input.getExpiry());
1086
+ result.put("vds", input.getVds());
1087
+ result.put("pagesCount", input.getPagesCount());
1088
+ } catch (JSONException e) {
1089
+ e.printStackTrace();
1090
+ }
1091
+ return result;
1092
+ }
1093
+
1094
+ static JSONObject generateDetailsRFID(DocumentReaderResultsStatus.DetailsRFID input) {
1095
+ JSONObject result = new JSONObject();
1096
+ if (input == null) return result;
1097
+ try {
1098
+ result.put("pa", input.getPA());
1099
+ result.put("ca", input.getCA());
1100
+ result.put("aa", input.getAA());
1101
+ result.put("ta", input.getTA());
1102
+ result.put("bac", input.getBAC());
1103
+ result.put("pace", input.getPACE());
1104
+ result.put("overallStatus", input.getOverallStatus());
1105
+ } catch (JSONException e) {
1106
+ e.printStackTrace();
1107
+ }
1108
+ return result;
1109
+ }
1110
+
1111
+ static JSONObject generateVDSNCData(VDSNCData input) {
1112
+ JSONObject result = new JSONObject();
1113
+ if (input == null) return result;
1114
+ try {
1115
+ result.put("type", input.getType());
1116
+ result.put("version", input.getVersion());
1117
+ result.put("issuingCountry", input.getIssuingCountry());
1118
+ result.put("message", input.getMessage());
1119
+ result.put("signatureAlgorithm", input.getSignatureAlg());
1120
+ result.put("signature", generateBytesData(input.getSignature()));
1121
+ result.put("certificate", generateBytesData(input.getCertificate()));
1122
+ result.put("certificateChain", generateList(input.getCertificateChain(), JSONConstructor::generateCertificateChain));
1123
+ result.put("notifications", generateLongArray(input.getNotifications()));
1124
+ } catch (JSONException e) {
1125
+ e.printStackTrace();
1126
+ }
1127
+ return result;
1128
+ }
1129
+
1130
+ static JSONObject generateBytesData(BytesData input) {
1131
+ JSONObject result = new JSONObject();
1132
+ if (input == null) return result;
1133
+ try {
1134
+ result.put("data", input.getData());
1135
+ result.put("length", input.getLength());
1136
+ result.put("status", input.getStatus());
1137
+ result.put("type", input.getType());
1138
+ } catch (JSONException e) {
1139
+ e.printStackTrace();
1140
+ }
1141
+ return result;
1142
+ }
1143
+
1042
1144
  static JSONObject generateDocumentReaderResults(DocumentReaderResults input, Context context) {
1043
1145
  JSONObject result = new JSONObject();
1044
1146
  if (input == null) return result;
@@ -1063,6 +1165,8 @@ class JSONConstructor {
1063
1165
  result.put("authenticityResult", generateDocumentReaderAuthenticityResult(input.authenticityResult, context));
1064
1166
  result.put("barcodeResult", generateDocumentReaderBarcodeResult(input.barcodeResult));
1065
1167
  result.put("documentType", generateList(input.documentType, JSONConstructor::generateDocumentReaderDocumentType));
1168
+ result.put("status", generateDocumentReaderResultsStatus(input.status));
1169
+ result.put("vdsncData", generateVDSNCData(input.vdsncData));
1066
1170
  } catch (JSONException e) {
1067
1171
  e.printStackTrace();
1068
1172
  }
@@ -1074,10 +1178,6 @@ class JSONConstructor {
1074
1178
  static DocumentReaderScenario DocumentReaderScenarioFromJSON(JSONObject input) {
1075
1179
  try {
1076
1180
  DocumentReaderScenario result = new DocumentReaderScenario();
1077
- if (input.has("uvTorch"))
1078
- result.uvTorch = input.getBoolean("uvTorch");
1079
- if (input.has("seriesProcessMode"))
1080
- result.seriesProcessMode = input.getBoolean("seriesProcessMode");
1081
1181
  if (input.has("name"))
1082
1182
  result.name = input.getString("name");
1083
1183
  if (input.has("caption"))
@@ -1091,9 +1191,9 @@ class JSONConstructor {
1091
1191
  return null;
1092
1192
  }
1093
1193
 
1094
- static DocumentReaderScenarioFull DocumentReaderScenarioFullFromJSON(JSONObject input) {
1194
+ static CoreDetailedScenario CoreDetailedScenarioFromJSON(JSONObject input) {
1095
1195
  try {
1096
- DocumentReaderScenarioFull result = new DocumentReaderScenarioFull();
1196
+ CoreDetailedScenario result = new CoreDetailedScenario();
1097
1197
  if (input.has("uvTorch"))
1098
1198
  result.uvTorch = input.getBoolean("uvTorch");
1099
1199
  if (input.has("frameOrientation"))