Skip to content

Commit

Permalink
Added encipher & decipher methods
Browse files Browse the repository at this point in the history
  • Loading branch information
emcconville committed Aug 20, 2020
1 parent 0e3124e commit a849c0d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changes.rst
Expand Up @@ -16,6 +16,7 @@ Unreleased.

- Added :meth:`Image.data_url() <wand.image.Image.data_url>` method. [:issue:`489`]
- Added :attr:`Image.sampling_factors <wand.image.BaseImage.sampling_factors>` property. [:issue:`491`]
- Added :meth:`Image.encipher() <wand.image.BaseImage.encipher>` & :meth:`Image.decipher() <wand.image.BaseImage.decipher>` methods.
- Uniformed additional pre-read parameters between :meth:`Image.__init__()` & :meth:`Image.read()`.


Expand Down
10 changes: 10 additions & 0 deletions tests/image_methods_test.py
Expand Up @@ -733,6 +733,16 @@ def test_emboss(fx_asset):
assert was != img.signature


def test_encipher_decipher():
with Image(filename='rose:') as img:
img.depth = 8 # Safety
was = img.signature
img.encipher(passphrase='secret')
assert was != img.signature
img.decipher(passphrase='secret')
assert was == img.signature


def test_enhance(fx_asset):
with Image(filename='rose:') as img:
was = img.signature
Expand Down
36 changes: 36 additions & 0 deletions wand/image.py
Expand Up @@ -4190,6 +4190,24 @@ def cycle_color_map(self, offset=1):
assertions.assert_integer(offset=offset)
return library.MagickCycleColormapImage(self.wand, offset)

@manipulative
@trap_exception
def decipher(self, passphrase):
"""Decrypt ciphered pixels into original values.
.. note::
:class:`~wand.exceptions.ImageError` will be thrown if the system's
ImageMagick library was compiled without cipher support.
:param passphrase: the secret passphrase to decrypt with.
:type passphrase: :class:`basestring`
.. versionadded:: 0.6.3
"""
assertions.assert_string(passphrase=passphrase)
return library.MagickDecipherImage(self.wand, binary(passphrase))

@manipulative
@trap_exception
def deconstruct(self):
Expand Down Expand Up @@ -4330,6 +4348,24 @@ def emboss(self, radius=0.0, sigma=0.0):
assertions.assert_real(radius=radius, sigma=sigma)
return library.MagickEmbossImage(self.wand, radius, sigma)

@manipulative
@trap_exception
def encipher(self, passphrase):
"""Encrypt plain pixels into ciphered values.
.. note::
:class:`~wand.exceptions.ImageError` will be thrown if the system's
ImageMagick library was compiled without cipher support.
:param passphrase: the secret passphrase to encrypt with.
:type passphrase: :class:`basestring`
.. versionadded:: 0.6.3
"""
assertions.assert_string(passphrase=passphrase)
return library.MagickDecipherImage(self.wand, binary(passphrase))

@manipulative
@trap_exception
def enhance(self):
Expand Down

0 comments on commit a849c0d

Please sign in to comment.