From 6a29ca187a22012a984808d76caaa339c85c5616 Mon Sep 17 00:00:00 2001 From: nagendra modadugu Date: Thu, 17 Dec 2015 10:32:11 -0800 Subject: Refactor crypto subcommands into their own python module. BRANCH=none TEST=tpmtest.py passes BUG=chrome-os-partner:43025,chrome-os-partner:47524 Signed-off-by: nagendra modadugu Change-Id: I48f426176f17c57c723104d19c963b228f16d985 Reviewed-on: https://chromium-review.googlesource.com/318915 Commit-Ready: Nagendra Modadugu Tested-by: Nagendra Modadugu Reviewed-by: Vadim Bendebury --- test/tpm_test/crypto_test.py | 6 ++---- test/tpm_test/hash_test.py | 5 ++--- test/tpm_test/subcmd.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 test/tpm_test/subcmd.py (limited to 'test') diff --git a/test/tpm_test/crypto_test.py b/test/tpm_test/crypto_test.py index 147b5f301b..7fa4ea6146 100644 --- a/test/tpm_test/crypto_test.py +++ b/test/tpm_test/crypto_test.py @@ -10,11 +10,9 @@ from __future__ import print_function import struct import xml.etree.ElementTree as ET +import subcmd import utils -# Extension 'cryptography' subcommand codes: -AES = 0 - # Basic crypto operations DECRYPT = 0 ENCRYPT = 1 @@ -99,7 +97,7 @@ class CryptoD(object): self.submodes = submodes SUPPORTED_MODES = { - 'AES': CryptoD(AES, { + 'AES': CryptoD(subcmd.AES, { 'ECB': 0, 'CTR': 1, 'CBC': 2, diff --git a/test/tpm_test/hash_test.py b/test/tpm_test/hash_test.py index c1cdddbbe5..fd8d0f4184 100644 --- a/test/tpm_test/hash_test.py +++ b/test/tpm_test/hash_test.py @@ -10,10 +10,9 @@ from __future__ import print_function import hashlib import struct +import subcmd import utils -HASH = 1 - # Hash command modes CMD_START = 0 CMD_CONT = 1 @@ -92,7 +91,7 @@ def hash_test(tpm): cmd += '%c' % handle # Ignored for single shots cmd += struct.pack('>H', len(text)) cmd += text - wrapped_response = tpm.command(tpm.wrap_ext_command(HASH, cmd)) + wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.HASH, cmd)) if hash_cmd in (CMD_START, CMD_CONT): if hash_cmd == CMD_START: contexts[handle] = hash_func() diff --git a/test/tpm_test/subcmd.py b/test/tpm_test/subcmd.py new file mode 100644 index 0000000000..dbfcadb1c5 --- /dev/null +++ b/test/tpm_test/subcmd.py @@ -0,0 +1,10 @@ +#!/usr/bin/python +# Copyright 2015 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Subcommand codes that specify the crypto module.""" + +# Keep these codes in sync with include/extension.h. +AES = 0 +HASH = 1 -- cgit v1.2.1