]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
py:key_credential_links: allow encoding=='auto'
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 15 Aug 2025 05:35:33 +0000 (17:35 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Wed, 20 Aug 2025 04:34:37 +0000 (04:34 +0000)
'auto' is the same as None. This is helpful to samba-tool.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
python/samba/key_credential_link.py

index b17581bf46df3fd50a0506a6f5ce2aec5a803861..64bca98b946951a6f5c5a9054b4c1ea34f617c62 100644 (file)
@@ -195,7 +195,7 @@ class KeyCredentialLinkDn(BinaryDn):
         return pem.decode()
 
 
-def get_public_key(data:bytes, encoding:str):
+def get_public_key(data:bytes, encoding:Optional[str] = None) -> RSAPublicKey:
     """decode a key in PEM or DER format.
 
     If it turns out to be a certificate or something, we try to get
@@ -268,6 +268,9 @@ def create_key_credential_link(samdb: SamDB,
         if len(res) == 0:
             raise ValueError(f"link target {target} does not exist")
 
+    if encoding == 'auto':
+        encoding = None
+
     key = get_public_key(data, encoding)
 
     if key.key_size != 2048: