viff

changeset 1425:efa1983063d6

Orlandi: Better error messages when the pypaillier or commitment modules are not installed.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Thu, 14 Jan 2010 11:36:13 +0100
parents 681b1a6760ff
children 0cae74c348e8 2324d01c74e2 0164b895d948
files apps/benchmark.py viff/orlandi.py viff/test/test_orlandi_runtime.py
diffstat 3 files changed, 52 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- a/apps/benchmark.py	Mon Dec 14 17:02:00 2009 +0100
     1.2 +++ b/apps/benchmark.py	Thu Jan 14 11:36:13 2010 +0100
     1.3 @@ -70,10 +70,25 @@
     1.4  from viff.comparison import ComparisonToft05Mixin, ComparisonToft07Mixin
     1.5  from viff.equality import ProbabilisticEqualityMixin
     1.6  from viff.paillier import PaillierRuntime
     1.7 -from viff.orlandi import OrlandiRuntime
     1.8  from viff.config import load_config
     1.9  from viff.util import find_prime
    1.10  
    1.11 +try:
    1.12 +    import commitment  
    1.13 +except ImportError:
    1.14 +    commitment = None
    1.15 +
    1.16 +try:
    1.17 +    from pypaillier import encrypt_r, decrypt, tripple_2c, tripple_3a
    1.18 +except:
    1.19 +    pypaillier = None
    1.20 +
    1.21 +if commitment and pypaillier:
    1.22 +    from viff.orlandi import OrlandiRuntime
    1.23 +else:
    1.24 +    OrlandiRuntime = None
    1.25 +    OrlandiShare = None
    1.26 +
    1.27  from benchutil import (SelfcontainedBenchmarkStrategy,
    1.28                         NeededDataBenchmarkStrategy,
    1.29                         ParallelBenchmark, SequentialBenchmark,
    1.30 @@ -180,6 +195,15 @@
    1.31  
    1.32  
    1.33  # Identify the base runtime class.
    1.34 +if options.runtime == "OrlandiRuntime" and not OrlandiRuntime:
    1.35 +    print "Error: The following modules did not load correctly:"
    1.36 +    if not commitment:
    1.37 +        print "commitment"
    1.38 +    if not pypaillier:
    1.39 +        print "pypaillier"
    1.40 +    if not OrlandiRuntime:
    1.41 +        print "OrlandiRuntime"
    1.42 +    exit(1)
    1.43  base_runtime_class = runtimes[options.runtime]
    1.44  
    1.45  # Identify the additional mixins.
     2.1 --- a/viff/orlandi.py	Mon Dec 14 17:02:00 2009 +0100
     2.2 +++ b/viff/orlandi.py	Thu Jan 14 11:36:13 2010 +0100
     2.3 @@ -37,6 +37,13 @@
     2.4  
     2.5  try:
     2.6      from pypaillier import encrypt_r, decrypt, tripple_2c, tripple_3a
     2.7 +
     2.8 +except ImportError:
     2.9 +    # The pypaillier module is not released yet, so we cannot expect
    2.10 +    # the import to work.
    2.11 +    print "Error: The pypaillier module or one of the used functions are not available."
    2.12 +
    2.13 +try:
    2.14      import commitment
    2.15      commitment.set_reference_string(23434347834783478783478L,
    2.16                                      489237823478234783478020L)
    2.17 @@ -45,10 +52,7 @@
    2.18      # import to work. Catching the ImportError here allows the
    2.19      # benchmark and tests to import viff.orlandi without blowing up.
    2.20      # It is only if the OrlandiRuntime is used that things blow up.
    2.21 -
    2.22 -    # The pypaillier module is not released yet, so we cannot expect
    2.23 -    # the import to work.
    2.24 -    from viff.paillier import encrypt_r, decrypt
    2.25 +    print "Error: The commitment module is not available."
    2.26  
    2.27  # import logging
    2.28  # LOG_FILENAME = 'logging_example.out'
     3.1 --- a/viff/test/test_orlandi_runtime.py	Mon Dec 14 17:02:00 2009 +0100
     3.2 +++ b/viff/test/test_orlandi_runtime.py	Thu Jan 14 11:36:13 2010 +0100
     3.3 @@ -23,8 +23,15 @@
     3.4  from viff.config import generate_configs
     3.5  
     3.6  try:
     3.7 -    from viff.orlandi import OrlandiRuntime, OrlandiShare
     3.8 -    import commitment
     3.9 +    import commitment  
    3.10 +    try:
    3.11 +        from pypaillier import encrypt_r, decrypt, tripple_2c, tripple_3a
    3.12 +        from viff.orlandi import OrlandiRuntime, OrlandiShare
    3.13 +    except ImportError:
    3.14 +        pypaillier = None
    3.15 +        OrlandiRuntime = None
    3.16 +        OrlandiShare = None
    3.17 +
    3.18  except ImportError:
    3.19      commitment = None
    3.20      OrlandiRuntime = None
    3.21 @@ -852,7 +859,14 @@
    3.22          runtime.schedule_callback(shares_ready, cont)
    3.23          return shares_ready
    3.24  
    3.25 +
    3.26 +def skip_tests(module_name):
    3.27 +    OrlandiAdvancedCommandsTest.skip = "Skipped due to missing " + module_name + " module."
    3.28 +    OrlandiBasicCommandsTest.skip = "Skipped due to missing " + module_name + " module."
    3.29 +    TripleGenTest.skip = "Skipped due to missing " + module_name + " module."
    3.30 +
    3.31  if not commitment:
    3.32 -    OrlandiAdvancedCommandsTest.skip = "Skipped due to missing commitment module."
    3.33 -    OrlandiBasicCommandsTest.skip = "Skipped due to missing commitment module."
    3.34 -    TripleGenTest.skip = "Skipped due to missing commitment module."
    3.35 +    skip_tests("commitment")
    3.36 +
    3.37 +if not pypaillier:
    3.38 +    skip_tests("pypaillier")