def open(self, pPasswordList): if self.isOpen(): print("Warning: Open attempted on an open vault.") return -1 pRecoveredList = self.vault.recover(pPasswordList) if -1 not in pRecoveredList: return -1 # lclPivot = pRecoveredList.getByIdentifier(-1) # if lclPivot == -1: # return -1 lclPivotPassword = pRecoveredList[-1] self.vault = PivotedVault(self.vault, lclPivotPassword) return 0
def test_FullFunctionality(self): print("Running the FullFunctionality test for the TestPivotedVault.") self.data = Definitions() print("Variables defined.") vault = PivotedVault() print("1:" + vault.toString()) vault.addOutput(self.data.lclpwd6) print("2:" + vault.toString()) vault.addOutput(self.data.lclpwd5) print("3:" + vault.toString()) vault.addInputList(self.data.passwordListA1) print("4:" + vault.toString()) vault.addInputList(self.data.passwordListA2) print("5:" + vault.toString()) vault.addInputList(self.data.passwordListA3) print("6:" + vault.toString()) vault.addInputList(self.data.passwordListA4) print("7:" + vault.toString()) vault.removeOutput(self.data.lclpwd5) print("8:" + vault.toString()) vault.removeOutput(self.data.lclpwd2) print("9:" + vault.toString()) vault.removeInputList(self.data.passwordListA1) print("10:" + vault.toString()) vault.removeInputList(self.data.passwordListA1) print("11:" + vault.toString())
class OpenableVault(object): ''' classdocs ''' def __init__(self, pVault = None): ''' Constructor ''' # The vault is closed if pVault is a SimpleVault if pVault is None: pVault = PivotedVault() # if pPasswordList is None: # pPasswordList = PasswordList() self.vault = pVault def getVaultForSaving(self): return self.vault.getVaultForSaving() def isOpen(self): if isinstance(self.vault, PivotedVault): return True return False def open(self, pPasswordList): if self.isOpen(): print("Warning: Open attempted on an open vault.") return -1 pRecoveredList = self.vault.recover(pPasswordList) if -1 not in pRecoveredList: return -1 # lclPivot = pRecoveredList.getByIdentifier(-1) # if lclPivot == -1: # return -1 lclPivotPassword = pRecoveredList[-1] self.vault = PivotedVault(self.vault, lclPivotPassword) return 0 def getVault(self): return self.vault def addPassword(self, pPasswordTuple): # if not isinstance(pPasswordTuple, PasswordTuple): # raise TypeError("Argument passed into append function for PasswordList is not a PasswordTuple.") if not self.isOpen(): return -1 self.vault.addOutput(pPasswordTuple) def removePassword(self, pPasswordTuple): # if not isinstance(pPasswordTuple, PasswordTuple): # raise TypeError("Argument passed into append function for PasswordList is not a PasswordTuple.") if not self.isOpen(): return -1 self.vault.removeOutput(pPasswordTuple) def addInput(self, pInputList): # if not isinstance(pInputList, PasswordList): # raise TypeError("Argument passed into append function for PasswordList is not a PasswordList.") if not self.isOpen(): return -1 self.vault.addInputList(pInputList) return 0 def addInputListAndPasswords(self, pInputList): self.addInput(pInputList) for i in pInputList: self.addPassword(i) return def removeInput(self, pInputList): # if not isinstance(pInputList, PasswordList): # raise TypeError("Argument passed into append function for PasswordList is not a PasswordList.") if not self.isOpen(): return -1 self.vault.removeInputList(pInputList) return 0 def toString(self): return self.vault.toString() def createPickledVault(self): return self.vault.createPickledVault()