Projects
osmocom:master
pyosmocom
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 5
View file
commit_6851b921ac780a19ea811ddee0140c50ea32e231.txt
Added
View file
commit_b899e3fd866cfe1fc78a69a3e2359cd2bb826f85.txt
Deleted
View file
pyosmocom_0.0.4.204.b899.dsc -> pyosmocom_0.0.4.206.6851.dsc
Changed
@@ -2,7 +2,7 @@ Source: pyosmocom Binary: python3-pyosmocom-doc, python3-pyosmocom Architecture: all -Version: 0.0.4.204.b899 +Version: 0.0.4.206.6851 Maintainer: Osmocom team <openbsc@lists.osmocom.org> Homepage: https://osmocom.org/projects/pyosmocom/wiki Standards-Version: 3.9.8 @@ -13,8 +13,8 @@ python3-pyosmocom deb python optional arch=all python3-pyosmocom-doc deb doc optional arch=all Checksums-Sha1: - 762d013a1b204553dafe41ca0827cfdabb48de4e 31872 pyosmocom_0.0.4.204.b899.tar.xz + 9558037a6d521df689cfd455ae134e3eff49b147 32644 pyosmocom_0.0.4.206.6851.tar.xz Checksums-Sha256: - 4c4627633d4609b5e7d59dfb0d3a8b1a9974726b5ff9dc11c2e546d432451652 31872 pyosmocom_0.0.4.204.b899.tar.xz + 5dcdff8f55cff1fd7029f13ab6c071d9281574de8f94f589722d27c4ce015d39 32644 pyosmocom_0.0.4.206.6851.tar.xz Files: - e90c8606c34a3952692aa213fc3cc9cb 31872 pyosmocom_0.0.4.204.b899.tar.xz + d73d6ce6e7ed06991ab677226dfa0cb8 32644 pyosmocom_0.0.4.206.6851.tar.xz
View file
pyosmocom_0.0.4.204.b899.tar.xz/.tarball-version -> pyosmocom_0.0.4.206.6851.tar.xz/.tarball-version
Changed
@@ -1 +1 @@ -0.0.4.204-b899 +0.0.4.206-6851
View file
pyosmocom_0.0.4.204.b899.tar.xz/debian/changelog -> pyosmocom_0.0.4.206.6851.tar.xz/debian/changelog
Changed
@@ -1,8 +1,8 @@ -pyosmocom (0.0.4.204.b899) unstable; urgency=medium +pyosmocom (0.0.4.206.6851) unstable; urgency=medium * Automatically generated changelog entry for building the Osmocom master feed - -- Osmocom OBS scripts <info@osmocom.org> Thu, 26 Sep 2024 07:39:12 +0000 + -- Osmocom OBS scripts <info@osmocom.org> Mon, 30 Sep 2024 17:29:42 +0000 pyosmocom (0.0.4) unstable; urgency=medium
View file
pyosmocom_0.0.4.204.b899.tar.xz/src/osmocom/construct.py -> pyosmocom_0.0.4.206.6851.tar.xz/src/osmocom/construct.py
Changed
@@ -16,7 +16,7 @@ from construct.core import evaluate from construct.lib import integertypes -from osmocom.utils import b2h, h2b, swap_nibbles +from osmocom.utils import b2h, h2b, swap_nibbles, int_bytes_required # (C) 2021-2022 by Harald Welte <laforge@osmocom.org> # @@ -587,29 +587,10 @@ except ValueError as e: raise IntegerError(str(e), path=path) - def __bytes_required(self, i, minlen=0): - if self.signed: - raise NotImplementedError("FIXME: Implement support for encoding signed integer") - - # compute how many bytes we need - nbytes = 1 - while True: - i = i >> 8 - if i == 0: - break - else: - nbytes = nbytes + 1 - - # round up to the minimum number - # of bytes we anticipate - nbytes = max(nbytes, minlen) - - return nbytes - def _build(self, obj, stream, context, path): if not isinstance(obj, integertypes): raise IntegerError(f"value {obj} is not an integer", path=path) - length = self.__bytes_required(obj, self.minlen) + length = int_bytes_required(obj, self.minlen, self.signed) try: data = obj.to_bytes(length, byteorder='big', signed=self.signed) except ValueError as e: @@ -619,6 +600,19 @@ stream_write(stream, data, length, path) return obj +class Asn1DerInteger(Construct): + """A signed integer value using ASN.1 DER encoding rules (see also ITU-T X.690 8.3)""" + def _parse(self, stream, context, path): + data = stream_read_entire(stream, path) + return int.from_bytes(data, byteorder='big', signed=True) + + def _build(self, obj, stream, context, path): + if not isinstance(obj, integertypes): + raise IntegerError(f"value {obj} is not an integer", path=path) + val = obj.to_bytes(int_bytes_required(obj, signed=True), byteorder='big', signed=True) + stream_write(stream, val, len(val), path) + return obj + # merged definitions of 24.008 + 23.040 TypeOfNumber = Enum(BitsInteger(3), unknown=0, international=1, national=2, network_specific=3, short_code=4, alphanumeric=5, abbreviated=6, reserved_for_extension=7)
View file
pyosmocom_0.0.4.204.b899.tar.xz/src/osmocom/utils.py -> pyosmocom_0.0.4.206.6851.tar.xz/src/osmocom/utils.py
Changed
@@ -137,6 +137,44 @@ return (n + 1)//2 +def int_bytes_required(number: int, minlen:int = 0, signed:bool = False): + """compute how many bytes an integer requires when it is encoded into bytes + Args: + number : integer number + minlen : minimum length + signed : compute the number of bytes for a signed integer (two's complement) + Returns: + Integer 'nbytes', which is the number of bytes required to encode 'number' + """ + + if signed == False and number < 0: + raise ValueError("expecting a positive number") + + # Compute how many bytes we need for the absolute (positive) value of the given number + nbytes = 1 + i = abs(number) + while True: + i = i >> 8 + if i == 0: + break + else: + nbytes = nbytes + 1 + + # When we deal with signed numbers, then the two's complement applies. This means that we must check if the given + # number would still fit in the value range of the number of bytes we have calculated above. If not, one more + # byte is required. + if signed: + value_range_limit = pow(2,nbytes*8) // 2 + if number < -value_range_limit: + nbytes = nbytes + 1 + elif number >= value_range_limit: + nbytes = nbytes + 1 + + # round up to the minimum number of bytes we anticipate + nbytes = max(nbytes, minlen) + return nbytes + + def str_sanitize(s: str) -> str: """replace all non printable chars, line breaks and whitespaces, with ' ', make sure that there are no whitespaces at the end and at the beginning of the string.
View file
pyosmocom_0.0.4.204.b899.tar.xz/tests/test_construct.py -> pyosmocom_0.0.4.206.6851.tar.xz/tests/test_construct.py
Changed
@@ -114,6 +114,66 @@ self.assertEqual(re_enc, enc) +class TestAsn1DerInteger(unittest.TestCase): + + tests = + # positive numbers + ( b'\x00', 0 ), + ( b'\x01', 1 ), + ( b'\x02', 2 ), + ( b'\x7f', 127 ), + ( b'\x00\x80', 128 ), + ( b'\x00\x81', 129 ), + ( b'\x00\xfe', 254 ), + ( b'\x01\x00', 256 ), + ( b'\x01\x01', 257 ), + ( b'\x7f\xff', 32767 ), + ( b'\x00\x80\x00', 32768 ), + ( b'\x00\x80\x01', 32769 ), + ( b'\x00\xff\xfe', 65534 ), + ( b'\x00\xff\xff', 65535 ), + ( b'\x01\x00\x00', 65536 ), + + # negative numbers + ( b'\x00', -0 ), + ( b'\xff', -1 ), + ( b'\xfe', -2 ), + ( b'\x81', -127 ), + ( b'\x80', -128 ), + ( b'\xff\x7f', -129 ), + ( b'\xff\x02', -254 ), + ( b'\xff\x00', -256 ), + ( b'\xfe\xff', -257 ), + ( b'\x80\x01', -32767 ), + ( b'\x80\x00', -32768 ), + ( b'\xff\x7f\xff', -32769 ), + ( b'\xff\x00\x02', -65534 ), + ( b'\xff\x00\x01', -65535 ), + ( b'\xff\x00\x00', -65536 ), + + + def test_encode(self): + adi = Asn1DerInteger() + + # Verfiy with chosen numbers + for t in self.tests: + self.assertEqual(t0, adi.build(t1)) + + # Verify that ITU-T X.690 8.3.2 is always complied with (for standard two's + # complement that should always be the case) + for i in range(-100000,100000): + res = adi.build(i) + if len(res) > 1: + self.assertFalse(int(res0) == 0xff and int(res1) & 0x80 == 0x80) + self.assertFalse(int(res0) == 0x00 and int(res1) & 0x80 == 0x00) + + def test_decode(self): + adi = Asn1DerInteger() + + # Verfiy with chosen numbers + for t in self.tests: + self.assertEqual(t1, adi.parse(t0)) + if __name__ == "__main__": unittest.main()
View file
pyosmocom_0.0.4.204.b899.tar.xz/tests/test_utils.py -> pyosmocom_0.0.4.206.6851.tar.xz/tests/test_utils.py
Changed
@@ -54,5 +54,42 @@ self.assertEqual(str(hexstr('ABCD')), 'abcd') +class Test_int_bytes_required(unittest.TestCase): + + def test_int_bytes_required(self): + + tests = + # unsigned positive numbers + ( 1, 0, False ), + ( 1, 1, False ), + ( 1, 255, False ), + ( 2, 256, False ), + ( 2, 65535, False ), + ( 3, 65536, False ), + ( 2, 65535, False ), + ( 3, 16777215, False ), + ( 4, 16777216, False ), + + # signed positive numbers + ( 1, 0, True ), + ( 1, 1, True ), + ( 1, 127, True ), + ( 2, 128, True ), + ( 2, 32767, True ), + ( 3, 32768, True ), + + # signed negative numbers + ( 1, -0, True ), + ( 1, -1, True ), + ( 1, -128, True ), + ( 2, -129, True ), + ( 2, -32768, True ), + ( 3, -32769, True ), + + + for t in tests: + self.assertEqual(t0, int_bytes_required(t1, signed = t2)) + + if __name__ == "__main__": unittest.main()
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.