Skip to content

Commit

Permalink
Code review: 321240043: Made Unicode strings the default #204 and upd…
Browse files Browse the repository at this point in the history
…ated docstrings #182
  • Loading branch information
joachimmetz committed Jul 19, 2017
1 parent 3a0fdbc commit 881e154
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 68 deletions.
2 changes: 1 addition & 1 deletion config/dpkg/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ dfvfs (20170719-1) unstable; urgency=low

* Auto-generated

-- Log2Timeline <log2timeline-dev@googlegroups.com> Wed, 19 Jul 2017 17:36:11 +0200
-- Log2Timeline <log2timeline-dev@googlegroups.com> Wed, 19 Jul 2017 17:37:42 +0200
6 changes: 4 additions & 2 deletions dfvfs/credentials/bde_credentials.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
"""The BitLocker Drive Encryption (BDE) credentials."""

from __future__ import unicode_literals

from dfvfs.credentials import credentials
from dfvfs.credentials import manager
from dfvfs.lib import definitions
Expand All @@ -10,11 +12,11 @@


class BDECredentials(credentials.Credentials):
"""Class that implements the BDE credentials."""
"""BDE credentials."""

# TODO: add support for key_data credential, needs pybde update.
CREDENTIALS = frozenset([
u'password', u'recovery_password', u'startup_key'])
'password', 'recovery_password', 'startup_key'])

TYPE_INDICATOR = definitions.TYPE_INDICATOR_BDE

Expand Down
10 changes: 6 additions & 4 deletions dfvfs/credentials/credentials.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# -*- coding: utf-8 -*-
"""The credentials object interface."""
"""The credentials interface."""

from __future__ import unicode_literals


class Credentials(object):
"""Class that implements the credentials object interface."""
"""Credentials interface."""

@property
def type_indicator(self):
"""The type indicator."""
type_indicator = getattr(self, u'TYPE_INDICATOR', None)
type_indicator = getattr(self, 'TYPE_INDICATOR', None)
if type_indicator is None:
raise NotImplementedError(
u'Invalid resolver helper missing type indicator.')
'Invalid resolver helper missing type indicator.')
return type_indicator
6 changes: 4 additions & 2 deletions dfvfs/credentials/encrypted_stream_credentials.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# -*- coding: utf-8 -*-
"""The encrypted stream credentials."""

from __future__ import unicode_literals

from dfvfs.credentials import credentials
from dfvfs.credentials import manager
from dfvfs.lib import definitions


class EncryptedStreamCredentials(credentials.Credentials):
"""Class that implements the encrypted stream credentials."""
"""Encrypted stream credentials."""

CREDENTIALS = frozenset([u'cipher_mode', u'initialization_vector', u'key'])
CREDENTIALS = frozenset(['cipher_mode', 'initialization_vector', 'key'])

TYPE_INDICATOR = definitions.TYPE_INDICATOR_ENCRYPTED_STREAM

Expand Down
6 changes: 4 additions & 2 deletions dfvfs/credentials/fvde_credentials.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
"""The FileVault Drive Encryption (FVDE) credentials."""

from __future__ import unicode_literals

from dfvfs.credentials import credentials
from dfvfs.credentials import manager
from dfvfs.lib import definitions
Expand All @@ -10,11 +12,11 @@


class FVDECredentials(credentials.Credentials):
"""Class that implements the FVDE credentials."""
"""FVDE credentials."""

# TODO: add support for key_data credential, needs pyfvde update.
CREDENTIALS = frozenset([
u'encrypted_root_plist', u'password', u'recovery_password'])
'encrypted_root_plist', 'password', 'recovery_password'])

TYPE_INDICATOR = definitions.TYPE_INDICATOR_FVDE

Expand Down
10 changes: 6 additions & 4 deletions dfvfs/credentials/keychain.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
credential (e.g. password) to access the unencrypted data (unlock).
"""

from __future__ import unicode_literals

from dfvfs.credentials import manager


class KeyChain(object):
"""Class that implements the key chain."""
"""Key chain."""

def __init__(self):
"""Initializes the key chain."""
"""Initializes a key chain."""
super(KeyChain, self).__init__()
self._credentials_per_path_spec = {}

Expand Down Expand Up @@ -76,8 +78,8 @@ def SetCredential(self, path_spec, identifier, data):

if identifier not in supported_credentials.CREDENTIALS:
raise KeyError((
u'Unsuppored credential: {0:s} for path specification type: '
u'{1:s}').format(identifier, path_spec.type_indicator))
'Unsuppored credential: {0:s} for path specification type: '
'{1:s}').format(identifier, path_spec.type_indicator))

credentials = self._credentials_per_path_spec.get(path_spec.comparable, {})
credentials[identifier] = data
Expand Down
12 changes: 7 additions & 5 deletions dfvfs/credentials/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
* key data.
"""

from __future__ import unicode_literals


class CredentialsManager(object):
"""Class that implements the credentials manager."""
"""Credentials manager."""

_credentials = {}

Expand All @@ -25,11 +27,11 @@ def DeregisterCredentials(cls, credentials):
Raises:
KeyError: if credential object is not set for the corresponding
type indicator.
type indicator.
"""
if credentials.type_indicator not in cls._credentials:
raise KeyError(
u'Credential object not set for type indicator: {0:s}.'.format(
'Credential object not set for type indicator: {0:s}.'.format(
credentials.type_indicator))

del cls._credentials[credentials.type_indicator]
Expand Down Expand Up @@ -59,11 +61,11 @@ def RegisterCredentials(cls, credentials):
Raises:
KeyError: if credentials object is already set for the corresponding
type indicator.
type indicator.
"""
if credentials.type_indicator in cls._credentials:
raise KeyError(
u'Credentials object already set for type indicator: {0:s}.'.format(
'Credentials object already set for type indicator: {0:s}.'.format(
credentials.type_indicator))

cls._credentials[credentials.type_indicator] = credentials
8 changes: 5 additions & 3 deletions dfvfs/encoding/base16_decoder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
"""The base16 decoder object implementation."""
"""The base16 decoder implementation."""

from __future__ import unicode_literals

import base64
import binascii
Expand All @@ -11,7 +13,7 @@


class Base16Decoder(decoder.Decoder):
"""Class that implements a base16 decoder using base64."""
"""Base16 decoder using base64."""

ENCODING_METHOD = definitions.ENCODING_METHOD_BASE16

Expand All @@ -31,7 +33,7 @@ def Decode(self, encoded_data):
decoded_data = base64.b16decode(encoded_data, casefold=False)
except (TypeError, binascii.Error) as exception:
raise errors.BackEndError(
u'Unable to decode base16 stream with error: {0!s}.'.format(
'Unable to decode base16 stream with error: {0!s}.'.format(
exception))

return decoded_data, b''
Expand Down
8 changes: 5 additions & 3 deletions dfvfs/encoding/base32_decoder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
"""The base32 decoder object implementation."""
"""The base32 decoder implementation."""

from __future__ import unicode_literals

import base64
import binascii
Expand All @@ -11,7 +13,7 @@


class Base32Decoder(decoder.Decoder):
"""Class that implements a base32 decoder using base64."""
"""Base32 decoder using base64."""

ENCODING_METHOD = definitions.ENCODING_METHOD_BASE32

Expand All @@ -31,7 +33,7 @@ def Decode(self, encoded_data):
decoded_data = base64.b32decode(encoded_data, casefold=False)
except (TypeError, binascii.Error) as exception:
raise errors.BackEndError(
u'Unable to decode base32 stream with error: {0!s}.'.format(
'Unable to decode base32 stream with error: {0!s}.'.format(
exception))

return decoded_data, b''
Expand Down
8 changes: 5 additions & 3 deletions dfvfs/encoding/base64_decoder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
"""The base64 decoder object implementation."""
"""The base64 decoder implementation."""

from __future__ import unicode_literals

import base64
import binascii
Expand All @@ -11,7 +13,7 @@


class Base64Decoder(decoder.Decoder):
"""Class that implements a base64 decoder using base64."""
"""Base64 decoder using base64."""

ENCODING_METHOD = definitions.ENCODING_METHOD_BASE64

Expand All @@ -35,7 +37,7 @@ def Decode(self, encoded_data):
decoded_data = base64.b64decode(encoded_data)
except (TypeError, binascii.Error) as exception:
raise errors.BackEndError(
u'Unable to decode base64 stream with error: {0!s}.'.format(
'Unable to decode base64 stream with error: {0!s}.'.format(
exception))

return decoded_data, b''
Expand Down
6 changes: 4 additions & 2 deletions dfvfs/encoding/decoder.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# -*- coding: utf-8 -*-
"""The decoder object interface."""
"""The decoder interface."""

from __future__ import unicode_literals

import abc


class Decoder(object):
"""Class that implements the decoder object interface."""
"""Decoder interface."""

@abc.abstractmethod
def Decode(self, encoded_data):
Expand Down
8 changes: 5 additions & 3 deletions dfvfs/encoding/manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
"""The encoding manager."""

from __future__ import unicode_literals


class EncodingManager(object):
"""Class that implements the encoding manager."""
"""Encoding manager."""

_decoders = {}

Expand All @@ -20,7 +22,7 @@ def DeregisterDecoder(cls, decoder):
encoding_method = decoder.ENCODING_METHOD.lower()
if encoding_method not in cls._decoders:
raise KeyError(
u'Decoder for encoding method: {0:s} not set.'.format(
'Decoder for encoding method: {0:s} not set.'.format(
decoder.ENCODING_METHOD))

del cls._decoders[encoding_method]
Expand Down Expand Up @@ -55,7 +57,7 @@ def RegisterDecoder(cls, decoder):
encoding_method = decoder.ENCODING_METHOD.lower()
if encoding_method in cls._decoders:
raise KeyError(
u'Decoder for encoding method: {0:s} already set.'.format(
'Decoder for encoding method: {0:s} already set.'.format(
decoder.ENCODING_METHOD))

cls._decoders[encoding_method] = decoder
Expand Down
16 changes: 9 additions & 7 deletions dfvfs/encryption/aes_decrypter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
"""The AES decrypter object implementation."""
"""The AES decrypter implementation."""

from __future__ import unicode_literals

from Crypto.Cipher import AES

Expand All @@ -9,7 +11,7 @@


class AESDecrypter(decrypter.Decrypter):
"""Class that implements a AES decrypter using pycrypto."""
"""AES decrypter using pycrypto."""

ENCRYPTION_METHOD = definitions.ENCRYPTION_METHOD_AES

Expand All @@ -21,7 +23,7 @@ class AESDecrypter(decrypter.Decrypter):

def __init__(
self, cipher_mode=None, initialization_vector=None, key=None, **kwargs):
"""Initializes the decrypter object.
"""Initializes a decrypter.
Args:
cipher_mode (Optional[str]): cipher mode.
Expand All @@ -31,19 +33,19 @@ def __init__(
Raises:
ValueError: when key is not set, block cipher mode is not supported,
or initialization_vector is required and not set.
or initialization_vector is required and not set.
"""
if not key:
raise ValueError(u'Missing key.')
raise ValueError('Missing key.')

cipher_mode = self.ENCRYPTION_MODES.get(cipher_mode, None)
if cipher_mode is None:
raise ValueError(u'Unsupported cipher mode: {0!s}'.format(cipher_mode))
raise ValueError('Unsupported cipher mode: {0!s}'.format(cipher_mode))

if cipher_mode != AES.MODE_ECB and not initialization_vector:
# Pycrypto does not create a meaningful error when initialization vector
# is missing. Therefore, we report it ourselves.
raise ValueError(u'Missing initialization vector.')
raise ValueError('Missing initialization vector.')

super(AESDecrypter, self).__init__()
if cipher_mode == AES.MODE_ECB:
Expand Down
16 changes: 9 additions & 7 deletions dfvfs/encryption/blowfish_decrypter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
"""The Blowfish decrypter object implementation."""
"""The Blowfish decrypter implementation."""

from __future__ import unicode_literals

from Crypto.Cipher import Blowfish

Expand All @@ -9,7 +11,7 @@


class BlowfishDecrypter(decrypter.Decrypter):
"""Class that implements a Blowfish decrypter using pycrypto."""
"""Blowfish decrypter using pycrypto."""

ENCRYPTION_METHOD = definitions.ENCRYPTION_METHOD_BLOWFISH

Expand All @@ -21,7 +23,7 @@ class BlowfishDecrypter(decrypter.Decrypter):

def __init__(
self, cipher_mode=None, initialization_vector=None, key=None, **kwargs):
"""Initializes the decrypter object.
"""Initializes a decrypter.
Args:
cipher_mode (Optional[str]): cipher mode.
Expand All @@ -31,19 +33,19 @@ def __init__(
Raises:
ValueError: when key is not set, block cipher mode is not supported,
or initialization_vector is required and not set.
or initialization_vector is required and not set.
"""
if not key:
raise ValueError(u'Missing key.')
raise ValueError('Missing key.')

cipher_mode = self.ENCRYPTION_MODES.get(cipher_mode, None)
if cipher_mode is None:
raise ValueError(u'Unsupported cipher mode: {0!s}'.format(cipher_mode))
raise ValueError('Unsupported cipher mode: {0!s}'.format(cipher_mode))

if cipher_mode != Blowfish.MODE_ECB and not initialization_vector:
# Pycrypto does not create a meaningful error when initialization vector
# is missing. Therefore, we report it ourselves.
raise ValueError(u'Missing initialization vector.')
raise ValueError('Missing initialization vector.')

super(BlowfishDecrypter, self).__init__()
if cipher_mode == Blowfish.MODE_ECB:
Expand Down
Loading

0 comments on commit 881e154

Please sign in to comment.