@@ -79,7 +79,11 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
7979
8080 abstract class KeyDerivationAlgorithmInstance extends LocatableElement { }
8181
82- abstract class EncryptionOperationInstance extends LocatableElement { }
82+ abstract class CipherOperationInstance extends LocatableElement {
83+ abstract EncryptionAlgorithmInstance getAlgorithm ( ) ;
84+
85+ abstract TCipherOperationMode getCipherOperationMode ( ) ;
86+ }
8387
8488 abstract class EncryptionAlgorithmInstance extends LocatableElement { }
8589
@@ -115,7 +119,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
115119 // Operations (e.g., hashing, encryption)
116120 THashOperation ( HashOperationInstance e ) or
117121 TKeyDerivationOperation ( KeyDerivationOperationInstance e ) or
118- TEncryptionOperation ( EncryptionOperationInstance e ) or
122+ TCipherOperation ( CipherOperationInstance e ) or
119123 TKeyEncapsulationOperation ( KeyEncapsulationOperationInstance e ) or
120124 // Algorithms (e.g., SHA-256, AES)
121125 TEncryptionAlgorithm ( EncryptionAlgorithmInstance e ) or
@@ -238,13 +242,14 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
238242 */
239243 abstract Algorithm getAlgorithm ( ) ;
240244
241- /**
242- * Gets the name of this operation, e.g., "hash" or "encrypt".
243- */
244- abstract string getOperationType ( ) ;
245-
246- final override string getInternalType ( ) { result = this .getOperationType ( ) }
247-
245+ // TODO: I only removed this because I want the operation type to be non-string
246+ // since for CipherOperations the user will have to pick the right type,
247+ // and I want to force them to use a type that is restricted. In this case to a TCipherOperationType
248+ // /**
249+ // * Gets the name of this operation, e.g., "hash" or "encrypt".
250+ // */
251+ // abstract string getOperationType();
252+ // final override string getInternalType() { result = this.getOperationType() }
248253 override NodeBase getChild ( string edgeName ) {
249254 result = super .getChild ( edgeName )
250255 or
@@ -290,8 +295,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
290295 */
291296 abstract class HashOperation extends Operation , THashOperation {
292297 abstract override HashAlgorithm getAlgorithm ( ) ;
293-
294- override string getOperationType ( ) { result = "HashOperation" }
298+ //override string getOperationType() { result = "HashOperation" }
295299 }
296300
297301 newtype THashType =
@@ -401,8 +405,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
401405 final override Location getLocation ( ) {
402406 exists ( LocatableElement le | this = TKeyDerivationOperation ( le ) and result = le .getLocation ( ) )
403407 }
404-
405- override string getOperationType ( ) { result = "KeyDerivationOperation" }
408+ //override string getOperationType() { result = "KeyDerivationOperation" }
406409 }
407410
408411 /**
@@ -681,15 +684,31 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
681684 abstract override string getRawAlgorithmName ( ) ;
682685 }
683686
687+ newtype TCipherOperationMode =
688+ EncryptionMode ( ) or
689+ DecryptionMode ( ) or
690+ UnknownCipherOperationMode ( )
691+
684692 /**
685693 * An encryption operation that processes plaintext to generate a ciphertext.
686694 * This operation takes an input message (plaintext) of arbitrary content and length
687695 * and produces a ciphertext as the output using a specified encryption algorithm (with a mode and padding).
688696 */
689- abstract class EncryptionOperation extends Operation , TEncryptionOperation {
690- override string getOperationType ( ) { result = "EncryptionOperation" }
697+ // NOTE FOR NICK: making this concrete here as I don't think users need to worry about making/extending these operations, just instances
698+ class CipherOperation extends Operation , TCipherOperation {
699+ CipherOperationInstance instance ;
700+
701+ CipherOperation ( ) { this = TCipherOperation ( instance ) }
702+
703+ override Location getLocation ( ) { result = instance .getLocation ( ) }
704+
705+ final TCipherOperationMode getCipherOperationMode ( ) {
706+ result = instance .getCipherOperationMode ( )
707+ }
708+
709+ final override EncryptionAlgorithm getAlgorithm ( ) { result = instance .getAlgorithm ( ) }
691710
692- abstract override EncryptionAlgorithm getAlgorithm ( ) ;
711+ override string getInternalType ( ) { result = "CipherOperation" }
693712 // /**
694713 // * Gets the initialization vector associated with this encryption operation.
695714 // *
0 commit comments