Browse Source

renumber hash/mac numbers, automate defaults in help

note: maybe we add the full (not truncated) sha512 hash and hmac-sha512, keep the numbers free.
Thomas Waldmann 10 years ago
parent
commit
b53a620602
2 changed files with 12 additions and 12 deletions
  1. 8 8
      attic/archiver.py
  2. 4 4
      attic/key.py

+ 8 - 8
attic/archiver.py

@@ -13,7 +13,7 @@ from attic import __version__
 from attic.archive import Archive, ArchiveChecker
 from attic.archive import Archive, ArchiveChecker
 from attic.repository import Repository
 from attic.repository import Repository
 from attic.cache import Cache
 from attic.cache import Cache
-from attic.key import key_creator, COMPR_DEFAULT
+from attic.key import key_creator, COMPR_DEFAULT, HASH_DEFAULT, MAC_DEFAULT
 from attic.helpers import Error, location_validator, format_time, \
 from attic.helpers import Error, location_validator, format_time, \
     format_file_mode, ExcludePattern, exclude_path, adjust_patterns, to_localtime, \
     format_file_mode, ExcludePattern, exclude_path, adjust_patterns, to_localtime, \
     get_cache_dir, get_keys_dir, format_timedelta, prune_within, prune_split, \
     get_cache_dir, get_keys_dir, format_timedelta, prune_within, prune_split, \
@@ -466,18 +466,18 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
         Encryption can be enabled, compression and mac method can be chosen at
         Encryption can be enabled, compression and mac method can be chosen at
         repository init time.
         repository init time.
 
 
-        --compression METHODs (default: zlib level 6):
+        --compression METHODs (default: %02d):
 
 
         - 00..09  zlib levels 0..9 (0 means no compression, 9 max. compression)
         - 00..09  zlib levels 0..9 (0 means no compression, 9 max. compression)
         - 10..19  lzma levels 0..9 (0 means no compression, 9 max. compression)
         - 10..19  lzma levels 0..9 (0 means no compression, 9 max. compression)
 
 
-        --mac METHODs (default: sha256 or hmac-sha256):
+        --mac METHODs (default: %02d or %02d):
 
 
-        - 0       sha256 (just simple hash, no MAC, faster on 32bit CPU)
-        - 1       sha512-256 (just simple hash, no MAC, faster on 64bit CPU)
-        - 2       hmac-sha256 (HMAC, faster on 32bit CPU)
-        - 3       hmac-sha512-256 (HMAC, faster on 64bit CPU)
-        """)
+        - 00      sha256 (just simple hash, no MAC, faster on 32bit CPU)
+        - 01      sha512-256 (just simple hash, no MAC, faster on 64bit CPU)
+        - 10      hmac-sha256 (HMAC, faster on 32bit CPU)
+        - 11      hmac-sha512-256 (HMAC, faster on 64bit CPU)
+        """ % (COMPR_DEFAULT, HASH_DEFAULT, MAC_DEFAULT))
         subparser = subparsers.add_parser('init', parents=[common_parser],
         subparser = subparsers.add_parser('init', parents=[common_parser],
                                           description=self.do_init.__doc__, epilog=init_epilog,
                                           description=self.do_init.__doc__, epilog=init_epilog,
                                           formatter_class=argparse.RawDescriptionHelpFormatter)
                                           formatter_class=argparse.RawDescriptionHelpFormatter)

+ 4 - 4
attic/key.py

@@ -64,7 +64,7 @@ class HMAC(hmac.HMAC):
 
 
 
 
 class SHA256(object):  # note: can't subclass sha256
 class SHA256(object):  # note: can't subclass sha256
-    TYPE = 0x00
+    TYPE = 0
 
 
     def __init__(self, key, data=b''):
     def __init__(self, key, data=b''):
         # signature is like for a MAC, we ignore the key as this is a simple hash
         # signature is like for a MAC, we ignore the key as this is a simple hash
@@ -84,7 +84,7 @@ class SHA256(object):  # note: can't subclass sha256
 
 
 class SHA512_256(sha512_256):
 class SHA512_256(sha512_256):
     """sha512, but digest truncated to 256bit - faster than sha256 on 64bit platforms"""
     """sha512, but digest truncated to 256bit - faster than sha256 on 64bit platforms"""
-    TYPE = 0x01
+    TYPE = 1
 
 
     def __init__(self, key, data):
     def __init__(self, key, data):
         # signature is like for a MAC, we ignore the key as this is a simple hash
         # signature is like for a MAC, we ignore the key as this is a simple hash
@@ -97,7 +97,7 @@ HASH_DEFAULT = SHA256.TYPE
 
 
 
 
 class HMAC_SHA256(HMAC):
 class HMAC_SHA256(HMAC):
-    TYPE = 0x02
+    TYPE = 10
 
 
     def __init__(self, key, data):
     def __init__(self, key, data):
         if key is None:
         if key is None:
@@ -106,7 +106,7 @@ class HMAC_SHA256(HMAC):
 
 
 
 
 class HMAC_SHA512_256(HMAC):
 class HMAC_SHA512_256(HMAC):
-    TYPE = 0x03
+    TYPE = 11
 
 
     def __init__(self, key, data):
     def __init__(self, key, data):
         if key is None:
         if key is None: