Skip to content

patch #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name='smime',
version=__import__('smime').__version__,
version='0.0.6',
description='Python S/MIME Toolkit',
long_description=long_description,
url='https://github.com/balena/python-smime',
Expand Down
3 changes: 1 addition & 2 deletions smime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

__author__ = 'G. B. Versiani'
__license__ = 'Apache License (2.0)'
__version__ = '0.0.4'

__all__ = [__author__, __license__, __version__]
__all__ = [__author__, __license__]

from .encrypt import encrypt
8 changes: 5 additions & 3 deletions smime/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,22 @@ def session_key(self):

def encrypt(self, data):
padded_data = self._pad(data, self.block_size)
encrypted_content = self._encryptor.update(padded_data.encode('utf-8')) + self._encryptor.finalize()
if not isinstance(padded_data, bytes):
padded_data = padded_data.encode()
encrypted_content = self._encryptor.update(padded_data) + self._encryptor.finalize()
return {
'content_type': 'data',
'content_encryption_algorithm': {
'algorithm': self.algorithm,
'parameters': self._iv
'parameters': self._iv,
},
'encrypted_content': encrypted_content
}

@staticmethod
def _pad(s, block_size):
n = block_size - len(s) % block_size
return s + n * chr(n)
return s + n * (chr(n) if isinstance(s, str) else bytes([n]))

@property
def parameters(self):
Expand Down