|
1 | 1 | import 'package:cbor/cbor.dart'; |
2 | 2 |
|
3 | | -import '../constants.dart'; |
4 | | - |
5 | 3 | class AuthenticatorInfo { |
| 4 | + static const int versionsIdx = 1; |
| 5 | + static const int extensionsIdx = 2; |
| 6 | + static const int aaguidIdx = 3; |
| 7 | + static const int optionsIdx = 4; |
| 8 | + static const int maxMsgSizeIdx = 5; |
| 9 | + static const int pinUvAuthProtocolsIdx = 6; |
| 10 | + static const int maxCredentialCountInListIdx = 7; |
| 11 | + static const int maxCredentialIdLengthIdx = 8; |
| 12 | + static const int transportsIdx = 9; |
| 13 | + static const int algorithmsIdx = 10; |
| 14 | + static const int maxSerializedLargeBlobArrayIdx = 11; |
| 15 | + static const int forcePinChangeIdx = 12; |
| 16 | + static const int minPinLengthIdx = 13; |
| 17 | + static const int firmwareVersionIdx = 14; |
| 18 | + static const int maxCredBlobLengthIdx = 15; |
| 19 | + static const int maxRpIdsForSetMinPinLengthIdx = 16; |
| 20 | + static const int preferredPlatformUvAttemptsIdx = 17; |
| 21 | + static const int uvModalityIdx = 18; |
| 22 | + static const int certificationsIdx = 19; |
| 23 | + static const int remainingDiscoverableCredentialsIdx = 20; |
| 24 | + static const int vendorPrototypeConfigCommandsIdx = 21; |
| 25 | + |
6 | 26 | final List<String> versions; |
7 | 27 | final List<String>? extensions; |
8 | 28 | final List<int> aaguid; |
@@ -51,103 +71,95 @@ class AuthenticatorInfo { |
51 | 71 |
|
52 | 72 | List<int> encode() { |
53 | 73 | final map = <int, dynamic>{}; |
54 | | - map[authInfoVersionsIdx] = versions; |
| 74 | + map[versionsIdx] = versions; |
55 | 75 | if (extensions != null) { |
56 | | - map[authInfoExtensionsIdx] = extensions; |
| 76 | + map[extensionsIdx] = extensions; |
57 | 77 | } |
58 | | - map[authInfoAaguidIdx] = aaguid; |
| 78 | + map[aaguidIdx] = aaguid; |
59 | 79 | if (options != null) { |
60 | | - map[authInfoOptionsIdx] = options; |
| 80 | + map[optionsIdx] = options; |
61 | 81 | } |
62 | 82 | if (maxMsgSize != null) { |
63 | | - map[authInfoMaxMsgSizeIdx] = maxMsgSize; |
| 83 | + map[maxMsgSizeIdx] = maxMsgSize; |
64 | 84 | } |
65 | 85 | if (pinUvAuthProtocols != null) { |
66 | | - map[authInfoPinUvAuthProtocolsIdx] = pinUvAuthProtocols; |
| 86 | + map[pinUvAuthProtocolsIdx] = pinUvAuthProtocols; |
67 | 87 | } |
68 | 88 | if (maxCredentialCountInList != null) { |
69 | | - map[authInfoMaxCredentialCountInListIdx] = maxCredentialCountInList; |
| 89 | + map[maxCredentialCountInListIdx] = maxCredentialCountInList; |
70 | 90 | } |
71 | 91 | if (maxCredentialIdLength != null) { |
72 | | - map[authInfoMaxCredentialIdLengthIdx] = maxCredentialIdLength; |
| 92 | + map[maxCredentialIdLengthIdx] = maxCredentialIdLength; |
73 | 93 | } |
74 | 94 | if (transports != null) { |
75 | | - map[authInfoTransportsIdx] = transports; |
| 95 | + map[transportsIdx] = transports; |
76 | 96 | } |
77 | 97 | if (algorithms != null) { |
78 | | - map[authInfoAlgorithmsIdx] = algorithms; |
| 98 | + map[algorithmsIdx] = algorithms; |
79 | 99 | } |
80 | 100 | if (maxSerializedLargeBlobArray != null) { |
81 | | - map[authInfoMaxSerializedLargeBlobArrayIdx] = maxSerializedLargeBlobArray; |
| 101 | + map[maxSerializedLargeBlobArrayIdx] = maxSerializedLargeBlobArray; |
82 | 102 | } |
83 | 103 | if (forcePinChange != null) { |
84 | | - map[authInfoForcePinChangeIdx] = forcePinChange; |
| 104 | + map[forcePinChangeIdx] = forcePinChange; |
85 | 105 | } |
86 | 106 | if (minPinLength != null) { |
87 | | - map[authInfoMinPinLengthIdx] = minPinLength; |
| 107 | + map[minPinLengthIdx] = minPinLength; |
88 | 108 | } |
89 | 109 | if (firmwareVersion != null) { |
90 | | - map[authInfoFirmwareVersionIdx] = firmwareVersion; |
| 110 | + map[firmwareVersionIdx] = firmwareVersion; |
91 | 111 | } |
92 | 112 | if (maxCredBlobLength != null) { |
93 | | - map[authInfoMaxCredBlobLengthIdx] = maxCredBlobLength; |
| 113 | + map[maxCredBlobLengthIdx] = maxCredBlobLength; |
94 | 114 | } |
95 | 115 | if (maxRpIdsForSetMinPinLength != null) { |
96 | | - map[authInfoMaxRpIdsForSetMinPinLengthIdx] = maxRpIdsForSetMinPinLength; |
| 116 | + map[maxRpIdsForSetMinPinLengthIdx] = maxRpIdsForSetMinPinLength; |
97 | 117 | } |
98 | 118 | if (preferredPlatformUvAttempts != null) { |
99 | | - map[authInfoPreferredPlatformUvAttemptsIdx] = preferredPlatformUvAttempts; |
| 119 | + map[preferredPlatformUvAttemptsIdx] = preferredPlatformUvAttempts; |
100 | 120 | } |
101 | 121 | if (uvModality != null) { |
102 | | - map[authInfoUvModalityIdx] = uvModality; |
| 122 | + map[uvModalityIdx] = uvModality; |
103 | 123 | } |
104 | 124 | if (certifications != null) { |
105 | | - map[authInfoCertificationsIdx] = certifications; |
| 125 | + map[certificationsIdx] = certifications; |
106 | 126 | } |
107 | 127 | if (remainingDiscoverableCredentials != null) { |
108 | | - map[authInfoRemainingDiscoverableCredentialsIdx] = |
| 128 | + map[remainingDiscoverableCredentialsIdx] = |
109 | 129 | remainingDiscoverableCredentials; |
110 | 130 | } |
111 | 131 | if (vendorPrototypeConfigCommands != null) { |
112 | | - map[authInfoVendorPrototypeConfigCommandsIdx] = |
113 | | - vendorPrototypeConfigCommands; |
| 132 | + map[vendorPrototypeConfigCommandsIdx] = vendorPrototypeConfigCommands; |
114 | 133 | } |
115 | 134 | return cbor.encode(CborValue(map)); |
116 | 135 | } |
117 | 136 |
|
118 | 137 | static AuthenticatorInfo decode(List<int> data) { |
119 | 138 | final map = cbor.decode(data).toObject() as Map; |
120 | 139 | return AuthenticatorInfo( |
121 | | - versions: (map[authInfoVersionsIdx] as List).cast<String>(), |
122 | | - extensions: (map[authInfoExtensionsIdx] as List?)?.cast<String>(), |
123 | | - aaguid: map[authInfoAaguidIdx] as List<int>, |
124 | | - options: (map[authInfoOptionsIdx] as Map?)?.cast<String, bool>(), |
125 | | - maxMsgSize: map[authInfoMaxMsgSizeIdx] as int?, |
126 | | - pinUvAuthProtocols: |
127 | | - (map[authInfoPinUvAuthProtocolsIdx] as List?)?.cast<int>(), |
128 | | - maxCredentialCountInList: |
129 | | - map[authInfoMaxCredentialCountInListIdx] as int?, |
130 | | - maxCredentialIdLength: map[authInfoMaxCredentialIdLengthIdx] as int?, |
131 | | - transports: (map[authInfoTransportsIdx] as List?)?.cast<String>(), |
132 | | - algorithms: |
133 | | - (map[authInfoAlgorithmsIdx] as List?)?.cast<Map<String, int>>(), |
134 | | - maxSerializedLargeBlobArray: |
135 | | - map[authInfoMaxSerializedLargeBlobArrayIdx] as int?, |
136 | | - forcePinChange: map[authInfoForcePinChangeIdx] as bool?, |
137 | | - minPinLength: map[authInfoMinPinLengthIdx] as int?, |
138 | | - firmwareVersion: map[authInfoFirmwareVersionIdx] as int?, |
139 | | - maxCredBlobLength: map[authInfoMaxCredBlobLengthIdx] as int?, |
140 | | - maxRpIdsForSetMinPinLength: |
141 | | - map[authInfoMaxRpIdsForSetMinPinLengthIdx] as int?, |
142 | | - preferredPlatformUvAttempts: |
143 | | - map[authInfoPreferredPlatformUvAttemptsIdx] as int?, |
144 | | - uvModality: map[authInfoUvModalityIdx] as int?, |
145 | | - certifications: |
146 | | - (map[authInfoCertificationsIdx] as Map?)?.cast<String, int>(), |
| 140 | + versions: (map[versionsIdx] as List).cast<String>(), |
| 141 | + extensions: (map[extensionsIdx] as List?)?.cast<String>(), |
| 142 | + aaguid: map[aaguidIdx] as List<int>, |
| 143 | + options: (map[optionsIdx] as Map?)?.cast<String, bool>(), |
| 144 | + maxMsgSize: map[maxMsgSizeIdx] as int?, |
| 145 | + pinUvAuthProtocols: (map[pinUvAuthProtocolsIdx] as List?)?.cast<int>(), |
| 146 | + maxCredentialCountInList: map[maxCredentialCountInListIdx] as int?, |
| 147 | + maxCredentialIdLength: map[maxCredentialIdLengthIdx] as int?, |
| 148 | + transports: (map[transportsIdx] as List?)?.cast<String>(), |
| 149 | + algorithms: (map[algorithmsIdx] as List?)?.cast<Map<String, int>>(), |
| 150 | + maxSerializedLargeBlobArray: map[maxSerializedLargeBlobArrayIdx] as int?, |
| 151 | + forcePinChange: map[forcePinChangeIdx] as bool?, |
| 152 | + minPinLength: map[minPinLengthIdx] as int?, |
| 153 | + firmwareVersion: map[firmwareVersionIdx] as int?, |
| 154 | + maxCredBlobLength: map[maxCredBlobLengthIdx] as int?, |
| 155 | + maxRpIdsForSetMinPinLength: map[maxRpIdsForSetMinPinLengthIdx] as int?, |
| 156 | + preferredPlatformUvAttempts: map[preferredPlatformUvAttemptsIdx] as int?, |
| 157 | + uvModality: map[uvModalityIdx] as int?, |
| 158 | + certifications: (map[certificationsIdx] as Map?)?.cast<String, int>(), |
147 | 159 | remainingDiscoverableCredentials: |
148 | | - map[authInfoRemainingDiscoverableCredentialsIdx] as int?, |
| 160 | + map[remainingDiscoverableCredentialsIdx] as int?, |
149 | 161 | vendorPrototypeConfigCommands: |
150 | | - (map[authInfoVendorPrototypeConfigCommandsIdx] as List?)?.cast<int>(), |
| 162 | + (map[vendorPrototypeConfigCommandsIdx] as List?)?.cast<int>(), |
151 | 163 | ); |
152 | 164 | } |
153 | 165 | } |
0 commit comments