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

Synss / python-mbedtls / 8002749462

22 Feb 2024 10:07AM UTC 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/Camellia.py
1
# SPDX-License-Identifier: MIT
2
# Copyright (c) 2016, Elaborated Networks GmbH
3
# Copyright (c) 2019, Mathias Laurin
4

5
"""Camellia cipher developed by Japan's Mitsubishi an NTT in 2000."""
1✔
6

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
block_size: Final = 16
1✔
19
key_size: Final = None
1✔
20

21

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

32
    Camellia cipher developed by Japan's Mitsubishi an NTT in 2000.
33

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

43
    """
44
    mode_ = Mode(mode)
1✔
45
    if len(key) not in {16, 24, 32}:
1✔
46
        raise TLSError(
×
47
            msg="key size must 16, 24, or 32 bytes, got %r" % len(key)
48
        )
49
    if mode_ not in {Mode.CBC, Mode.CFB, Mode.CTR, Mode.ECB, Mode.GCM}:
1✔
50
        raise TLSError(msg="unsupported mode %r" % mode_)
1✔
51
    name = (
1✔
52
        "CAMELLIA-%i-%s%s"
53
        % (len(key) * 8, mode_.name, "128" if mode_ is Mode.CFB else "")
54
    ).encode("ascii")
55
    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