99
1010namespace SAPTeam . EasySign . CommandLine
1111{
12+ /// <summary>
13+ /// Provides utility methods for various operations.
14+ /// </summary>
1215 public static class Utils
1316 {
17+ /// <summary>
18+ /// Runs the specified action within a status context, provides fancy progress showing.
19+ /// </summary>
20+ /// <param name="action">The action to run within the status context.</param>
1421 public static void RunInStatusContext ( Action < StatusContext > action )
1522 {
1623 AnsiConsole . Status ( )
@@ -19,6 +26,12 @@ public static void RunInStatusContext(Action<StatusContext> action)
1926 . Start ( "" , action ) ;
2027 }
2128
29+ /// <summary>
30+ /// Safely enumerates files in the specified path that match the search pattern.
31+ /// </summary>
32+ /// <param name="path">The path to search for files.</param>
33+ /// <param name="searchPattern">The search pattern to match files.</param>
34+ /// <returns>An enumerable collection of file paths.</returns>
2235 public static IEnumerable < string > SafeEnumerateFiles ( string path , string searchPattern )
2336 {
2437 ConcurrentQueue < string > folders = new ( ) ;
@@ -57,6 +70,13 @@ public static IEnumerable<string> SafeEnumerateFiles(string path, string searchP
5770 }
5871 }
5972
73+ /// <summary>
74+ /// Retrieves a collection of certificates from a PFX file or the current user's certificate store.
75+ /// </summary>
76+ /// <param name="pfxFilePath">The path to the PFX file.</param>
77+ /// <param name="pfxFilePassword">The password for the PFX file.</param>
78+ /// <param name="pfxNoPasswordPrompt">Indicates whether to prompt for a password if not provided.</param>
79+ /// <returns>A collection of certificates.</returns>
6080 public static X509Certificate2Collection GetCertificates ( string pfxFilePath , string pfxFilePassword , bool pfxNoPasswordPrompt )
6181 {
6282 X509Certificate2Collection collection = new ( ) ;
@@ -66,7 +86,7 @@ public static X509Certificate2Collection GetCertificates(string pfxFilePath, str
6686 string pfpass = ! string . IsNullOrEmpty ( pfxFilePassword ) ? pfxFilePassword : ! pfxNoPasswordPrompt ? SecurePrompt ( "Enter PFX File password (if needed): " ) : "" ;
6787
6888#if NET9_0_OR_GREATER
69- var tempCollection = X509CertificateLoader . LoadPkcs12CollectionFromFile ( pfxFilePath , pfpass , X509KeyStorageFlags . EphemeralKeySet ) ;
89+ var tempCollection = X509CertificateLoader . LoadPkcs12CollectionFromFile ( pfxFilePath , pfpass , X509KeyStorageFlags . EphemeralKeySet ) ;
7090#else
7191 var tempCollection = new X509Certificate2Collection ( ) ;
7292 tempCollection . Import ( pfxFilePath , pfpass , X509KeyStorageFlags . EphemeralKeySet ) ;
@@ -105,6 +125,11 @@ public static X509Certificate2Collection GetCertificates(string pfxFilePath, str
105125 return collection ;
106126 }
107127
128+ /// <summary>
129+ /// Prompts the user for input securely, hiding the input as it is typed.
130+ /// </summary>
131+ /// <param name="prompt">The prompt message to display.</param>
132+ /// <returns>The user input.</returns>
108133 public static string SecurePrompt ( string prompt )
109134 {
110135 return AnsiConsole . Prompt (
@@ -114,6 +139,10 @@ public static string SecurePrompt(string prompt)
114139 . Secret ( null ) ) ;
115140 }
116141
142+ /// <summary>
143+ /// Enumerates and displays the statuses of an X509 certificate chain.
144+ /// </summary>
145+ /// <param name="statuses">The array of X509 chain statuses.</param>
117146 public static void EnumerateStatuses ( X509ChainStatus [ ] statuses )
118147 {
119148 foreach ( var status in statuses )
0 commit comments