lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

September 2024

  • 1 participants
  • 1983 discussions
[XS] Change in ...pyosmocom[master]: tag 0.0.5 for osmocom.construct.Asn1DerInteger
by laforge 25 Sep '24

25 Sep '24
Attention is currently required from: dexter, osmith. laforge has posted comments on this change by laforge. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/38273?usp=email ) Change subject: tag 0.0.5 for osmocom.construct.Asn1DerInteger ...................................................................... Patch Set 7: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/38273?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: python/pyosmocom Gerrit-Branch: master Gerrit-Change-Id: I77914901d7f154d3a6e97c39575292e03453ddf7 Gerrit-Change-Number: 38273 Gerrit-PatchSet: 7 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Attention: osmith <osmith(a)sysmocom.de> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Wed, 25 Sep 2024 16:01:31 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[XS] Change in ...pyosmocom[master]: tag 0.0.5 for osmocom.construct.Asn1DerInteger
by laforge 25 Sep '24

25 Sep '24
Attention is currently required from: dexter, osmith. laforge has posted comments on this change by laforge. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/38273?usp=email ) Change subject: tag 0.0.5 for osmocom.construct.Asn1DerInteger ...................................................................... Set Ready For Review -- To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/38273?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: python/pyosmocom Gerrit-Branch: master Gerrit-Change-Id: I77914901d7f154d3a6e97c39575292e03453ddf7 Gerrit-Change-Number: 38273 Gerrit-PatchSet: 7 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Attention: osmith <osmith(a)sysmocom.de> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Wed, 25 Sep 2024 16:01:27 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: No
1 0
0 0
[M] Change in ...pyosmocom[master]: osmocom.construct.Asn1DerInteger
by laforge 25 Sep '24

25 Sep '24
Attention is currently required from: dexter, osmith. laforge has posted comments on this change by laforge. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/38272?usp=email ) Change subject: osmocom.construct.Asn1DerInteger ...................................................................... Patch Set 6: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/38272?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: python/pyosmocom Gerrit-Branch: master Gerrit-Change-Id: I0cfe97daf957919de86453d6d44f9c99ab3075ac Gerrit-Change-Number: 38272 Gerrit-PatchSet: 6 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Attention: osmith <osmith(a)sysmocom.de> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Wed, 25 Sep 2024 16:01:24 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[M] Change in ...pyosmocom[master]: osmocom.construct.Asn1DerInteger
by laforge 25 Sep '24

25 Sep '24
Attention is currently required from: dexter, laforge, osmith. laforge has posted comments on this change by laforge. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/38272?usp=email ) Change subject: osmocom.construct.Asn1DerInteger ...................................................................... Set Ready For Review -- To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/38272?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: python/pyosmocom Gerrit-Branch: master Gerrit-Change-Id: I0cfe97daf957919de86453d6d44f9c99ab3075ac Gerrit-Change-Number: 38272 Gerrit-PatchSet: 6 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Attention: osmith <osmith(a)sysmocom.de> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Wed, 25 Sep 2024 16:01:21 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: No
1 0
0 0
[M] Change in ...pyosmocom[master]: construct: move __bytes_required to utils and finish the implementation
by laforge 25 Sep '24

25 Sep '24
Attention is currently required from: dexter. laforge has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/38289?usp=email ) Change subject: construct: move __bytes_required to utils and finish the implementation ...................................................................... Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/38289?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: python/pyosmocom Gerrit-Branch: master Gerrit-Change-Id: I9ae4acc30dbd5fb6a6b24b10254ffb205bfde52d Gerrit-Change-Number: 38289 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Wed, 25 Sep 2024 16:00:49 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[S] Change in ...pyosmocom[master]: tlv/cosmetic: improve import of osmocom functions
by laforge 25 Sep '24

25 Sep '24
Attention is currently required from: dexter. laforge has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/38288?usp=email ) Change subject: tlv/cosmetic: improve import of osmocom functions ...................................................................... Patch Set 1: Code-Review+1 (1 comment) Patchset: PS1: Of course we could always just import osmocom and prefix everything, but that's now how we generally do things. the rationale is to avoid circular imports in follow-up patches. -- To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/38288?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: python/pyosmocom Gerrit-Branch: master Gerrit-Change-Id: I6ce3cffbce9b276de7b223d88268d35cf2706d6a Gerrit-Change-Number: 38288 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Wed, 25 Sep 2024 16:00:16 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes
1 0
0 0
[S] Change in ...pyosmocom[master]: test_construct: move testvectors inside unittest class
by laforge 25 Sep '24

25 Sep '24
Attention is currently required from: dexter. laforge has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/38287?usp=email ) Change subject: test_construct: move testvectors inside unittest class ...................................................................... Patch Set 1: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/38287?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: python/pyosmocom Gerrit-Branch: master Gerrit-Change-Id: Ida24295091efd30406e9a354ca5854150127b3d4 Gerrit-Change-Number: 38287 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-CC: Jenkins Builder Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Wed, 25 Sep 2024 15:59:21 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[M] Change in ...pyosmocom[master]: construct: move __bytes_required to utils and finish the implementation
by dexter 25 Sep '24

25 Sep '24
dexter has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/38289?usp=email ) Change subject: construct: move __bytes_required to utils and finish the implementation ...................................................................... Set Ready For Review -- To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/38289?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: python/pyosmocom Gerrit-Branch: master Gerrit-Change-Id: I9ae4acc30dbd5fb6a6b24b10254ffb205bfde52d Gerrit-Change-Number: 38289 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-CC: Jenkins Builder Gerrit-Comment-Date: Wed, 25 Sep 2024 15:12:51 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: No
1 0
0 0
[M] Change in ...pyosmocom[master]: construct: move __bytes_required to utils and finish the implementation
by dexter 25 Sep '24

25 Sep '24
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/38289?usp=email ) Change subject: construct: move __bytes_required to utils and finish the implementation ...................................................................... construct: move __bytes_required to utils and finish the implementation The method __bytes_required in the GreedyInteger class computes how many byte a given integer number requires, when it is encoded. This method currently only works for unsigned integers. Let's move it to utils and add support for signed integers. Related: SYS#7094 Change-Id: I9ae4acc30dbd5fb6a6b24b10254ffb205bfde52d --- M src/osmocom/construct.py M src/osmocom/utils.py M tests/test_utils.py 3 files changed, 77 insertions(+), 21 deletions(-) git pull ssh://gerrit.osmocom.org:29418/python/pyosmocom refs/changes/89/38289/1 diff --git a/src/osmocom/construct.py b/src/osmocom/construct.py index def5d85..7c0f034 100644 --- a/src/osmocom/construct.py +++ b/src/osmocom/construct.py @@ -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(a)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: diff --git a/src/osmocom/utils.py b/src/osmocom/utils.py index 009eb04..5947453 100644 --- a/src/osmocom/utils.py +++ b/src/osmocom/utils.py @@ -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. diff --git a/tests/test_utils.py b/tests/test_utils.py index 8e4732f..0f22e35 100755 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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(t[0], int_bytes_required(t[1], signed = t[2])) + + if __name__ == "__main__": unittest.main() -- To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/38289?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: python/pyosmocom Gerrit-Branch: master Gerrit-Change-Id: I9ae4acc30dbd5fb6a6b24b10254ffb205bfde52d Gerrit-Change-Number: 38289 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
1 0
0 0
[S] Change in ...pyosmocom[master]: tlv/cosmetic: improve import of osmocom functions
by dexter 25 Sep '24

25 Sep '24
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/38288?usp=email ) Change subject: tlv/cosmetic: improve import of osmocom functions ...................................................................... tlv/cosmetic: improve import of osmocom functions We can import osmocom and then reference build/parse_construct using osmocom.construct.build/parse_construct. Change-Id: I6ce3cffbce9b276de7b223d88268d35cf2706d6a --- M src/osmocom/tlv.py 1 file changed, 5 insertions(+), 5 deletions(-) git pull ssh://gerrit.osmocom.org:29418/python/pyosmocom refs/changes/88/38288/1 diff --git a/src/osmocom/tlv.py b/src/osmocom/tlv.py index d24f2aa..93e4e87 100644 --- a/src/osmocom/tlv.py +++ b/src/osmocom/tlv.py @@ -21,7 +21,7 @@ import re from typing import List, Tuple, Optional -from osmocom.construct import build_construct, parse_construct +import osmocom ######################################################################### # poor man's COMPREHENSION-TLV decoder. @@ -383,9 +383,9 @@ if self.decoded is None: do = b'' elif self._construct: - do = build_construct(self._construct, self.decoded, context) + do = osmocom.construct.build_construct(self._construct, self.decoded, context) elif self.__class__._construct: - do = build_construct(self.__class__._construct, self.decoded, context) + do = osmocom.construct.build_construct(self.__class__._construct, self.decoded, context) else: do = self._to_bytes() self.encoded = do @@ -402,9 +402,9 @@ if self.encoded == b'': self.decoded = None elif self._construct: - self.decoded = parse_construct(self._construct, do, context=context) + self.decoded = osmocom.construct.parse_construct(self._construct, do, context=context) elif self.__class__._construct: - self.decoded = parse_construct(self.__class__._construct, do, context=context) + self.decoded = osmocom.construct.parse_construct(self.__class__._construct, do, context=context) else: self.decoded = self._from_bytes(do) return self.decoded -- To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/38288?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: python/pyosmocom Gerrit-Branch: master Gerrit-Change-Id: I6ce3cffbce9b276de7b223d88268d35cf2706d6a Gerrit-Change-Number: 38288 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-CC: laforge <laforge(a)osmocom.org>
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • ...
  • 199
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.