1- using System ;
2- using System . Collections . Generic ;
3- using System . Security . Cryptography . X509Certificates ;
4- using System . Text ;
1+ using System . Security . Cryptography . X509Certificates ;
52
63using Microsoft . Extensions . Logging ;
74
@@ -54,15 +51,15 @@ protected virtual void RunAdd(StatusContext statusContext, bool replace, bool co
5451 statusContext . Status ( "[yellow]Adding Files[/]" ) ;
5552
5653 Logger . LogDebug ( "Discovering files in the directory: {RootPath}" , Bundle . RootPath ) ;
57- var foundFiles = Utilities . SafeEnumerateFiles ( Bundle . RootPath , "*" ) . ToArray ( ) ;
54+ string [ ] foundFiles = Utilities . SafeEnumerateFiles ( Bundle . RootPath , "*" ) . ToArray ( ) ;
5855 Logger . LogInformation ( "Discovered {FileCount} files" , foundFiles . Count ( ) ) ;
5956
6057 Logger . LogInformation ( "Starting file adder multi-thread task" ) ;
6158 bool errorOccurred = false ;
6259 _ = Parallel . ForEach ( foundFiles , ( file , state ) =>
6360 {
6461 if ( file == Bundle . BundlePath ) return ;
65- var entryName = Manifest . GetNormalizedEntryName ( Path . GetRelativePath ( Bundle . RootPath , file ) ) ;
62+ string entryName = Manifest . GetNormalizedEntryName ( Path . GetRelativePath ( Bundle . RootPath , file ) ) ;
6663
6764 Logger . LogInformation ( "Processing file: {EntryName}" , entryName ) ;
6865
@@ -88,7 +85,7 @@ protected virtual void RunAdd(StatusContext statusContext, bool replace, bool co
8885 else
8986 {
9087 Logger . LogDebug ( "Adding entry: {EntryName}" , entryName ) ;
91-
88+
9289 Bundle . AddEntry ( file ) ;
9390
9491 Logger . LogInformation ( "Entry: {EntryName} Added" , entryName ) ;
@@ -159,14 +156,14 @@ protected virtual void RunSign(StatusContext statusContext, X509Certificate2Coll
159156 int divider = 0 ;
160157 int signs = 0 ;
161158
162- foreach ( var cert in certificates )
159+ foreach ( X509Certificate2 cert in certificates )
163160 {
164161 if ( divider ++ > 0 ) AnsiConsole . WriteLine ( ) ;
165162
166163 Logger . LogDebug ( "Loading certificate information for {Cert}" , cert ) ;
167164 statusContext . Status ( "[yellow]Loading certificate informations[/]" ) ;
168165
169- var grid = new Grid ( ) ;
166+ Grid grid = new Grid ( ) ;
170167 grid . AddColumn ( new GridColumn ( ) . NoWrap ( ) ) ;
171168 grid . AddColumn ( new GridColumn ( ) . PadLeft ( 2 ) ) ;
172169 grid . AddRow ( "Certificate Info:" ) ;
@@ -193,7 +190,7 @@ protected virtual void RunSign(StatusContext statusContext, X509Certificate2Coll
193190 Logger . LogDebug ( "Acquiring RSA private key for {cert}" , cert ) ;
194191 statusContext . Status ( "[yellow]Preparing for signing[/]" ) ;
195192
196- var prvKey = cert . GetRSAPrivateKey ( ) ;
193+ System . Security . Cryptography . RSA ? prvKey = cert . GetRSAPrivateKey ( ) ;
197194 if ( prvKey == null )
198195 {
199196 Logger . LogError ( "Failed to acquire RSA private key for {cert}" , cert ) ;
@@ -239,7 +236,7 @@ protected virtual void RunVerify(StatusContext statusContext)
239236 throw new ApplicationException ( "Bundle is not initialized" ) ;
240237 }
241238
242- var colorDict = new Dictionary < string , Color > ( )
239+ Dictionary < string , Color > colorDict = new Dictionary < string , Color > ( )
243240 {
244241 [ "file_verified" ] = Color . MediumSpringGreen ,
245242 [ "file_failed" ] = Color . OrangeRed1 ,
@@ -257,24 +254,24 @@ protected virtual void RunVerify(StatusContext statusContext)
257254 int verifiedCerts = 0 ;
258255 int divider = 0 ;
259256
260- foreach ( var certificateHash in Bundle . Signatures . Entries . Keys )
257+ foreach ( string certificateHash in Bundle . Signatures . Entries . Keys )
261258 {
262259 if ( divider ++ > 0 ) AnsiConsole . WriteLine ( ) ;
263260
264- var certificate = Bundle . GetCertificate ( certificateHash ) ;
261+ X509Certificate2 certificate = Bundle . GetCertificate ( certificateHash ) ;
265262
266263 Logger . LogDebug ( "Verifying certificate {cert}" , certificate ) ;
267264 AnsiConsole . MarkupLine ( $ "Verifying Certificate [{ Color . Teal } ]{ certificate . GetNameInfo ( X509NameType . SimpleName , false ) } [/] Issued by [{ Color . Aqua } ]{ certificate . GetNameInfo ( X509NameType . SimpleName , true ) } [/]") ;
268265
269- var verifyCert = VerifyCertificate ( certificate ) ;
266+ bool verifyCert = VerifyCertificate ( certificate ) ;
270267 if ( ! verifyCert )
271268 {
272269 Logger . LogWarning ( "Skipping signature verification for {cert}" , certificate ) ;
273270 continue ;
274271 }
275272
276273 Logger . LogDebug ( "Verifying signature for certificate {cert}" , certificate ) ;
277- var verifySign = Bundle . VerifySignature ( certificateHash ) ;
274+ bool verifySign = Bundle . VerifySignature ( certificateHash ) ;
278275 AnsiConsole . MarkupLine ( $ "[{ ( verifySign ? Color . Green : Color . Red ) } ] Signature Verification { ( verifySign ? "Successful" : "Failed" ) } [/]") ;
279276 if ( ! verifySign )
280277 {
@@ -326,7 +323,7 @@ protected virtual void RunVerify(StatusContext statusContext)
326323
327324 _ = Parallel . ForEach ( Bundle . Manifest . Entries , ( entry ) =>
328325 {
329- var verifyFile = false ;
326+ bool verifyFile = false ;
330327
331328 Logger . LogDebug ( "Verifying file {file}" , entry . Key ) ;
332329
@@ -399,10 +396,10 @@ protected bool VerifyCertificate(X509Certificate2 certificate)
399396 throw new ApplicationException ( "Bundle is not initialized" ) ;
400397 }
401398
402- List < bool > verifyResults = new ( ) ;
399+ List < bool > verifyResults = [ ] ;
403400
404401 Logger . LogDebug ( "Verifying certificate {cert} with default verification policy" , certificate ) ;
405- var defaultVerification = Bundle . VerifyCertificate ( certificate , out X509ChainStatus [ ] statuses ) ;
402+ bool defaultVerification = Bundle . VerifyCertificate ( certificate , out X509ChainStatus [ ] statuses ) ;
406403 verifyResults . Add ( defaultVerification ) ;
407404
408405 Logger . LogInformation ( "Certificate verification with default policy for {cert}: {result}" , certificate , defaultVerification ) ;
@@ -418,10 +415,10 @@ protected bool VerifyCertificate(X509Certificate2 certificate)
418415 {
419416 Logger . LogWarning ( "Certificate has time validity issues, retrying verification with time check disabled" ) ;
420417
421- var policy = new X509ChainPolicy ( ) ;
418+ X509ChainPolicy policy = new X509ChainPolicy ( ) ;
422419 policy . VerificationFlags |= X509VerificationFlags . IgnoreNotTimeValid ;
423420
424- var noTimeVerification = Bundle . VerifyCertificate ( certificate , out X509ChainStatus [ ] noTimeStatuses , policy : policy ) ;
421+ bool noTimeVerification = Bundle . VerifyCertificate ( certificate , out X509ChainStatus [ ] noTimeStatuses , policy : policy ) ;
425422 verifyResults . Add ( noTimeVerification ) ;
426423
427424 Logger . LogInformation ( "Certificate verification without time checking for {cert}: {result}" , certificate , noTimeVerification ) ;
0 commit comments