def cleanSlots()

in cvm-attestation/tpm_wrapper.py [0:0]


  def cleanSlots(self, tpm, slotType):
      caps = tpm.GetCapability(TPM_CAP.HANDLES, slotType << 24, 8)
      handles = caps.capabilityData

      if len(handles.handle) == 0:
        self.log.info("No dangling {slotType} handles")
      else:
        for h in handles.handle:
          self.log.info(f"Dangling {slotType} handle {hex(h.handle)}")
          if slotType == TPM_HT.PERSISTENT:
            tpm.allowErrors().EvictControl(TPM_HANDLE.OWNER, h, h)
            if tpm.lastResponseCode not in [TPM_RC.SUCCESS, TPM_RC.HIERARCHY]:
              raise(tpm.lastError)
          else:
              tpm.FlushContext(h)