1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

python: remove string_to_byte_array()

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
This commit is contained in:
Douglas Bagnall 2024-06-12 12:16:46 +12:00 committed by Andrew Bartlett
parent 982dab8932
commit 43802f1bed
2 changed files with 1 additions and 13 deletions

View 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)

View 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):