]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common/cryptotools: Remove ascii and utf-8 references from encode/decode.
authorPaulo E. Castro <pecastro@wormholenet.com>
Wed, 23 Apr 2025 22:38:03 +0000 (23:38 +0100)
committerJohn Mulligan <jmulligan@redhat.com>
Mon, 7 Jul 2025 13:32:24 +0000 (09:32 -0400)
Signed-off-by: Paulo E. Castro <pecastro@wormholenet.com>
src/python-common/ceph/cryptotools/cryptotools.py
src/python-common/ceph/cryptotools/remote.py

index c38ee44fec48a438713f7f4ef095525fa66e1a7e..15284276ff881aac684d242d171939378562c8b2 100644 (file)
@@ -27,9 +27,9 @@ def password_hash(args: Namespace) -> None:
     if not salt_password:
         salt = bcrypt.gensalt()
     else:
-        salt = salt_password.encode('utf8')
+        salt = salt_password.encode()
 
-    hash_str = bcrypt.hashpw(password.encode('utf8'), salt).decode('utf-8')
+    hash_str = bcrypt.hashpw(password.encode(), salt).decode()
     json.dump({'hash': hash_str}, sys.stdout)
 
 
@@ -75,7 +75,7 @@ def _get_cert_issuer_info(crt: str) -> Tuple[Optional[str], Optional[str]]:
     """Basic validation of a CA cert
     """
 
-    crt_buffer = crt.encode("ascii") if isinstance(crt, str) else crt
+    crt_buffer = crt.encode() if isinstance(crt, str) else crt
     (org_name, cn) = (None, None)
     cert = crypto.load_certificate(crypto.FILETYPE_PEM, crt_buffer)
     components = cert.get_issuer().get_components()
@@ -91,14 +91,14 @@ def _get_cert_issuer_info(crt: str) -> Tuple[Optional[str], Optional[str]]:
 def verify_cacrt_content(args: Namespace) -> None:
     crt = sys.stdin.read()
 
-    crt_buffer = crt.encode("utf-8") if isinstance(crt, str) else crt
+    crt_buffer = crt.encode() if isinstance(crt, str) else crt
     x509 = crypto.load_certificate(crypto.FILETYPE_PEM, crt_buffer)
     no_after = x509.get_notAfter()
     if not no_after:
         print("Certificate does not have an expiration date.", file=sys.stderr)
         sys.exit(1)
 
-    end_date = datetime.datetime.strptime(no_after.decode('ascii'), '%Y%m%d%H%M%SZ')
+    end_date = datetime.datetime.strptime(no_after.decode(), '%Y%m%d%H%M%SZ')
 
     if x509.has_expired():
         org, cn = _get_cert_issuer_info(crt)
@@ -116,7 +116,7 @@ def verify_cacrt_content(args: Namespace) -> None:
 def get_cert_issuer_info(args: Namespace) -> None:
     crt = sys.stdin.read()
 
-    crt_buffer = crt.encode("utf-8") if isinstance(crt, str) else crt
+    crt_buffer = crt.encode() if isinstance(crt, str) else crt
     (org_name, cn) = (None, None)
     cert = crypto.load_certificate(crypto.FILETYPE_PEM, crt_buffer)
     components = cert.get_issuer().get_components()
@@ -145,7 +145,7 @@ def verify_tls(args: Namespace) -> None:
     except (ValueError, crypto.Error) as e:
         _fail_message('Invalid private key: %s' % str(e))
     try:
-        crt_buffer = crt.encode("ascii") if isinstance(crt, str) else crt
+        crt_buffer = crt.encode() if isinstance(crt, str) else crt
         _crt = crypto.load_certificate(crypto.FILETYPE_PEM, crt_buffer)
     except ValueError as e:
         _fail_message('Invalid certificate key: %s' % str(e))
index 3271ac847a87aab3eacd565abaed8bf286b78639..04d015382a10509bff49e7290d5654884a57ff6e 100644 (file)
@@ -62,7 +62,7 @@ class CryptoCaller:
         if input_data is None:
             _input = None
         else:
-            _input = input_data.encode('utf-8')
+            _input = input_data.encode()
         cmd = ['python3', '-m', _ctmodule] + list(args)
         logger.warning('CryptoCaller will run: %r', cmd)
         try:
@@ -82,7 +82,7 @@ class CryptoCaller:
         return result_obj
 
     def _result_str(self, result: subprocess.CompletedProcess) -> str:
-        return result.stdout.decode('utf-8')
+        return result.stdout.decode()
 
     def map_error(self, err: Exception) -> Optional[Exception]:
         """Convert between error types raised by the subprocesses