changeset 157:cba610df903a

secret_annotator: now secret_expr can find a default set of secret vars. It uses parent pointers to find an enclosing statement, and uses the in_values of that.
author Sigurd Meldgaard <stm@daimi.au.dk>
date Fri, 04 Dec 2009 11:25:07 +0100
parents c5d3949639f5
children db7a0ad210df
files pysmcl/secret_annotator.py
diffstat 1 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/secret_annotator.py	Fri Dec 04 10:51:30 2009 +0100
+++ b/pysmcl/secret_annotator.py	Fri Dec 04 11:25:07 2009 +0100
@@ -10,11 +10,18 @@
 
 secret_functions = set(["get"])
 
-def expr_secret(exp, secret_variables):
+analysis_key = "secret"
+
+def expr_secret(exp, secret_variables = None):
     """
     Returns True if the expression exp should be considered secret
-    given that the variables in *secret_variables* are secret.
+    given that the variables in *secret_variables* are secret.  If
+    *secret_variables* is None, it is assumed to be the *in_values* of
+    the parent statement.
     """
+    if(secret_variables is None):
+        secret_variables = ast.get_ancestor(exp, ast.stmt).in_values[analysis_key]
+
     if(isinstance(exp, ast.BoolOp)):
         return (expr_secret(exp.values[0], secret_variables)
                  or expr_secret(exp.values[1], secret_variables))
@@ -52,7 +59,7 @@
     """This is a may-analysis, so take the union"""
     r = set()
     for i in in_nodes:
-        r|=i.out_values["secret"]
+        r|=i.out_values[analysis_key]
     return r
 
 
@@ -89,4 +96,4 @@
     arguments = set(i.id for i in function.args.args)
     function.body[0].imported_secrets = arguments
     pysmcl.flow.analyze(function, secret_join,
-                        secret_combine, "secret", set())
+                        secret_combine, analysis_key, set())