Added tpm2-parse-error script

Added tpm2-parse-error script to parse the give error code.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
diff --git a/tpm2-parse-error b/tpm2-parse-error
new file mode 100755
index 0000000..59b1564
--- /dev/null
+++ b/tpm2-parse-error
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+from argparse import ArgumentParser
+from argparse import FileType
+import os
+import sys
+import tpm2
+
+
+def main():
+    parser = ArgumentParser(description='Parse a TPM error code')
+    parser.add_argument('rc', type=(lambda x: int(x, 0)))
+    args = parser.parse_args()
+
+    pe = tpm2.ProtocolError(None, args.rc)
+    print str(pe)
+
+if __name__ == '__main__':
+    main()
diff --git a/tpm2.py b/tpm2.py
index e64c658..ced8b84 100644
--- a/tpm2.py
+++ b/tpm2.py
@@ -214,10 +214,9 @@
 
 
 class ProtocolError(Exception):
-    def __init__(self, cc, rc, rsp):
+    def __init__(self, cc, rc):
         self.cc = cc
         self.rc = rc
-        self.rsp = rsp
 
         if (rc & RC_FMT1) == RC_FMT1:
             self.name = TPM2_FMT1_ERRORS.get(rc & 0x3f, "TPM_RC_UNKNOWN")
@@ -229,7 +228,10 @@
             self.name = TPM2_VER0_ERRORS.get(rc & 0x7f, "TPM_RC_UNKNOWN")
 
     def __str__(self):
-        return '%s: cc=0x%08x, rc=0x%08x' % (self.name, self.cc, self.rc)
+        if self.cc:
+            return '%s: cc=0x%08x, rc=0x%08x' % (self.name, self.cc, self.rc)
+        else:
+            return '%s: rc=0x%08x' % (self.name, self.rc)
 
 
 class AuthCommand(object):
@@ -431,7 +433,7 @@
         rc = struct.unpack('>I', rsp[6:10])[0]
         if rc != 0:
             cc = struct.unpack('>I', cmd[6:10])[0]
-            raise ProtocolError(cc, rc, rsp)
+            raise ProtocolError(cc, rc)
 
         return rsp