File: decrypter.py

package info (click to toggle)
dfvfs 20201219-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 284,900 kB
  • sloc: python: 30,025; vhdl: 1,921; sh: 465; makefile: 16
file content (64 lines) | stat: -rw-r--r-- 2,118 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for the RC4 decrypter object."""

from __future__ import unicode_literals

import unittest

from cryptography.hazmat.primitives.ciphers import algorithms

from dfvfs.encryption import decrypter
from dfvfs.lib import definitions

from tests.encryption import test_lib


class DecrypterTestCase(test_lib.DecrypterTestCase):
  """Tests for the decrypter interface."""

  def testInitialize(self):
    """Tests the __init__ method."""
    test_decrypter = decrypter.Decrypter()
    self.assertIsNotNone(test_decrypter)

    with self.assertRaises(ValueError):
      decrypter.Decrypter(key=b'test1')


class CryptographyBlockCipherDecrypterTest(test_lib.DecrypterTestCase):
  """Tests for the block cipher decrypter using Cryptography."""

  _DES3_INITIALIZATION_VECTOR = b'This IV!'
  _DES3_KEY = b'This is a key123'

  def testInitialize(self):
    """Tests the __init__ method."""
    algorithm = algorithms.TripleDES(self._DES3_KEY)

    test_decrypter = decrypter.CryptographyBlockCipherDecrypter(
        algorithm=algorithm, cipher_mode=definitions.ENCRYPTION_MODE_CBC,
        initialization_vector=self._DES3_INITIALIZATION_VECTOR)
    self.assertIsNotNone(test_decrypter)

    test_decrypter = decrypter.CryptographyBlockCipherDecrypter(
        algorithm=algorithm, cipher_mode=definitions.ENCRYPTION_MODE_CFB,
        initialization_vector=self._DES3_INITIALIZATION_VECTOR)
    self.assertIsNotNone(test_decrypter)

    test_decrypter = decrypter.CryptographyBlockCipherDecrypter(
        algorithm=algorithm, cipher_mode=definitions.ENCRYPTION_MODE_ECB)
    self.assertIsNotNone(test_decrypter)

    test_decrypter = decrypter.CryptographyBlockCipherDecrypter(
        algorithm=algorithm, cipher_mode=definitions.ENCRYPTION_MODE_OFB,
        initialization_vector=self._DES3_INITIALIZATION_VECTOR)
    self.assertIsNotNone(test_decrypter)

    with self.assertRaises(ValueError):
      decrypter.CryptographyBlockCipherDecrypter(
          algorithm=algorithm, cipher_mode=definitions.ENCRYPTION_MODE_CBC)


if __name__ == '__main__':
  unittest.main()