@@ -36,6 +36,7 @@ public class DgcItalianRulesValidator : IRulesValidator, IBlacklistProvider, ICu
3636 private readonly ILogger ? Logger ;
3737 private readonly DgcItalianRulesValidatorOptions Options ;
3838 private readonly RulesProvider _rulesProvider ;
39+ private readonly LibraryVersionCheckProvider _libraryVersionCheckProvider ;
3940
4041 #region Implementation of IRulesValidator
4142
@@ -73,6 +74,7 @@ public async Task<IRulesValidationResult> GetRulesValidationResult(EuDGC? dgc,
7374 dgcJson ,
7475 validationInstant ,
7576 validationMode ,
77+ doubleScanMode : false ,
7678 signatureValidationResult ,
7779 blacklistValidationResult ,
7880 cancellationToken ) ;
@@ -143,6 +145,7 @@ public async Task RefreshBlacklist(CancellationToken cancellationToken = default
143145 /// <param name="dgcJson">The RAW json of the DGC</param>
144146 /// <param name="validationInstant"></param>
145147 /// <param name="validationMode">The Italian validation mode to be used</param>
148+ /// <param name="doubleScanMode">If true, enable rules for double checks in <see cref="ValidationMode.Booster"/> mode for test entries</param>
146149 /// <param name="signatureValidationResult">The result from the signature validation step</param>
147150 /// <param name="blacklistValidationResult">The result from the blacklist validation step</param>
148151 /// <param name="cancellationToken"></param>
@@ -151,6 +154,7 @@ public async Task<IRulesValidationResult> GetRulesValidationResult(EuDGC? dgc,
151154 string dgcJson ,
152155 DateTimeOffset validationInstant ,
153156 ValidationMode validationMode ,
157+ bool doubleScanMode = false ,
154158 SignatureValidationResult ? signatureValidationResult = null ,
155159 BlacklistValidationResult ? blacklistValidationResult = null ,
156160 CancellationToken cancellationToken = default )
@@ -196,7 +200,7 @@ public async Task<IRulesValidationResult> GetRulesValidationResult(EuDGC? dgc,
196200 }
197201
198202 // Checking min version:
199- CheckMinSdkVersion ( rules , validationInstant , validationMode ) ;
203+ await CheckMinSdkVersion ( validationInstant , validationMode ) ;
200204
201205 // Preparing model for validators
202206 var certificateModel = new ValidationCertificateModel
@@ -215,7 +219,14 @@ public async Task<IRulesValidationResult> GetRulesValidationResult(EuDGC? dgc,
215219 return result ;
216220 }
217221
218- return validator . CheckCertificate ( certificateModel , rules , validationMode ) ;
222+ // See https://github.com/ministero-salute/it-dgc-verificac19-sdk-android/compare/1.1.5...release/1.1.6
223+ if ( doubleScanMode && ! certificateModel . Dgc . HasTests ( ) )
224+ {
225+ result . StatusMessage = "Double scan mode is supported only by Test entries" ;
226+ result . ItalianStatus = DgcItalianResultStatus . NotValid ;
227+ }
228+
229+ return validator . CheckCertificate ( certificateModel , rules , validationMode , doubleScanMode ) ;
219230 }
220231 catch ( DgcRulesValidationException e )
221232 {
@@ -239,7 +250,7 @@ public async Task<IRulesValidationResult> GetRulesValidationResult(EuDGC? dgc,
239250 {
240251 if ( certificateModel . Dgc . HasVaccinations ( ) )
241252 return new VaccinationValidator ( Logger ) ;
242- if ( certificateModel . Dgc . HasRecoveries ( ) )
253+ if ( certificateModel . Dgc . HasRecoveries ( ) )
243254 return new RecoveryValidator ( Logger ) ;
244255 if ( certificateModel . Dgc . HasTests ( ) )
245256 return new TestValidator ( Logger ) ;
@@ -252,44 +263,37 @@ public async Task<IRulesValidationResult> GetRulesValidationResult(EuDGC? dgc,
252263 /// Check the minimum version of the SDK implementation required.
253264 /// If <see cref="DgcItalianRulesValidatorOptions.IgnoreMinimumSdkVersion"/> is false, an exception will be thrown if the implementation is obsolete
254265 /// </summary>
255- /// <param name="rules"></param>
256266 /// <param name="validationInstant"></param>
257267 /// <param name="validationMode"></param>
268+ /// <param name="cancellation"></param>
258269 /// <exception cref="DgcRulesValidationException"></exception>
259- private void CheckMinSdkVersion ( IEnumerable < RuleSetting > rules , DateTimeOffset validationInstant , ValidationMode validationMode )
270+ private async Task CheckMinSdkVersion (
271+ DateTimeOffset validationInstant ,
272+ ValidationMode validationMode ,
273+ CancellationToken cancellation = default )
260274 {
261- var obsolete = false ;
262- string message = string . Empty ;
263-
275+ var assemblyName = this . GetType ( ) . Assembly . GetName ( ) ;
276+ Version ? latestVersion = null ;
264277
265- var sdkMinVersion = rules . GetRule ( SettingNames . SdkMinVersion , SettingTypes . AppMinVersion ) ;
266- if ( sdkMinVersion != null )
278+ // New check: verify library version by checking the GitHub repository
279+ try
267280 {
268- if ( sdkMinVersion . Value . CompareTo ( SdkConstants . ReferenceSdkMinVersion ) > 0 )
281+ latestVersion = await _libraryVersionCheckProvider . GetValueSet ( cancellation ) ;
282+ if ( latestVersion == null )
269283 {
270- obsolete = true ;
271- message = $ "The minimum version of the SDK implementation is { sdkMinVersion . Value } . " +
272- $ "Please update the package with the latest implementation in order to get a reliable result";
284+ Logger ? . LogWarning ( "Unable to get library version. Skip check" ) ;
285+ return ;
273286 }
274287 }
275- else
288+ catch ( Exception e )
276289 {
277- // Fallback to android app version
278- var appMinVersion = rules . GetRule ( SettingNames . AndroidAppMinVersion , SettingTypes . AppMinVersion ) ;
279- if ( appMinVersion != null )
280- {
281- if ( appMinVersion . Value . CompareTo ( SdkConstants . ReferenceAppMinVersion ) > 0 )
282- {
283- obsolete = true ;
284- message = $ "The minimum version of the App implementation is { appMinVersion . Value } . " +
285- $ "Please update the package with the latest implementation in order to get a reliable result";
286- }
287- }
290+ Logger ? . LogWarning ( "Failed to check library latest release: {errorMessage}" , e . Message ) ;
288291 }
289292
290- if ( obsolete )
293+ var currentVersion = assemblyName . Version ;
294+ if ( latestVersion > currentVersion )
291295 {
292-
296+ var message = $ "The current { assemblyName . Name } version ( { currentVersion } ) is obsolete. Please update the package to the latest version ( { latestVersion } ) in order to get a reliable result" ;
293297 if ( Options . IgnoreMinimumSdkVersion )
294298 {
295299 Logger ? . LogWarning ( message ) ;
@@ -325,6 +329,7 @@ public DgcItalianRulesValidator(HttpClient httpClient,
325329 Logger = logger ;
326330
327331 _rulesProvider = new RulesProvider ( httpClient , Options , logger ) ;
332+ _libraryVersionCheckProvider = new LibraryVersionCheckProvider ( httpClient , logger ) ;
328333 }
329334
330335 /// <summary>
@@ -354,6 +359,7 @@ public DgcItalianRulesValidator(HttpClient httpClient,
354359 Logger = logger ;
355360
356361 _rulesProvider = new RulesProvider ( httpClient , Options , logger ) ;
362+ _libraryVersionCheckProvider = new LibraryVersionCheckProvider ( httpClient , logger ) ;
357363 }
358364
359365 /// <summary>
0 commit comments