Skip to content

Commit 3913f44

Browse files
committed
quanntum-c#: refactor class names
1 parent 01b98fc commit 3913f44

3 files changed

Lines changed: 50 additions & 39 deletions

File tree

csharp/ql/lib/experimental/quantum/dotnet/Cryptography.qll

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
private import csharp
22
private 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
6049
class 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+
6879
class 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
}

csharp/ql/lib/experimental/quantum/dotnet/FlowAnalysis.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ signature class UseCallSig instanceof QualifiableExpr {
3232
predicate isIntermediate();
3333
}
3434

35-
module CryptographyCreateToUseFlow = CreationToUseFlow<CryptographyCreateCall, DotNetSigner>;
35+
module SigningCreateToUseFlow = CreationToUseFlow<SigningCreateCall, SignerUse>;
3636

3737
module CreationToUseFlow<CreationCallSig Creation, UseCallSig Use> {
3838
private module CreationToUseConfig implements DataFlow::ConfigSig {

csharp/ql/lib/experimental/quantum/dotnet/OperationInstances.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ private import DataFlow
44
private import FlowAnalysis
55
private import Cryptography
66

7-
class ECDsaORRSASigningOperationInstance extends Crypto::SignatureOperationInstance instanceof DotNetSigner
7+
class ECDsaORRSASigningOperationInstance extends Crypto::SignatureOperationInstance instanceof SignerUse
88
{
9-
CryptographyCreateCall creator;
9+
SigningCreateCall creator;
1010

1111
ECDsaORRSASigningOperationInstance() {
12-
creator = CryptographyCreateToUseFlow::getCreationFromUse(this, _, _)
12+
creator = SigningCreateToUseFlow::getCreationFromUse(this, _, _)
1313
}
1414

1515
override Crypto::AlgorithmValueConsumer getAnAlgorithmValueConsumer() {

0 commit comments

Comments
 (0)