Skip to content

Commit

Permalink
Auth: ssh_sign, add type hints; rucio#6600
Browse files Browse the repository at this point in the history
Follow-up from this PR: rucio#6497
  • Loading branch information
rdimaio committed Apr 8, 2024
1 parent 5496213 commit f747500
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/rucio/common/utils.py
Expand Up @@ -1271,21 +1271,21 @@ def detect_client_location():
'longitude': longitude}


def ssh_sign(private_key, message):
def ssh_sign(private_key: str, message: str) -> str:
"""
Sign a string message using the private key.
:param private_key: The SSH RSA private key as a string.
:param message: The message to sign as a string.
:return: Base64 encoded signature as a string.
"""
message = message.encode()
encoded_message = message.encode()
if not EXTRA_MODULES['paramiko']:
raise MissingModuleException('The paramiko module is not installed or faulty.')
sio_private_key = StringIO(private_key)
priv_k = RSAKey.from_private_key(sio_private_key)
sio_private_key.close()
signature_stream = priv_k.sign_ssh_data(message)
signature_stream = priv_k.sign_ssh_data(encoded_message)
signature_stream.rewind()
base64_encoded = base64.b64encode(signature_stream.get_remainder())
base64_encoded = base64_encoded.decode()
Expand Down

0 comments on commit f747500

Please sign in to comment.