import re
import operator
-from . import aescrypto
+#from . import aescrypto
+from . import crypto
try:
import grp, pwd
"size": int
}
+VALID_ENCRYPTION_MODES = [ "aes" ]
+
#---------------------------------------------------------
# initialization
#---------------------------------------------------------
class SubsequentHeaderError(HeaderError):
"""Exception for missing and invalid extended headers."""
pass
+class InvalidEncryptionError(TarError):
+ """Exception for undefined crypto modes and combinations."""
+ pass
#---------------------------
# internal stream interface
def tell(self):
return self.offset
+
class _Stream:
"""Class that serves as an adapter between TarFile and
a stream-like object. The stream-like object only
self.bytes_written = 0
try:
+ if enctype != "" and enctype not in VALID_ENCRYPTION_MODES:
+ raise InvalidEncryptionError("unsupported encryption mode %r"
+ % enctype)
if comptype == "gz":
try:
import zlib
self.zlib = zlib
if mode == "r":
if self.enctype == 'aes':
- self.encryption = aescrypto.AESCrypt(self.password,
- key_length=self.key_length)
+ self.encryption = crypto.AES_GCM_context(self.password,
+ key_length=self.key_length)
self._init_read_gz()
self.exception = zlib.error
else:
self.crc = zlib.crc32(b"") & 0xFFFFffff
elif comptype == "bz2":
+ if self.enctype != "":
+ raise InvalidEncryptionError("encryption mode %r not "
+ "available for compression %s"
+ % (enctype, comptype))
try:
import bz2
except ImportError:
self.cmp = bz2.BZ2Compressor()
elif comptype == 'xz':
+ if self.enctype != "":
+ raise InvalidEncryptionError("encryption mode %r not "
+ "available for compression %s"
+ % (enctype, comptype))
try:
import lzma
except ImportError:
self.__write_to_file(self.encryption.salt_str)
elif comptype != "tar":
+ if self.enctype != "":
+ raise InvalidEncryptionError("encryption mode %r not "
+ "available for compression %s"
+ % (enctype, comptype))
raise CompressionError("unknown compression type %r" % comptype)
except: