@@ -5,59 +5,59 @@ namespace ADCS.CertMod.Managed.Extensions;
55
66static class CertServerModuleExtensions {
77 #region private helpers
8-
9- public static T GetInSubjectProperty < T > ( this ICertServerModule certExit , IntPtr pvarPropertyValue , RequestSubjectName subjectName ) {
10- certExit . getScalarProperty ( pvarPropertyValue , "Subject." + subjectName , out T retValue ) ;
8+
9+ public static T GetInSubjectProperty < T > ( this ICertServerModule certServerModule , IntPtr pvarPropertyValue , RequestSubjectName subjectName ) {
10+ certServerModule . getScalarProperty ( pvarPropertyValue , "Subject." + subjectName , out T retValue ) ;
1111
1212 return retValue ;
1313 }
14- public static T GetOutSubjectProperty < T > ( this ICertServerModule certExit , IntPtr pvarPropertyValue , RequestSubjectName subjectName ) {
15- certExit . getScalarProperty ( pvarPropertyValue , subjectName . ToString ( ) , out T retValue ) ;
14+ public static T GetOutSubjectProperty < T > ( this ICertServerModule certServerModule , IntPtr pvarPropertyValue , RequestSubjectName subjectName ) {
15+ certServerModule . getScalarProperty ( pvarPropertyValue , subjectName . ToString ( ) , out T retValue ) ;
1616
1717 return retValue ;
1818 }
1919
20- public static Byte [ ] GetInSubjectNameBin ( this ICertServerModule certExit , IntPtr pvarPropertyValue , RequestSubjectName propertyName ) {
21- return certExit . getBinaryProperty ( pvarPropertyValue , "Subject." + propertyName ) ;
20+ public static Byte [ ] GetInSubjectNameBin ( this ICertServerModule certServerModule , IntPtr pvarPropertyValue , RequestSubjectName propertyName ) {
21+ return certServerModule . getBinaryProperty ( pvarPropertyValue , "Subject." + propertyName ) ;
2222 }
23- public static Byte [ ] GetOutSubjectNameBin ( this ICertServerModule certExit , IntPtr pvarPropertyValue , RequestSubjectName propertyName ) {
24- return certExit . getBinaryProperty ( pvarPropertyValue , propertyName . ToString ( ) ) ;
23+ public static Byte [ ] GetOutSubjectNameBin ( this ICertServerModule certServerModule , IntPtr pvarPropertyValue , RequestSubjectName propertyName ) {
24+ return certServerModule . getBinaryProperty ( pvarPropertyValue , propertyName . ToString ( ) ) ;
2525 }
2626
27- public static T GetRequestProperty < T > ( this ICertServerModule certExit , IntPtr pvarPropertyValue , RequestPropertyName propertyName ) {
28- certExit . getScalarProperty ( pvarPropertyValue , propertyName . ToString ( ) , out T retValue ) ;
27+ public static T GetRequestProperty < T > ( this ICertServerModule certServerModule , IntPtr pvarPropertyValue , RequestPropertyName propertyName ) {
28+ certServerModule . getScalarProperty ( pvarPropertyValue , propertyName . ToString ( ) , out T retValue ) ;
2929
3030 return retValue ;
3131 }
32- public static Byte [ ] GetRequestPropertyBin ( this ICertServerModule certExit , IntPtr pvarPropertyValue , RequestPropertyName propertyName ) {
33- return certExit . getBinaryProperty ( pvarPropertyValue , propertyName . ToString ( ) ) ;
32+ public static Byte [ ] GetRequestPropertyBin ( this ICertServerModule certServerModule , IntPtr pvarPropertyValue , RequestPropertyName propertyName ) {
33+ return certServerModule . getBinaryProperty ( pvarPropertyValue , propertyName . ToString ( ) ) ;
3434 }
3535
36- public static T GetCertProperty < T > ( this ICertServerModule certExit , IntPtr pvarPropertyValue , CertificatePropertyName propertyName ) {
37- certExit . getScalarProperty ( pvarPropertyValue , propertyName . ToString ( ) , out T retValue , true ) ;
36+ public static T GetCertProperty < T > ( this ICertServerModule certServerModule , IntPtr pvarPropertyValue , CertificatePropertyName propertyName ) {
37+ certServerModule . getScalarProperty ( pvarPropertyValue , propertyName . ToString ( ) , out T retValue , true ) ;
3838
3939 return retValue ;
4040 }
41- public static Byte [ ] GetCertPropertyBin ( this ICertServerModule certExit , IntPtr pvarPropertyValue , CertificatePropertyName propertyName ) {
42- return certExit . getBinaryProperty ( pvarPropertyValue , propertyName . ToString ( ) , true ) ;
41+ public static Byte [ ] GetCertPropertyBin ( this ICertServerModule certServerModule , IntPtr pvarPropertyValue , CertificatePropertyName propertyName ) {
42+ return certServerModule . getBinaryProperty ( pvarPropertyValue , propertyName . ToString ( ) , true ) ;
4343 }
4444
45- public static Int32 ? GetLongProperty ( this ICertServerModule certExit , IntPtr pvarPropertyValue , String propertyName , Boolean cert = false ) {
46- if ( certExit . getScalarProperty ( pvarPropertyValue , propertyName , out Int32 retValue , cert ) ) {
45+ public static Int32 ? GetLongProperty ( this ICertServerModule certServerModule , IntPtr pvarPropertyValue , String propertyName , Boolean cert = false ) {
46+ if ( certServerModule . getScalarProperty ( pvarPropertyValue , propertyName , out Int32 retValue , cert ) ) {
4747 return retValue ;
4848 }
4949
5050 return null ;
5151 }
52- public static DateTime ? GetDateTimeProperty ( this ICertServerModule certExit , IntPtr pvarPropertyValue , String propertyName , Boolean cert = false ) {
53- if ( certExit . getScalarProperty ( pvarPropertyValue , propertyName , out DateTime retValue , cert ) ) {
52+ public static DateTime ? GetDateTimeProperty ( this ICertServerModule certServerModule , IntPtr pvarPropertyValue , String propertyName , Boolean cert = false ) {
53+ if ( certServerModule . getScalarProperty ( pvarPropertyValue , propertyName , out DateTime retValue , cert ) ) {
5454 return retValue ;
5555 }
5656
5757 return null ;
5858 }
5959
60- static Boolean getScalarProperty < T > ( this ICertServerModule certExit , IntPtr pvarPropertyValue , String propertyName , out T retValue , Boolean cert = false ) {
60+ static Boolean getScalarProperty < T > ( this ICertServerModule certServerModule , IntPtr pvarPropertyValue , String propertyName , out T retValue , Boolean cert = false ) {
6161 retValue = default ;
6262 Type leftType = typeof ( T ) ;
6363 Int32 propType ;
@@ -72,36 +72,31 @@ static Boolean getScalarProperty<T>(this ICertServerModule certExit, IntPtr pvar
7272 return false ;
7373 }
7474
75- try {
76- if ( cert ) {
77- certExit . GetCertificateProperty ( propertyName , propType , pvarPropertyValue ) ;
78- } else {
79- certExit . GetRequestProperty ( propertyName , propType , pvarPropertyValue ) ;
80- }
81-
82- retValue = ( T ) Marshal . GetObjectForNativeVariant ( pvarPropertyValue ) ;
83- OleAut32 . VariantClear ( pvarPropertyValue ) ;
84-
85- return true ;
86- } catch {
75+ Int32 hresult = cert
76+ ? certServerModule . GetCertificateProperty ( propertyName , propType , pvarPropertyValue )
77+ : certServerModule . GetRequestProperty ( propertyName , propType , pvarPropertyValue ) ;
78+ if ( hresult != 0 ) {
8779 return false ;
8880 }
81+
82+ retValue = ( T ) Marshal . GetObjectForNativeVariant ( pvarPropertyValue ) ;
83+ OleAut32 . VariantClear ( pvarPropertyValue ) ;
84+
85+ return true ;
8986 }
90- static Byte [ ] getBinaryProperty ( this ICertServerModule certExit , IntPtr pvarPropertyValue , String propertyName , Boolean cert = false ) {
91- try {
92- if ( cert ) {
93- certExit . GetCertificateProperty ( propertyName , CertSrvH . PROPTYPE_BINARY , pvarPropertyValue ) ;
94- } else {
95- certExit . GetRequestProperty ( propertyName , CertSrvH . PROPTYPE_BINARY , pvarPropertyValue ) ;
96- }
97-
98- Byte [ ] retValue = pvarPropertyValue . GetBstrBinary ( null ) ;
99- OleAut32 . VariantClear ( pvarPropertyValue ) ;
87+ static Byte [ ] getBinaryProperty ( this ICertServerModule certServerModule , IntPtr pvarPropertyValue , String propertyName , Boolean cert = false ) {
88+ Int32 hresult = cert
89+ ? certServerModule . GetCertificateProperty ( propertyName , CertSrvH . PROPTYPE_BINARY , pvarPropertyValue )
90+ : certServerModule . GetRequestProperty ( propertyName , CertSrvH . PROPTYPE_BINARY , pvarPropertyValue ) ;
10091
101- return retValue ;
102- } catch {
92+ if ( hresult != 0 ) {
10393 return default ;
10494 }
95+
96+ Byte [ ] retValue = pvarPropertyValue . GetBstrBinary ( null ) ;
97+ OleAut32 . VariantClear ( pvarPropertyValue ) ;
98+
99+ return retValue ;
105100 }
106101
107102 #endregion
0 commit comments