diff options
author | Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> | 2016-09-03 22:24:23 +0300 |
---|---|---|
committer | Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> | 2016-09-05 12:12:43 +0300 |
commit | 7b7cf25c583398c8679bdfc149956f438288883a (patch) | |
tree | 185b0e1340f1ed29d7326fa09f97772a78d39b95 | |
parent | 35481c326b739c4000a03d0d4e800740e1b6c05f (diff) | |
download | tpm2-scripts-7b7cf25c583398c8679bdfc149956f438288883a.tar.gz |
Open /dev/tpm0 only once in the life-cycle of a Client object
Moved opening of the Client object to __init__ so that it can be used
with an in-kernel resource manager sessions.
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
-rw-r--r-- | tpm2.py | 10 | ||||
-rwxr-xr-x | tpm2_smoke.py | 1 |
2 files changed, 7 insertions, 4 deletions
@@ -461,15 +461,17 @@ class Client: def __init__(self, flags = 0, simulator = None): self.flags = flags self.simulator = simulator + self.tpm = open('/dev/tpm0', 'r+b') + + def close(self): + self.tpm.close() def send_cmd(self, cmd): if self.simulator: rsp = self.simulator.send_cmd(cmd) else: - f = open('/dev/tpm0', 'r+b') - f.write(cmd) - rsp = f.read() - f.close() + self.tpm.write(cmd) + rsp = self.tpm.read() if (self.flags & Client.FLAG_DEBUG) != 0: sys.stderr.write('cmd' + os.linesep) diff --git a/tpm2_smoke.py b/tpm2_smoke.py index 80bb4aa..500a230 100755 --- a/tpm2_smoke.py +++ b/tpm2_smoke.py @@ -41,6 +41,7 @@ class SmokeTest(unittest.TestCase): def tearDown(self): self.client.flush_context(self.root_key) + self.client.close() def test_seal_with_auth(self): data = 'X' * 64 |