@@ -17,9 +17,25 @@ class ECCurve extends CryptographyType {
1717 ECCurve ( ) { this .hasName ( "ECCurve" ) }
1818}
1919
20+ class HashAlgorithmType extends CryptographyType {
21+ HashAlgorithmType ( ) {
22+ this .hasName ( [
23+ "MD5" ,
24+ "RIPEMD160" ,
25+ "SHA1" ,
26+ "SHA256" ,
27+ "SHA384" ,
28+ "SHA512" ,
29+ "SHA3_256" ,
30+ "SHA3_384" ,
31+ "SHA3_512"
32+ ] )
33+ }
34+ }
35+
2036// This class models Create calls for the ECDsa and RSA classes in .NET.
21- class SigningCreateCall extends MethodCall {
22- SigningCreateCall ( ) {
37+ class CryptographyCreateCall extends MethodCall {
38+ CryptographyCreateCall ( ) {
2339 this .getTarget ( ) .getName ( ) = "Create" and
2440 this .getQualifier ( ) .getType ( ) instanceof CryptographyType
2541 }
@@ -41,7 +57,7 @@ class SigningCreateCall extends MethodCall {
4157 }
4258}
4359
44- class ECDsaCreateCall extends SigningCreateCall {
60+ class ECDsaCreateCall extends CryptographyCreateCall {
4561 ECDsaCreateCall ( ) { this .getQualifier ( ) .getType ( ) .hasName ( "ECDsa" ) }
4662}
4763
@@ -54,28 +70,21 @@ class ECDsaCreateCallWithECCurve extends ECDsaCreateCall {
5470 ECDsaCreateCallWithECCurve ( ) { this .getArgument ( 0 ) .getType ( ) instanceof ECCurve }
5571}
5672
57- class RSACreateCall extends SigningCreateCall {
73+ class RSACreateCall extends CryptographyCreateCall {
5874 RSACreateCall ( ) { this .getQualifier ( ) .getType ( ) .hasName ( "RSA" ) }
5975}
6076
61- class HashAlgorithmCreateCall extends SigningCreateCall {
62- HashAlgorithmCreateCall ( ) {
63- this .getQualifier ( )
64- .getType ( )
65- .hasName ( [
66- "MD5" ,
67- "RIPEMD160" ,
68- "SHA1" ,
69- "SHA256" ,
70- "SHA384" ,
71- "SHA512" ,
72- "SHA3_256" ,
73- "SHA3_384" ,
74- "SHA3_512"
75- ] )
77+ class SigningCreateCall extends CryptographyCreateCall {
78+ SigningCreateCall ( ) {
79+ this instanceof ECDsaCreateCall or
80+ this instanceof RSACreateCall
7681 }
7782}
7883
84+ class HashAlgorithmCreateCall extends CryptographyCreateCall {
85+ HashAlgorithmCreateCall ( ) { this .getQualifier ( ) .getType ( ) instanceof HashAlgorithmType }
86+ }
87+
7988class SigningNamedCurvePropertyAccess extends PropertyAccess {
8089 string curveName ;
8190
@@ -166,6 +175,13 @@ private class RSAClass extends CryptographyType {
166175 RSAClass ( ) { this .hasName ( "RSA" ) }
167176}
168177
178+ private class SignerType extends Type {
179+ SignerType ( ) {
180+ this instanceof ECDsaClass or
181+ this instanceof RSAClass
182+ }
183+ }
184+
169185class ByteArrayType extends Type {
170186 ByteArrayType ( ) { this .getName ( ) = "Byte[]" }
171187}
@@ -174,8 +190,25 @@ class ReadOnlyByteSpanType extends Type {
174190 ReadOnlyByteSpanType ( ) { this .getName ( ) = "ReadOnlySpan<Byte>" }
175191}
176192
193+ class HashUse extends MethodCall {
194+ HashUse ( ) {
195+ this .getQualifier ( ) .getType ( ) instanceof HashAlgorithmType and
196+ this .getTarget ( )
197+ .getName ( )
198+ .matches ( [
199+ "ComputeHash" , "ComputeHashAsync" , "HashCore" , "HashData" , "HashDataAsync" ,
200+ "TransformBlock" , "TransformFinalBlock" , "TryComputeHash" , "TryHashData" , "TryHashFinal"
201+ ] )
202+ }
203+
204+ predicate isIntermediate ( ) { this .getTarget ( ) .hasName ( "HashCore" ) }
205+ }
206+
177207class SignerUse extends MethodCall {
178- SignerUse ( ) { this .getTarget ( ) .getName ( ) .matches ( [ "Verify%" , "Sign%" ] ) }
208+ SignerUse ( ) {
209+ this .getTarget ( ) .getName ( ) .matches ( [ "Verify%" , "Sign%" ] ) and
210+ this .getQualifier ( ) .getType ( ) instanceof SignerType
211+ }
179212
180213 Expr getMessageArg ( ) {
181214 // Both Sign and Verify methods take the message as the first argument.
0 commit comments