File: _crypto_utils.py

package info (click to toggle)
python-securesystemslib 1.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,316 kB
  • sloc: python: 5,319; sh: 38; makefile: 5
file content (23 lines) | stat: -rw-r--r-- 566 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
"""Signer utils for internal use that require pyca/cryptography."""

from cryptography.hazmat.primitives.hashes import (
    SHA224,
    SHA256,
    SHA384,
    SHA512,
    HashAlgorithm,
)


def get_hash_algorithm(name: str) -> HashAlgorithm:
    """Helper to return hash algorithm object for name."""
    if name == "sha224":
        return SHA224()
    elif name == "sha256":
        return SHA256()
    elif name == "sha384":
        return SHA384()
    elif name == "sha512":
        return SHA512()

    raise ValueError(f"Unsupported hash algorithm: {name}")