]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python: remove string_to_byte_array()
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 12 Jun 2024 00:16:46 +0000 (12:16 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 12 Jun 2024 09:16:39 +0000 (09:16 +0000)
This was a useful function during the Python 2 -> 3 migration, but it
is not used any more. In all the cases it was used, we knew we already
had a bytes object, and this was just an inefficient way of confirming
that.

In cases where we actually want to cast a string into a mutable list
of byte-sized ints, the builtin bytearray() function will do a better
job than this, because it will encode high unicode characters as utf-8
bytes, rather than adding them as out-of-range values in the list.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Wed Jun 12 09:16:39 UTC 2024 on atb-devel-224

python/samba/__init__.py
python/samba/tests/core.py

index 5b1a3f91ba8ecd9002a4644fa8dade13c34eede1..d0e797e94c3fc64af6f61e646bffbf6241d0d5a6 100644 (file)
@@ -348,10 +348,6 @@ def current_unix_time():
     return int(time.time())
 
 
-def string_to_byte_array(string):
-    return [c if isinstance(c, int) else ord(c) for c in string]
-
-
 def arcfour_encrypt(key, data):
     from samba.crypto import arcfour_crypt_blob
     return arcfour_crypt_blob(data, key)
index 9f53473d4f6f28f8b62d977d8287e411e2f8b456..eaed4f9bf84635e6365fbd3d7b102bb88ea40704 100644 (file)
@@ -20,7 +20,7 @@
 import ldb
 import os
 import samba
-from samba import arcfour_encrypt, string_to_byte_array
+from samba import arcfour_encrypt
 from samba.tests import TestCase, TestCaseInTempDir
 
 
@@ -61,14 +61,6 @@ class ArcfourTestCase(TestCase):
         self.assertEqual(crypt_expected, crypt_calculated)
 
 
-class StringToByteArrayTestCase(TestCase):
-
-    def test_byte_array(self):
-        expected = [218, 145, 90, 176, 108, 215, 185, 207, 153]
-        calculated = string_to_byte_array('\xda\x91Z\xb0l\xd7\xb9\xcf\x99')
-        self.assertEqual(expected, calculated)
-
-
 class LdbExtensionTests(TestCaseInTempDir):
 
     def test_searchone(self):