11private import csharp
22private import experimental.quantum.Language
33
4+ class CryptographyType extends Type {
5+ CryptographyType ( ) { this .hasFullyQualifiedName ( "System.Security.Cryptography" , _) }
6+ }
7+
8+ class ECParameters extends CryptographyType {
9+ ECParameters ( ) { this .hasName ( "ECParameters" ) }
10+ }
11+
12+ class RSAParameters extends CryptographyType {
13+ RSAParameters ( ) { this .hasName ( "RSAParameters" ) }
14+ }
15+
16+ class ECCurve extends CryptographyType {
17+ ECCurve ( ) { this .hasName ( "ECCurve" ) }
18+ }
19+
420// This class models Create calls for the ECDsa and RSA classes in .NET.
5- class CryptographyCreateCall extends MethodCall {
6- CryptographyCreateCall ( ) {
21+ class SigningCreateCall extends MethodCall {
22+ SigningCreateCall ( ) {
723 this .getTarget ( ) .getName ( ) = "Create" and
8- this .getQualifier ( ) .getType ( ) . hasFullyQualifiedName ( "System.Security.Cryptography" , _ )
24+ this .getQualifier ( ) .getType ( ) instanceof CryptographyType
925 }
1026
1127 Expr getAlgorithmArg ( ) {
@@ -25,37 +41,10 @@ class CryptographyCreateCall extends MethodCall {
2541 }
2642}
2743
28- class ECDsaCreateCall extends CryptographyCreateCall {
44+ class ECDsaCreateCall extends SigningCreateCall {
2945 ECDsaCreateCall ( ) { this .getQualifier ( ) .getType ( ) .hasName ( "ECDsa" ) }
3046}
3147
32- // TODO
33- // class HashAlgorithmCreateCall extends CryptographyCreateCall {
34- // ValueOrRefType type;
35-
36- // HashAlgorithmCreateCall() { type = this.getQualifier().getType().getDeclaringType() }
37- // }
38-
39- class RSACreateCall extends CryptographyCreateCall {
40- RSACreateCall ( ) { this .getQualifier ( ) .getType ( ) .hasName ( "RSA" ) }
41- }
42-
43- class CryptographyType extends Type {
44- CryptographyType ( ) { this .hasFullyQualifiedName ( "System.Security.Cryptography" , _) }
45- }
46-
47- class ECParameters extends CryptographyType {
48- ECParameters ( ) { this .hasName ( "ECParameters" ) }
49- }
50-
51- class RSAParameters extends CryptographyType {
52- RSAParameters ( ) { this .hasName ( "RSAParameters" ) }
53- }
54-
55- class ECCurve extends CryptographyType {
56- ECCurve ( ) { this .hasName ( "ECCurve" ) }
57- }
58-
5948// This class is used to model the `ECDsa.Create(ECParameters)` call
6049class ECDsaCreateCallWithParameters extends ECDsaCreateCall {
6150 ECDsaCreateCallWithParameters ( ) { this .getArgument ( 0 ) .getType ( ) instanceof ECParameters }
@@ -65,6 +54,28 @@ class ECDsaCreateCallWithECCurve extends ECDsaCreateCall {
6554 ECDsaCreateCallWithECCurve ( ) { this .getArgument ( 0 ) .getType ( ) instanceof ECCurve }
6655}
6756
57+ class RSACreateCall extends SigningCreateCall {
58+ RSACreateCall ( ) { this .getQualifier ( ) .getType ( ) .hasName ( "RSA" ) }
59+ }
60+
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+ ] )
76+ }
77+ }
78+
6879class SigningNamedCurvePropertyAccess extends PropertyAccess {
6980 string curveName ;
7081
@@ -163,8 +174,8 @@ class ReadOnlyByteSpanType extends Type {
163174 ReadOnlyByteSpanType ( ) { this .getName ( ) = "ReadOnlySpan<Byte>" }
164175}
165176
166- class DotNetSigner extends MethodCall {
167- DotNetSigner ( ) { this .getTarget ( ) .getName ( ) .matches ( [ "Verify%" , "Sign%" ] ) }
177+ class SignerUse extends MethodCall {
178+ SignerUse ( ) { this .getTarget ( ) .getName ( ) .matches ( [ "Verify%" , "Sign%" ] ) }
168179
169180 Expr getMessageArg ( ) {
170181 // Both Sign and Verify methods take the message as the first argument.
@@ -200,10 +211,10 @@ class DotNetSigner extends MethodCall {
200211 predicate isVerifier ( ) { this .getTarget ( ) .getName ( ) .matches ( "Verify%" ) }
201212}
202213
203- private class ECDsaSigner extends DotNetSigner {
214+ private class ECDsaSigner extends SignerUse {
204215 ECDsaSigner ( ) { this .getQualifier ( ) .getType ( ) instanceof ECDsaClass }
205216}
206217
207- private class RSASigner extends DotNetSigner {
218+ private class RSASigner extends SignerUse {
208219 RSASigner ( ) { this .getQualifier ( ) .getType ( ) instanceof RSAClass }
209220}
0 commit comments