@trustchex/react-native-sdk 1.163.8 → 1.163.10

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.
Files changed (42) hide show
  1. package/lib/module/Shared/EIDReader/constants/eidConstants.js +65 -0
  2. package/lib/module/Shared/EIDReader/data/country.js +21 -44
  3. package/lib/module/Shared/EIDReader/data/countryInterface.js +1 -0
  4. package/lib/module/Shared/EIDReader/data/countryRegistry.js +65 -0
  5. package/lib/module/Shared/EIDReader/data/isoCountry.js +5 -1
  6. package/lib/module/Shared/EIDReader/data/unicodeCountry.js +5 -1
  7. package/lib/module/Shared/EIDReader/defaultFileSystem.js +4 -4
  8. package/lib/module/Shared/EIDReader/eidService.js +52 -51
  9. package/lib/module/Shared/EIDReader/lds/cvcaFile.js +2 -2
  10. package/lib/module/Shared/EIDReader/tlv/tlvCore.js +161 -0
  11. package/lib/module/Shared/EIDReader/tlv/tlvInputStream.js +4 -4
  12. package/lib/module/Shared/EIDReader/tlv/tlvOutputState.js +4 -4
  13. package/lib/module/Shared/EIDReader/tlv/tlvOutputStream.js +13 -11
  14. package/lib/typescript/src/Shared/EIDReader/constants/eidConstants.d.ts +58 -0
  15. package/lib/typescript/src/Shared/EIDReader/constants/eidConstants.d.ts.map +1 -0
  16. package/lib/typescript/src/Shared/EIDReader/data/country.d.ts +4 -5
  17. package/lib/typescript/src/Shared/EIDReader/data/country.d.ts.map +1 -1
  18. package/lib/typescript/src/Shared/EIDReader/data/countryInterface.d.ts +21 -0
  19. package/lib/typescript/src/Shared/EIDReader/data/countryInterface.d.ts.map +1 -0
  20. package/lib/typescript/src/Shared/EIDReader/data/countryRegistry.d.ts +14 -0
  21. package/lib/typescript/src/Shared/EIDReader/data/countryRegistry.d.ts.map +1 -0
  22. package/lib/typescript/src/Shared/EIDReader/data/isoCountry.d.ts.map +1 -1
  23. package/lib/typescript/src/Shared/EIDReader/data/unicodeCountry.d.ts.map +1 -1
  24. package/lib/typescript/src/Shared/EIDReader/eidService.d.ts.map +1 -1
  25. package/lib/typescript/src/Shared/EIDReader/tlv/tlvCore.d.ts +22 -0
  26. package/lib/typescript/src/Shared/EIDReader/tlv/tlvCore.d.ts.map +1 -0
  27. package/lib/typescript/src/Shared/EIDReader/tlv/tlvOutputStream.d.ts +2 -2
  28. package/lib/typescript/src/Shared/EIDReader/tlv/tlvOutputStream.d.ts.map +1 -1
  29. package/package.json +1 -1
  30. package/src/Shared/EIDReader/constants/eidConstants.ts +67 -0
  31. package/src/Shared/EIDReader/data/country.ts +16 -47
  32. package/src/Shared/EIDReader/data/countryInterface.ts +21 -0
  33. package/src/Shared/EIDReader/data/countryRegistry.ts +73 -0
  34. package/src/Shared/EIDReader/data/isoCountry.ts +4 -0
  35. package/src/Shared/EIDReader/data/unicodeCountry.ts +4 -0
  36. package/src/Shared/EIDReader/defaultFileSystem.ts +4 -4
  37. package/src/Shared/EIDReader/eidService.ts +58 -53
  38. package/src/Shared/EIDReader/lds/cvcaFile.ts +2 -2
  39. package/src/Shared/EIDReader/tlv/tlvCore.ts +170 -0
  40. package/src/Shared/EIDReader/tlv/tlvInputStream.ts +4 -4
  41. package/src/Shared/EIDReader/tlv/tlvOutputState.ts +4 -4
  42. package/src/Shared/EIDReader/tlv/tlvOutputStream.ts +13 -12
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Constants used throughout the EID Reader module.
5
+ * This file helps avoid circular dependencies by centralizing shared constants.
6
+ */
7
+
8
+ export const EID_CONSTANTS = {
9
+ // Transceive lengths
10
+ EXTENDED_MAX_TRANSCEIVE_LENGTH: 65536,
11
+ NORMAL_MAX_TRANSCEIVE_LENGTH: 256,
12
+ DEFAULT_MAX_BLOCKSIZE: 223,
13
+ // File identifiers
14
+ EF_CARD_ACCESS: 0x011c,
15
+ EF_CARD_SECURITY: 0x011d,
16
+ EF_DG1: 0x0101,
17
+ EF_DG2: 0x0102,
18
+ EF_DG3: 0x0103,
19
+ EF_DG4: 0x0104,
20
+ EF_DG5: 0x0105,
21
+ EF_DG6: 0x0106,
22
+ EF_DG7: 0x0107,
23
+ EF_DG8: 0x0108,
24
+ EF_DG9: 0x0109,
25
+ EF_DG10: 0x010a,
26
+ EF_DG11: 0x010b,
27
+ EF_DG12: 0x010c,
28
+ EF_DG13: 0x010d,
29
+ EF_DG14: 0x010e,
30
+ EF_DG15: 0x010f,
31
+ EF_DG16: 0x0110,
32
+ EF_SOD: 0x011d,
33
+ EF_COM: 0x011e,
34
+ EF_CVCA: 0x011c,
35
+ // Short file identifiers
36
+ SFI_CARD_ACCESS: 0x1c,
37
+ SFI_CARD_SECURITY: 0x1d,
38
+ SFI_DG1: 0x01,
39
+ SFI_DG2: 0x02,
40
+ SFI_DG3: 0x03,
41
+ SFI_DG4: 0x04,
42
+ SFI_DG5: 0x05,
43
+ SFI_DG6: 0x06,
44
+ SFI_DG7: 0x07,
45
+ SFI_DG8: 0x08,
46
+ SFI_DG9: 0x09,
47
+ SFI_DG10: 0x0a,
48
+ SFI_DG11: 0x0b,
49
+ SFI_DG12: 0x0c,
50
+ SFI_DG13: 0x0d,
51
+ SFI_DG14: 0x0e,
52
+ SFI_DG15: 0x0f,
53
+ SFI_DG16: 0x10,
54
+ SFI_COM: 0x1e,
55
+ SFI_SOD: 0x1d,
56
+ SFI_CVCA: 0x1c,
57
+ // PACE key references
58
+ NO_PACE_KEY_REFERENCE: 0x00,
59
+ MRZ_PACE_KEY_REFERENCE: 0x01,
60
+ CAN_PACE_KEY_REFERENCE: 0x02,
61
+ PIN_PACE_KEY_REFERENCE: 0x03,
62
+ PUK_PACE_KEY_REFERENCE: 0x04,
63
+ // Applet AID
64
+ APPLET_AID: new Uint8Array([0xa0, 0x00, 0x00, 0x02, 0x47, 0x10, 0x01])
65
+ };
@@ -1,25 +1,20 @@
1
1
  "use strict";
2
2
 
3
- import { ISOCountry } from "./isoCountry.js";
4
- import { UnicodeCountry } from "./unicodeCountry.js";
5
3
  export class Country {
6
- static SUB_CLASSES = [ISOCountry, UnicodeCountry];
7
4
  static getInstance(code) {
5
+ // Note: This will be dynamically resolved at runtime
6
+ const {
7
+ CountryRegistry
8
+ } = require('./countryRegistry');
8
9
  if (typeof code === 'number') {
9
- const values = Country.values();
10
- for (const country of values) {
11
- if (country.valueOf() === code) {
12
- return country;
13
- }
14
- }
15
- throw new Error('Illegal country code ' + code.toString(16));
10
+ return CountryRegistry.fromNumericCode(code);
16
11
  } else if (typeof code === 'string') {
17
12
  code = code.trim();
18
13
  switch (code.length) {
19
14
  case 2:
20
- return Country.fromAlpha2(code);
15
+ return CountryRegistry.fromAlpha2(code);
21
16
  case 3:
22
- return Country.fromAlpha3(code);
17
+ return CountryRegistry.fromAlpha3(code);
23
18
  default:
24
19
  throw new Error('Illegal country code ' + code);
25
20
  }
@@ -28,39 +23,21 @@ export class Country {
28
23
  }
29
24
  }
30
25
  static values() {
31
- const result = [];
32
- for (const subClass of Country.SUB_CLASSES) {
33
- if (Country.isAssignable(subClass)) {
34
- try {
35
- const method = subClass.values;
36
- const subClassValues = method.call(null);
37
- result.push(...subClassValues);
38
- } catch (e) {
39
- console.debug(`Exception: ${e}`);
40
- }
41
- }
42
- }
43
- return result;
44
- }
45
- static fromAlpha2(code) {
46
- const values = Country.values();
47
- for (const country of values) {
48
- if (country.toAlpha2Code() === code) {
49
- return country;
50
- }
51
- }
52
- throw new Error('Unknown country code ' + code);
26
+ const {
27
+ CountryRegistry
28
+ } = require('./countryRegistry');
29
+ return CountryRegistry.values();
53
30
  }
54
- static fromAlpha3(code) {
55
- const values = Country.values();
56
- for (const country of values) {
57
- if (country.toAlpha3Code() === code) {
58
- return country;
59
- }
60
- }
61
- throw new Error('Unknown country code ' + code);
31
+ static fromAlpha2(alpha2Code) {
32
+ const {
33
+ CountryRegistry
34
+ } = require('./countryRegistry');
35
+ return CountryRegistry.fromAlpha2(alpha2Code);
62
36
  }
63
- static isAssignable(subClass) {
64
- return subClass.prototype instanceof Country;
37
+ static fromAlpha3(alpha3Code) {
38
+ const {
39
+ CountryRegistry
40
+ } = require('./countryRegistry');
41
+ return CountryRegistry.fromAlpha3(alpha3Code);
65
42
  }
66
43
  }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Registry for country implementations to avoid circular dependencies.
5
+ */
6
+ export class CountryRegistry {
7
+ static countryTypes = [];
8
+ static register(countryType) {
9
+ if (!CountryRegistry.countryTypes.includes(countryType)) {
10
+ CountryRegistry.countryTypes.push(countryType);
11
+ }
12
+ }
13
+ static getRegisteredTypes() {
14
+ return [...CountryRegistry.countryTypes];
15
+ }
16
+ static values() {
17
+ const result = [];
18
+ for (const countryType of CountryRegistry.countryTypes) {
19
+ try {
20
+ const values = countryType.values?.();
21
+ if (Array.isArray(values)) {
22
+ result.push(...values);
23
+ }
24
+ } catch (e) {
25
+ console.debug(`Exception getting values from ${countryType.name}: ${e}`);
26
+ }
27
+ }
28
+ return result;
29
+ }
30
+ static fromAlpha2(alpha2Code) {
31
+ for (const countryType of CountryRegistry.countryTypes) {
32
+ try {
33
+ const country = countryType.fromAlpha2?.(alpha2Code);
34
+ if (country) {
35
+ return country;
36
+ }
37
+ } catch (e) {
38
+ // Continue to next type
39
+ }
40
+ }
41
+ throw new Error(`Unknown country code: ${alpha2Code}`);
42
+ }
43
+ static fromAlpha3(alpha3Code) {
44
+ for (const countryType of CountryRegistry.countryTypes) {
45
+ try {
46
+ const country = countryType.fromAlpha3?.(alpha3Code);
47
+ if (country) {
48
+ return country;
49
+ }
50
+ } catch (e) {
51
+ // Continue to next type
52
+ }
53
+ }
54
+ throw new Error(`Unknown country code: ${alpha3Code}`);
55
+ }
56
+ static fromNumericCode(numericCode) {
57
+ const values = CountryRegistry.values();
58
+ for (const country of values) {
59
+ if (country.valueOf() === numericCode) {
60
+ return country;
61
+ }
62
+ }
63
+ throw new Error(`Unknown country code: ${numericCode.toString(16)}`);
64
+ }
65
+ }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  import { Country } from "./country.js";
4
+ import { CountryRegistry } from "./countryRegistry.js";
4
5
  export class ISOCountry extends Country {
5
6
  static AD = new ISOCountry(32, 'AD', 'AND', 'Andorra', 'Andorran');
6
7
  static AE = new ISOCountry(1924, 'AE', 'ARE', 'United Arab Emirates', 'Emirati, Emirian');
@@ -280,4 +281,7 @@ export class ISOCountry extends Country {
280
281
  toAlpha3Code() {
281
282
  return this.alpha3Code;
282
283
  }
283
- }
284
+ }
285
+
286
+ // Register this country type with the registry
287
+ CountryRegistry.register(ISOCountry);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  import { Country } from "./country.js";
4
+ import { CountryRegistry } from "./countryRegistry.js";
4
5
  export class UnicodeCountry extends Country {
5
6
  static AD = new UnicodeCountry(32, 'AD', 'AND', 'Andorra', 'Andorran');
6
7
  static AE = new UnicodeCountry(1924, 'AE', 'ARE', 'United Arab Emirates', 'Emirati, Emirian');
@@ -275,4 +276,7 @@ export class UnicodeCountry extends Country {
275
276
  toAlpha3Code() {
276
277
  return this.alpha3Code;
277
278
  }
278
- }
279
+ }
280
+
281
+ // Register this country type with the registry
282
+ CountryRegistry.register(UnicodeCountry);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import { EIDService } from "./eidService.js";
3
+ import { EID_CONSTANTS } from "./constants/eidConstants.js";
4
4
  import { ByteArrayInputStream } from "./java/byteArrayInputStream.js";
5
5
  import { DefaultFileInfo } from "./defaultFileInfo.js";
6
6
  import { ISO7816_SW } from "./smartcards/iso7816.js";
@@ -19,7 +19,7 @@ export class DefaultFileSystem {
19
19
  this.isSelected = false;
20
20
  this.isSFIEnabled = isSFIEnabled;
21
21
  this.fidToSFI = fidToSFI;
22
- this.maxReadBinaryLength = EIDService.EXTENDED_MAX_TRANSCEIVE_LENGTH;
22
+ this.maxReadBinaryLength = EID_CONSTANTS.EXTENDED_MAX_TRANSCEIVE_LENGTH;
23
23
  }
24
24
  setWrapper(wrapper) {
25
25
  this.oldWrapper = this.wrapper;
@@ -90,9 +90,9 @@ export class DefaultFileSystem {
90
90
  return result;
91
91
  } catch (error) {
92
92
  const sw = error.getSW();
93
- if ((sw & ISO7816_SW.WRONG_LENGTH) === ISO7816_SW.WRONG_LENGTH && this.maxReadBinaryLength > EIDService.DEFAULT_MAX_BLOCKSIZE) {
93
+ if ((sw & ISO7816_SW.WRONG_LENGTH) === ISO7816_SW.WRONG_LENGTH && this.maxReadBinaryLength > EID_CONSTANTS.DEFAULT_MAX_BLOCKSIZE) {
94
94
  this.wrapper = this.oldWrapper;
95
- this.maxReadBinaryLength = EIDService.DEFAULT_MAX_BLOCKSIZE;
95
+ this.maxReadBinaryLength = EID_CONSTANTS.DEFAULT_MAX_BLOCKSIZE;
96
96
  return new Uint8Array(0);
97
97
  }
98
98
  throw new Error(`Read binary failed on file ${fileInfo == null ? this.selectedFID.toString(16) : fileInfo}`);
@@ -6,163 +6,164 @@ import { DefaultFileSystem } from "./defaultFileSystem.js";
6
6
  import { BACAPDUSender } from "./protocol/bacAPDUSender.js";
7
7
  import { ReadBinaryAPDUSender } from "./protocol/readBinaryAPDUSender.js";
8
8
  import { BACProtocol } from "./protocol/bacProtocol.js";
9
+ import { EID_CONSTANTS } from "./constants/eidConstants.js";
9
10
  export class EIDService extends AbstractMRTDCardService {
10
11
  /** Shared secret type for non-PACE key. */
11
- static NO_PACE_KEY_REFERENCE = 0x00;
12
+ static NO_PACE_KEY_REFERENCE = EID_CONSTANTS.NO_PACE_KEY_REFERENCE;
12
13
 
13
14
  /** Shared secret type for PACE according to BSI TR-03110 v2.03 B.11.1. */
14
- static MRZ_PACE_KEY_REFERENCE = 0x01;
15
+ static MRZ_PACE_KEY_REFERENCE = EID_CONSTANTS.MRZ_PACE_KEY_REFERENCE;
15
16
 
16
17
  /** Shared secret type for PACE according to BSI TR-03110 v2.03 B.11.1. */
17
- static CAN_PACE_KEY_REFERENCE = 0x02;
18
+ static CAN_PACE_KEY_REFERENCE = EID_CONSTANTS.CAN_PACE_KEY_REFERENCE;
18
19
 
19
20
  /** Shared secret type for PACE according to BSI TR-03110 v2.03 B.11.1. */
20
- static PIN_PACE_KEY_REFERENCE = 0x03;
21
+ static PIN_PACE_KEY_REFERENCE = EID_CONSTANTS.PIN_PACE_KEY_REFERENCE;
21
22
 
22
23
  /** Shared secret type for PACE according to BSI TR-03110 v2.03 B.11.1. */
23
- static PUK_PACE_KEY_REFERENCE = 0x04;
24
+ static PUK_PACE_KEY_REFERENCE = EID_CONSTANTS.PUK_PACE_KEY_REFERENCE;
24
25
 
25
26
  /** Card Access. */
26
- static EF_CARD_ACCESS = 0x011c;
27
+ static EF_CARD_ACCESS = EID_CONSTANTS.EF_CARD_ACCESS;
27
28
 
28
29
  /** Card Security. */
29
- static EF_CARD_SECURITY = 0x011d;
30
+ static EF_CARD_SECURITY = EID_CONSTANTS.EF_CARD_SECURITY;
30
31
 
31
32
  /** File identifier for data group 1. Data group 1 contains the MRZ. */
32
- static EF_DG1 = 0x0101;
33
+ static EF_DG1 = EID_CONSTANTS.EF_DG1;
33
34
 
34
35
  /** File identifier for data group 2. Data group 2 contains face image data. */
35
- static EF_DG2 = 0x0102;
36
+ static EF_DG2 = EID_CONSTANTS.EF_DG2;
36
37
 
37
38
  /** File identifier for data group 3. Data group 3 contains finger print data. */
38
- static EF_DG3 = 0x0103;
39
+ static EF_DG3 = EID_CONSTANTS.EF_DG3;
39
40
 
40
41
  /** File identifier for data group 4. Data group 4 contains iris data. */
41
- static EF_DG4 = 0x0104;
42
+ static EF_DG4 = EID_CONSTANTS.EF_DG4;
42
43
 
43
44
  /** File identifier for data group 5. Data group 5 contains displayed portrait. */
44
- static EF_DG5 = 0x0105;
45
+ static EF_DG5 = EID_CONSTANTS.EF_DG5;
45
46
 
46
47
  /** File identifier for data group 6. Data group 6 is RFU. */
47
- static EF_DG6 = 0x0106;
48
+ static EF_DG6 = EID_CONSTANTS.EF_DG6;
48
49
 
49
50
  /** File identifier for data group 7. Data group 7 contains displayed signature. */
50
- static EF_DG7 = 0x0107;
51
+ static EF_DG7 = EID_CONSTANTS.EF_DG7;
51
52
 
52
53
  /** File identifier for data group 8. Data group 8 contains data features. */
53
- static EF_DG8 = 0x0108;
54
+ static EF_DG8 = EID_CONSTANTS.EF_DG8;
54
55
 
55
56
  /** File identifier for data group 9. Data group 9 contains structure features. */
56
- static EF_DG9 = 0x0109;
57
+ static EF_DG9 = EID_CONSTANTS.EF_DG9;
57
58
 
58
59
  /** File identifier for data group 10. Data group 10 contains substance features. */
59
- static EF_DG10 = 0x010a;
60
+ static EF_DG10 = EID_CONSTANTS.EF_DG10;
60
61
 
61
62
  /** File identifier for data group 11. Data group 11 contains additional personal details. */
62
- static EF_DG11 = 0x010b;
63
+ static EF_DG11 = EID_CONSTANTS.EF_DG11;
63
64
 
64
65
  /** File identifier for data group 12. Data group 12 contains additional document details. */
65
- static EF_DG12 = 0x010c;
66
+ static EF_DG12 = EID_CONSTANTS.EF_DG12;
66
67
 
67
68
  /** File identifier for data group 13. Data group 13 contains optional details. */
68
- static EF_DG13 = 0x010d;
69
+ static EF_DG13 = EID_CONSTANTS.EF_DG13;
69
70
 
70
71
  /** File identifier for data group 14. Data group 14 contains security infos. */
71
- static EF_DG14 = 0x010e;
72
+ static EF_DG14 = EID_CONSTANTS.EF_DG14;
72
73
 
73
74
  /** File identifier for data group 15. Data group 15 contains the public key used for Active Authentication. */
74
- static EF_DG15 = 0x010f;
75
+ static EF_DG15 = EID_CONSTANTS.EF_DG15;
75
76
 
76
77
  /** File identifier for data group 16. Data group 16 contains person(s) to notify. */
77
- static EF_DG16 = 0x0110;
78
+ static EF_DG16 = EID_CONSTANTS.EF_DG16;
78
79
 
79
80
  /** The security document. */
80
- static EF_SOD = 0x011d;
81
+ static EF_SOD = EID_CONSTANTS.EF_SOD;
81
82
 
82
83
  /** The data group presence list. */
83
- static EF_COM = 0x011e;
84
+ static EF_COM = EID_CONSTANTS.EF_COM;
84
85
 
85
86
  /**
86
87
  * Contains EAC CVA references. Note: this can be overridden by a file
87
88
  * identifier in the DG14 file (in a TerminalAuthenticationInfo). Check DG14
88
89
  * first. Also, this file does not have a header tag, like the others.
89
90
  */
90
- static EF_CVCA = 0x011c;
91
+ static EF_CVCA = EID_CONSTANTS.EF_CVCA;
91
92
 
92
93
  /** Short file identifier for card access file. */
93
- static SFI_CARD_ACCESS = 0x1c;
94
+ static SFI_CARD_ACCESS = EID_CONSTANTS.SFI_CARD_ACCESS;
94
95
 
95
96
  /** Short file identifier for card security file. */
96
- static SFI_CARD_SECURITY = 0x1d;
97
+ static SFI_CARD_SECURITY = EID_CONSTANTS.SFI_CARD_SECURITY;
97
98
 
98
99
  /** Short file identifier for file. */
99
- static SFI_DG1 = 0x01;
100
+ static SFI_DG1 = EID_CONSTANTS.SFI_DG1;
100
101
 
101
102
  /** Short file identifier for file. */
102
- static SFI_DG2 = 0x02;
103
+ static SFI_DG2 = EID_CONSTANTS.SFI_DG2;
103
104
 
104
105
  /** Short file identifier for file. */
105
- static SFI_DG3 = 0x03;
106
+ static SFI_DG3 = EID_CONSTANTS.SFI_DG3;
106
107
 
107
108
  /** Short file identifier for file. */
108
- static SFI_DG4 = 0x04;
109
+ static SFI_DG4 = EID_CONSTANTS.SFI_DG4;
109
110
 
110
111
  /** Short file identifier for file. */
111
- static SFI_DG5 = 0x05;
112
+ static SFI_DG5 = EID_CONSTANTS.SFI_DG5;
112
113
 
113
114
  /** Short file identifier for file. */
114
- static SFI_DG6 = 0x06;
115
+ static SFI_DG6 = EID_CONSTANTS.SFI_DG6;
115
116
 
116
117
  /** Short file identifier for file. */
117
- static SFI_DG7 = 0x07;
118
+ static SFI_DG7 = EID_CONSTANTS.SFI_DG7;
118
119
 
119
120
  /** Short file identifier for file. */
120
- static SFI_DG8 = 0x08;
121
+ static SFI_DG8 = EID_CONSTANTS.SFI_DG8;
121
122
 
122
123
  /** Short file identifier for file. */
123
- static SFI_DG9 = 0x09;
124
+ static SFI_DG9 = EID_CONSTANTS.SFI_DG9;
124
125
 
125
126
  /** Short file identifier for file. */
126
- static SFI_DG10 = 0x0a;
127
+ static SFI_DG10 = EID_CONSTANTS.SFI_DG10;
127
128
 
128
129
  /** Short file identifier for file. */
129
- static SFI_DG11 = 0x0b;
130
+ static SFI_DG11 = EID_CONSTANTS.SFI_DG11;
130
131
 
131
132
  /** Short file identifier for file. */
132
- static SFI_DG12 = 0x0c;
133
+ static SFI_DG12 = EID_CONSTANTS.SFI_DG12;
133
134
 
134
135
  /** Short file identifier for file. */
135
- static SFI_DG13 = 0x0d;
136
+ static SFI_DG13 = EID_CONSTANTS.SFI_DG13;
136
137
 
137
138
  /** Short file identifier for file. */
138
- static SFI_DG14 = 0x0e;
139
+ static SFI_DG14 = EID_CONSTANTS.SFI_DG14;
139
140
 
140
141
  /** Short file identifier for file. */
141
- static SFI_DG15 = 0x0f;
142
+ static SFI_DG15 = EID_CONSTANTS.SFI_DG15;
142
143
 
143
144
  /** Short file identifier for file. */
144
- static SFI_DG16 = 0x10;
145
+ static SFI_DG16 = EID_CONSTANTS.SFI_DG16;
145
146
 
146
147
  /** Short file identifier for file. */
147
- static SFI_COM = 0x1e;
148
+ static SFI_COM = EID_CONSTANTS.SFI_COM;
148
149
 
149
150
  /** Short file identifier for file. */
150
- static SFI_SOD = 0x1d;
151
+ static SFI_SOD = EID_CONSTANTS.SFI_SOD;
151
152
 
152
153
  /** Short file identifier for file. */
153
- static SFI_CVCA = 0x1c;
154
+ static SFI_CVCA = EID_CONSTANTS.SFI_CVCA;
154
155
 
155
156
  /** The default maximal blocksize used for unencrypted APDUs. */
156
- static DEFAULT_MAX_BLOCKSIZE = 223;
157
+ static DEFAULT_MAX_BLOCKSIZE = EID_CONSTANTS.DEFAULT_MAX_BLOCKSIZE;
157
158
 
158
159
  /** The normal maximal transceive length of APDUs. */
159
- static NORMAL_MAX_TRANSCEIVE_LENGTH = 256;
160
+ static NORMAL_MAX_TRANSCEIVE_LENGTH = EID_CONSTANTS.NORMAL_MAX_TRANSCEIVE_LENGTH;
160
161
 
161
162
  /** The extended maximal transceive length of APDUs. */
162
- static EXTENDED_MAX_TRANSCEIVE_LENGTH = 65536;
163
+ static EXTENDED_MAX_TRANSCEIVE_LENGTH = EID_CONSTANTS.EXTENDED_MAX_TRANSCEIVE_LENGTH;
163
164
 
164
165
  /** The applet we select when we start a session. */
165
- static APPLET_AID = Uint8Array.from([0xa0, 0x00, 0x00, 0x02, 0x47, 0x10, 0x01]);
166
+ static APPLET_AID = EID_CONSTANTS.APPLET_AID;
166
167
  wrapper = null;
167
168
  constructor(service, maxTransceiveLengthForSecureMessaging = EIDService.NORMAL_MAX_TRANSCEIVE_LENGTH, maxBlockSize = EIDService.DEFAULT_MAX_BLOCKSIZE, isSFIEnabled = false, shouldCheckMAC = false) {
168
169
  super();
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import { EIDService } from "../eidService.js";
3
+ import { EID_CONSTANTS } from "../constants/eidConstants.js";
4
4
  import { CVCPrincipal } from "../cert/cvcPrincipal.js";
5
5
  import { DataInputStream } from "../java/dataInputStream.js";
6
6
  export class CVCAFile {
@@ -20,7 +20,7 @@ export class CVCAFile {
20
20
  this.caReference = caReference;
21
21
  this.altCAReference = altCAReference || null;
22
22
  } else {
23
- this.fid = EIDService.EF_CVCA;
23
+ this.fid = EID_CONSTANTS.EF_CVCA;
24
24
  this.readObject(fidOrInputStream);
25
25
  }
26
26
  }
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+
3
+ import { ASN1Constants } from "./asn1Constants.js";
4
+
5
+ /**
6
+ * Core TLV utility functions that don't depend on TLVInputStream/TLVOutputStream
7
+ * to avoid circular dependencies.
8
+ */
9
+ export class TLVCore extends ASN1Constants {
10
+ // Tag class constants
11
+ static UNIVERSAL_CLASS = 0;
12
+ static APPLICATION_CLASS = 1;
13
+ static CONTEXT_SPECIFIC_CLASS = 2;
14
+ static PRIVATE_CLASS = 3;
15
+ static isPrimitive(tag) {
16
+ let i = 3;
17
+ for (; i >= 0; i--) {
18
+ const mask = 0xff << 8 * i;
19
+ if ((tag & mask) !== 0x00) {
20
+ break;
21
+ }
22
+ }
23
+ const msByte = (tag & 0xff << 8 * i) >> 8 * i & 0xff;
24
+ return (msByte & 0x20) === 0x00;
25
+ }
26
+ static getTagLength(tag) {
27
+ if (tag < 0x1f) {
28
+ return 1;
29
+ }
30
+ if (tag < 0x80) {
31
+ return 2;
32
+ }
33
+ if (tag < 0x8000) {
34
+ return 3;
35
+ }
36
+ if (tag < 0x800000) {
37
+ return 4;
38
+ }
39
+ return 5;
40
+ }
41
+ static isValidTag(tag) {
42
+ return tag >= 0x00 && tag <= 0xffffffff;
43
+ }
44
+ static getLengthLength(length) {
45
+ if (length < 0x80) {
46
+ return 1;
47
+ }
48
+ if (length < 0x100) {
49
+ return 2;
50
+ }
51
+ if (length < 0x10000) {
52
+ return 3;
53
+ }
54
+ if (length < 0x1000000) {
55
+ return 4;
56
+ }
57
+ return 5;
58
+ }
59
+ static getTagAsBytes(tag) {
60
+ const out = [];
61
+ const byteCount = Math.floor(Math.log(tag) / Math.log(256)) + 1;
62
+ for (let i = 0; i < byteCount; i++) {
63
+ const pos = 8 * (byteCount - i - 1);
64
+ out.push((tag & 0xff << pos) >> pos);
65
+ }
66
+ const tagBytes = out;
67
+ switch (TLVCore.getTagClass(tag)) {
68
+ case TLVCore.APPLICATION_CLASS:
69
+ tagBytes[0] |= 0x40;
70
+ break;
71
+ case TLVCore.CONTEXT_SPECIFIC_CLASS:
72
+ tagBytes[0] |= 0x80;
73
+ break;
74
+ case TLVCore.PRIVATE_CLASS:
75
+ tagBytes[0] |= 0xc0;
76
+ break;
77
+ default:
78
+ /* NOTE: Unsupported tag class. Now what? */
79
+ break;
80
+ }
81
+ if (!TLVCore.isPrimitive(tag)) {
82
+ tagBytes[0] |= 0x20;
83
+ }
84
+ return tagBytes;
85
+ }
86
+ static getLengthAsBytes(length) {
87
+ const out = [];
88
+ if (length < 0x80) {
89
+ /* short form */
90
+ out.push(length);
91
+ } else {
92
+ const byteCount = TLVCore.log(length, 256);
93
+ out.push(0x80 | byteCount);
94
+ for (let i = 0; i < byteCount; i++) {
95
+ const pos = 8 * (byteCount - i - 1);
96
+ out.push((length & 0xff << pos) >> pos);
97
+ }
98
+ }
99
+ return out;
100
+ }
101
+ static getTagClass(tag) {
102
+ let i = 3;
103
+ for (; i >= 0; i--) {
104
+ const mask = 0xff << 8 * i;
105
+ if ((tag & mask) !== 0x00) {
106
+ break;
107
+ }
108
+ }
109
+ const msByte = (tag & 0xff << 8 * i) >> 8 * i & 0xff;
110
+ switch (msByte & 0xc0) {
111
+ case 0x00:
112
+ return TLVCore.UNIVERSAL_CLASS;
113
+ case 0x40:
114
+ return TLVCore.APPLICATION_CLASS;
115
+ case 0x80:
116
+ return TLVCore.CONTEXT_SPECIFIC_CLASS;
117
+ case 0xc0:
118
+ default:
119
+ return TLVCore.PRIVATE_CLASS;
120
+ }
121
+ }
122
+ static log(n, base) {
123
+ let result = 0;
124
+ while (n > 0) {
125
+ n = n / base;
126
+ result++;
127
+ }
128
+ return result;
129
+ }
130
+ static writeTagLength(tag, length) {
131
+ const tagLength = TLVCore.getTagLength(tag);
132
+ const lengthLength = TLVCore.getLengthLength(length);
133
+ const result = new Uint8Array(tagLength + lengthLength);
134
+ let offset = 0;
135
+
136
+ // Write tag
137
+ if (tagLength === 1) {
138
+ result[offset++] = tag & 0xff;
139
+ } else if (tagLength === 2) {
140
+ result[offset++] = 0x1f;
141
+ result[offset++] = tag & 0xff;
142
+ } else {
143
+ result[offset++] = 0x1f;
144
+ for (let i = tagLength - 2; i >= 0; i--) {
145
+ result[offset++] = tag >> i * 8 & 0xff;
146
+ }
147
+ }
148
+
149
+ // Write length
150
+ if (lengthLength === 1) {
151
+ result[offset++] = length & 0xff;
152
+ } else {
153
+ result[offset++] = 0x80 | lengthLength - 1;
154
+ for (let i = lengthLength - 2; i >= 0; i--) {
155
+ result[offset++] = length >> i * 8 & 0xff;
156
+ }
157
+ }
158
+ return result;
159
+ }
160
+ }
161
+ export default TLVCore;