@@ -6,8 +6,6 @@ import codeql.util.Location
66import codeql.util.Option
77
88signature module InputSig< LocationSig Location> {
9- class KnownUnknownLocation extends Location ;
10-
119 class LocatableElement {
1210 Location getLocation ( ) ;
1311 }
@@ -16,14 +14,7 @@ signature module InputSig<LocationSig Location> {
1614module CryptographyBase< LocationSig Location, InputSig< Location > Input> {
1715 final class LocatableElement = Input:: LocatableElement ;
1816
19- newtype TNode =
20- TNodeUnknown ( ) or
21- TNodeAsset ( ) or
22- TNodeValue ( ) // currently unused
23-
24- class KnownNode = TNodeAsset or TNodeValue ;
25-
26- abstract class NodeBase extends TNode {
17+ abstract class NodeBase instanceof LocatableElement {
2718 /**
2819 * Returns a string representation of this node, usually the name of the operation/algorithm/property.
2920 */
@@ -32,45 +23,27 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
3223 /**
3324 * Returns the location of this node in the code.
3425 */
35- abstract Location getLocation ( ) ;
26+ Location getLocation ( ) { result = super . getLocation ( ) }
3627
3728 /**
3829 * Returns the child of this node with the given edge name.
3930 *
4031 * This predicate is used by derived classes to construct the graph of cryptographic operations.
4132 */
42- NodeBase getChild ( string edgeName ) { none ( ) }
33+ NodeBase getChild ( string edgeName ) { edgeName = "origin" and result = this .getOrigin ( ) }
34+
35+ /**
36+ * Gets the origin of this node, e.g., a string literal in source describing it.
37+ */
38+ NodeBase getOrigin ( ) { none ( ) }
4339
4440 /**
4541 * Returns the parent of this node.
4642 */
4743 final NodeBase getAParent ( ) { result .getChild ( _) = this }
4844 }
4945
50- /**
51- * A node representing an unknown value.
52- *
53- * If a property should have a value but that value is unknown, `UnknownNode` to represent that value.
54- */
55- final class UnknownNode extends NodeBase , TNodeUnknown {
56- override string toString ( ) { result = "unknown" }
57-
58- override Location getLocation ( ) { result instanceof Input:: KnownUnknownLocation }
59- }
60-
61- /**
62- * A node with a known location in the code.
63- */
64- abstract class LocatableNode extends NodeBase , TNodeAsset {
65- abstract LocatableElement toElement ( ) ;
66-
67- override Location getLocation ( ) { result = this .toElement ( ) .getLocation ( ) }
68- }
69-
70- /**
71- * A node representing a known asset, i.e., an algorithm, operation, or property.
72- */
73- class Asset = LocatableNode ;
46+ class Asset = NodeBase ;
7447
7548 /**
7649 * A cryptographic operation, such as hashing or encryption.
@@ -79,12 +52,6 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
7952 /**
8053 * Gets the algorithm associated with this operation.
8154 */
82- private NodeBase getAlgorithmOrUnknown ( ) {
83- if exists ( this .getAlgorithm ( ) )
84- then result = this .getAlgorithm ( )
85- else result instanceof UnknownNode
86- }
87-
8855 abstract Algorithm getAlgorithm ( ) ;
8956
9057 /**
@@ -95,8 +62,10 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
9562 final override string toString ( ) { result = this .getOperationName ( ) }
9663
9764 override NodeBase getChild ( string edgeName ) {
65+ result = super .getChild ( edgeName )
66+ or
9867 edgeName = "algorithm" and
99- this .getAlgorithmOrUnknown ( ) = result
68+ if exists ( this .getAlgorithm ( ) ) then result = this . getAlgorithm ( ) else result = this
10069 }
10170 }
10271
@@ -125,6 +94,10 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
12594 */
12695 abstract class HashAlgorithm extends Algorithm { }
12796
97+ abstract class SHA1 extends HashAlgorithm {
98+ override string getAlgorithmName ( ) { result = "SHA1" }
99+ }
100+
128101 /**
129102 * An operation that derives one or more keys from an input value.
130103 */
@@ -142,24 +115,27 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
142115 /**
143116 * HKDF Extract+Expand key derivation function.
144117 */
145- abstract class HKDFAlgorithm extends KeyDerivationAlgorithm {
118+ abstract class HKDF extends KeyDerivationAlgorithm {
146119 final override string getAlgorithmName ( ) { result = "HKDF" }
147120
148- private NodeBase getHashAlgorithmOrUnknown ( ) {
149- if exists ( this .getHashAlgorithm ( ) )
150- then result = this .getHashAlgorithm ( )
151- else result instanceof UnknownNode
121+ abstract HashAlgorithm getHashAlgorithm ( ) ;
122+
123+ override NodeBase getChild ( string edgeName ) {
124+ result = super .getChild ( edgeName )
125+ or
126+ edgeName = "digest" and result = this .getHashAlgorithm ( )
152127 }
128+ }
129+
130+ abstract class PKCS12KDF extends KeyDerivationAlgorithm {
131+ final override string getAlgorithmName ( ) { result = "PKCS12KDF" }
153132
154133 abstract HashAlgorithm getHashAlgorithm ( ) ;
155134
156- /**
157- * digest:HashAlgorithm
158- */
159135 override NodeBase getChild ( string edgeName ) {
160136 result = super .getChild ( edgeName )
161137 or
162- edgeName = "digest" and result = this .getHashAlgorithmOrUnknown ( )
138+ edgeName = "digest" and result = this .getHashAlgorithm ( )
163139 }
164140 }
165141}
0 commit comments