mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-03 23:51:48 +00:00
##### SUMMARY All `module_utils` are now marked as **private**. None of the modules were intended for public use. Similar to https://togithub.com/ansible-collections/community.general/issues/11312
21 lines
653 B
Python
21 lines
653 B
Python
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
|
# Do not use this from other collections or standalone plugins/modules!
|
|
|
|
from __future__ import annotations
|
|
|
|
from base64 import b64decode
|
|
from hashlib import md5
|
|
|
|
|
|
def ssh_public_key_md5_fingerprint(value: str) -> str:
|
|
"""
|
|
Compute the md5 fingerprint of a SSH public key.
|
|
"""
|
|
parts = value.strip().split()
|
|
if len(parts) < 2:
|
|
raise ValueError("invalid ssh public key")
|
|
|
|
raw = b64decode(parts[1].encode("ascii"))
|
|
digest = md5(raw).hexdigest()
|
|
|
|
return ":".join(a + b for a, b in zip(digest[::2], digest[1::2]))
|