Skip to content

Commit a7c5f7a

Browse files
committed
refactoring
1 parent e0430a7 commit a7c5f7a

2 files changed

Lines changed: 27 additions & 22 deletions

File tree

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
private import csharp
22
private import experimental.quantum.Language
3+
private import FlowAnalysis
34

45
class CryptographyType extends Type {
56
CryptographyType() { this.hasFullyQualifiedName("System.Security.Cryptography", _) }
@@ -190,6 +191,13 @@ class ReadOnlyByteSpanType extends Type {
190191
ReadOnlyByteSpanType() { this.getName() = "ReadOnlySpan<Byte>" }
191192
}
192193

194+
class ByteArrayOrReadOnlyByteSpanType extends Type {
195+
ByteArrayOrReadOnlyByteSpanType() {
196+
this instanceof ByteArrayType or
197+
this instanceof ReadOnlyByteSpanType
198+
}
199+
}
200+
193201
class HashUse extends MethodCall {
194202
HashUse() {
195203
this.getQualifier().getType() instanceof HashAlgorithmType and
@@ -217,9 +225,13 @@ class HashUse extends MethodCall {
217225
else result = this
218226
}
219227

220-
Expr getInputConsumer() {
221-
not this.getTarget().getName() = "HashFinal" and result = this.getArgument(0)
228+
Expr getInputArg() {
229+
result = this.getAnArgument() and result.getType() instanceof ByteArrayOrReadOnlyByteSpanType
222230
}
231+
// Expr getStreamArg() {
232+
// result = this.getAnArgument() and
233+
// result.getType() instanceof Stream
234+
// }
223235
}
224236

225237
class SignerUse extends MethodCall {
@@ -238,10 +250,7 @@ class SignerUse extends MethodCall {
238250
this.isVerifier() and
239251
(
240252
result = this.getArgument([1, 3]) and
241-
(
242-
result.getType() instanceof ByteArrayType or
243-
result.getType() instanceof ReadOnlyByteSpanType
244-
)
253+
result.getType() instanceof ByteArrayOrReadOnlyByteSpanType
245254
)
246255
}
247256

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,18 @@ class ECDsaORRSASigningOperationInstance extends Crypto::SignatureOperationInsta
4545
}
4646
}
4747

48-
class HashOperationInstance extends Crypto::HashOperationInstance instanceof HashUse {
49-
HashAlgorithmCreateCall creator;
50-
51-
HashOperationInstance() { creator = HashCreateToUseFlow::getCreationFromUse(this, _, _) }
52-
53-
override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() {
54-
result = DataFlow::exprNode(this.(HashUse).getOutputArtifact())
55-
}
56-
57-
override Crypto::ConsumerInputDataFlowNode getInputConsumer() {
58-
result = DataFlow::exprNode(this.(HashUse).getInputConsumer())
59-
}
60-
61-
override Crypto::AlgorithmValueConsumer getAnAlgorithmValueConsumer() { none() }
62-
}
63-
48+
// class HashOperationInstance extends Crypto::HashOperationInstance instanceof HashUse {
49+
// HashOperationInstance() {
50+
// not super.isIntermediate()
51+
// }
52+
// override Crypto::ArtifactOutputDataFlowNode getOutputArtifact() {
53+
// result.asExpr() = super.getOutputArtifact()
54+
// }
55+
// override Crypto::ConsumerInputDataFlowNode getInputConsumer() {
56+
// result.asExpr() = super.getInputArg() or result = StreamFlow::getIntermediateUse(this.getStreamArg(), _, _).getInputArg()
57+
// }
58+
// override Crypto::AlgorithmValueConsumer getAnAlgorithmValueConsumer() { result = HashCreateToUseFlow::getCreationFromUse(this, _, _) }
59+
// }
6460
/**
6561
* A symmetric algorithm class, such as AES or DES.
6662
*/

0 commit comments

Comments
 (0)