Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor streamlined xtra xs field support in Matter #829

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/keri/core/coring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,21 +1424,18 @@ def _exfil(self, qb64b):
# these are well formed.
# when fs is None then ss > 0 otherwise fs > hs + ss when ss > 0

xtra = qb64b[hs:hs+xs] # extract xtra prepad chars of soft, empty when xs==0
if isinstance(xtra, memoryview):
xtra = bytes(xtra)
if hasattr(xtra, "decode"):
xtra = xtra.decode() # converts bytes/bytearray to str
if xtra != f"{self.Pad * xs}":
raise UnexpectedCodeError(f"Invalid prepad xtra ={xtra}.")

# extract soft chars excluding xtra, empty when ss==0 and xs == 0
# extract soft chars including xtra, empty when ss==0 and xs == 0
# assumes that when ss == 0 then xs must be 0
soft = qb64b[hs+xs:hs+ss]
soft = qb64b[hs:hs+ss]
if isinstance(soft, memoryview):
soft = bytes(soft)
if hasattr(soft, "decode"):
soft = soft.decode() # converts bytes/bytearray to str
xtra = soft[:xs] # extract xtra if any from front of soft
soft = soft[xs:] # strip xtra from soft
if xtra != f"{self.Pad * xs}":
raise UnexpectedCodeError(f"Invalid prepad xtra ={xtra}.")

if not fs: # compute fs from soft from ss part which provides size B64
# compute variable size as int may have value 0
Expand Down Expand Up @@ -1516,13 +1513,14 @@ def _bexfil(self, qb2):
raise ShortageError("Need {} more bytes.".format(bcs - len(qb2)))

both = codeB2ToB64(qb2, cs) # extract and convert both hard and soft part of code
xtra = both[hs:hs+xs] # extract xtra prepad chars of soft, empty when xs==0
if xtra != f"{self.Pad * xs}":
raise UnexpectedCodeError(f"Invalid prepad xtra ={xtra}.")

# extract soft chars excluding xtra, empty when ss==0 and xs == 0
# extract soft chars including xtra, empty when ss==0 and xs == 0
# assumes that when ss == 0 then xs must be 0
soft = both[hs+xs:hs+ss] # get soft may be empty
soft = both[hs:hs+ss] # get soft may be empty
xtra = soft[:xs] # extract xtra if any from front of soft
soft = soft[xs:] # strip xtra from soft
if xtra != f"{self.Pad * xs}":
raise UnexpectedCodeError(f"Invalid prepad xtra ={xtra}.")

if not fs: # compute fs from size chars in ss part of code
if len(qb2) < bcs: # need more bytes
Expand Down
Loading