Debian Codegraph @

ansible_collections/hetzner/hcloud/plugins/module_utils/_ssh.py

raw
1 # Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
2 # Do not use this from other collections or standalone plugins/modules!
3
4 from __future__ import annotations
5
6 from base64 import b64decode
7 from hashlib import md5
8
9
10 def ssh_public_key_md5_fingerprint(value: str) -> str:
11 """
12 Compute the md5 fingerprint of a SSH public key.
13 """
14 parts = value.strip().split()
15 if len(parts) < 2:
16 raise ValueError("invalid ssh public key")
17
18 raw = b64decode(parts[1].encode("ascii"))
19 digest = md5(raw).hexdigest()
20
21 return ":".join(a + b for a, b in zip(digest[::2], digest[1::2]))