• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Synss / python-mbedtls / 8002749462

22 Feb 2024 10:07AM CUT coverage: 88.482%. First build
8002749462

push

github

Synss
pk: Track cipher content internally

mbedtls-3.x

2704 of 3056 relevant lines covered (88.48%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/src/mbedtls/cipher/DES.py
1
# SPDX-License-Identifier: MIT
2
# Copyright (c) 2016, Elaborated Networks GmbH
3
# Copyright (c) 2019, Mathias Laurin
4

5
"""Data Encryption Standard (DES) cipher developed by IBM
1✔
6
in the 70's."""
7

8
from __future__ import annotations
1✔
9

10
from typing import Final, Literal, Optional, Union
11

12
from mbedtls.exceptions import TLSError
1✔
13

14
from ._cipher import Cipher, Mode
1✔
15

16
__all__ = ["block_size", "key_size", "new"]
1✔
17

18

19
block_size: Final = 8
1✔
20
key_size: Final = 8
1✔
21

22

23
def new(
1✔
24
    key: bytes,
25
    mode: Union[int, Literal[Mode.CBC, Mode.ECB]],
26
    iv: Optional[bytes] = None,
27
) -> Cipher:
28
    """Return a `Cipher` object that can perform DES encryption and
29
    decryption.
30

31
    Data Encryption Standard (DES) cipher developed by IBM in the 70's.
32

33
    Parameters:
34
        key: The key to encrypt decrypt.  If None,
35
            encryption and decryption are unavailable.
36
        mode: The mode of operation of the cipher.
37
        iv: The initialization vector (IV).  The IV is
38
            required for every mode but ECB and CTR where it is ignored.
39
            If not set, the IV is initialized to all 0, which should not
40
            be used for encryption.
41

42
    """
43
    mode_ = Mode(mode)
1✔
44
    if len(key) != key_size:
1✔
45
        raise TLSError(msg="key size must be 16 bytes, got %r" % len(key))
×
46
    if mode_ not in {Mode.CBC, Mode.ECB}:
1✔
47
        raise TLSError(msg="unsupported mode %r" % mode_)
1✔
48
    name = ("DES-%s" % mode_.name).encode("ascii")
1✔
49
    return Cipher(name, key, mode_, iv)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc