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

Synss / python-mbedtls / 8860635695

27 Apr 2024 02:49PM CUT coverage: 87.47%. Remained the same
8860635695

push

github

Synss
ci: Split sdist/wheels workflows

2583 of 2953 relevant lines covered (87.47%)

0.87 hits per line

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

92.59
/src/mbedtls/hashlib.py
1
# SPDX-License-Identifier: MIT
2
# Copyright (c) 2015, Elaborated Networks GmbH
3
# Copyright (c) 2019, Mathias Laurin
4

5
"""Generic message digest wrapper (hash algorithm)."""
1✔
6

7
from __future__ import annotations
1✔
8

9
from typing import Optional, Protocol
10

11
# pylint: disable=no-name-in-module
12
from mbedtls._md import Hash as Hash
1✔
13
from mbedtls._md import algorithms_available as algorithms_available
1✔
14
from mbedtls._md import algorithms_guaranteed as algorithms_guaranteed
1✔
15

16
# pylint: enable=no-name-in-module
17

18

19
# Work around pyflakes' F401: imported but unused
20
assert algorithms_available
1✔
21
assert algorithms_guaranteed
1✔
22

23

24
class Algorithm(Protocol):
1✔
25
    def __call__(self, buffer: Optional[bytes] = ...) -> Hash: ...
26

27

28
def new(name: str, buffer: Optional[bytes] = None) -> Hash:
1✔
29
    """A generic constructor that takes the string name of the desired
30
    algorithm as its first parameter.
31

32
    """
33
    block_size = {
1✔
34
        "md2": 16,
35
        "md4": 64,
36
        "md5": 64,
37
        "sha1": 64,
38
        "sha224": 64,
39
        "sha256": 64,
40
        "sha384": 128,
41
        "sha512": 128,
42
        "ripemd160": 64,
43
    }.get(name.lower(), 64)
44
    return Hash(name, buffer, block_size=block_size)
1✔
45

46

47
def md2(buffer: Optional[bytes] = None) -> Hash:
1✔
48
    """MD2 message-digest algorithm."""
49
    return new("md2", buffer)  # pragma: no cover
50

51

52
def md4(buffer: Optional[bytes] = None) -> Hash:
1✔
53
    """MD4 message-digest algorithm."""
54
    return new("md4", buffer)  # pragma: no cover
55

56

57
def md5(buffer: Optional[bytes] = None) -> Hash:
1✔
58
    """MD5 message-digest algorithm."""
59
    return new("md5", buffer)
1✔
60

61

62
def sha1(buffer: Optional[bytes] = None) -> Hash:
1✔
63
    """Secure Hash Algorithm 1 (SHA-1)."""
64
    return new("sha1", buffer)
1✔
65

66

67
def sha224(buffer: Optional[bytes] = None) -> Hash:
1✔
68
    """Secure Hash Algorithm 2 (SHA-2) with 224 bits hash value."""
69
    return new("sha224", buffer)
×
70

71

72
def sha256(buffer: Optional[bytes] = None) -> Hash:
1✔
73
    """Secure Hash Algorithm 2 (SHA-2) with 256 bits hash value."""
74
    return new("sha256", buffer)
1✔
75

76

77
def sha384(buffer: Optional[bytes] = None) -> Hash:
1✔
78
    """Secure Hash Algorithm 2 (SHA-2) with 384 bits hash value."""
79
    return new("sha384", buffer)
×
80

81

82
def sha512(buffer: Optional[bytes] = None) -> Hash:
1✔
83
    """Secure Hash Algorithm 2 (SHA-2) with 512 bits hash value."""
84
    return new("sha512", buffer)
1✔
85

86

87
def ripemd160(buffer: Optional[bytes] = None) -> Hash:
1✔
88
    """RACE Integrity Primitives Evaluation Message Digest (RIPEMD) with
89
    160 bits hash value."""
90
    return new("ripemd160", buffer)
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