Skip to content

Commit

Permalink
Update the GUID code
Browse files Browse the repository at this point in the history
* Annotate the parameters and return values
* Remove module executable code
  • Loading branch information
kurtmckee committed Sep 27, 2024
1 parent 152e6da commit e95d58b
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions src/smartcard/guid.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,21 @@
"""
import uuid

# guid is ulong+ushort+ushort+uchar[8]


def strToGUID(s):
def strToGUID(s: str) -> list[int]:
"""Converts a GUID string into a list of bytes.
>>> strToGUID('{AD4F1667-EA75-4124-84D4-641B3B197C65}')
[103, 22, 79, 173, 117, 234, 36, 65, 132, 212, 100, 27, 59, 25, 124, 101]
"""
dat = uuid.UUID(hex=s)
dat = list(dat.bytes_le)
return dat
return list(uuid.UUID(s).bytes_le)


def GUIDToStr(g):
def GUIDToStr(g: list[int]) -> str:
"""Converts a GUID sequence of bytes into a string.
>>> GUIDToStr([103,22,79,173, 117,234, 36,65,
... 132, 212, 100, 27, 59, 25, 124, 101])
'{AD4F1667-EA75-4124-84D4-641B3B197C65}'
"""
dat = uuid.UUID(bytes_le=bytes(g))
return '{' + str(dat).upper() + '}'


if __name__ == "__main__":
"""Small sample illustrating the use of guid.py."""
guid_in = '{AD4F1667-EA75-4124-84D4-641B3B197C65}'
print(guid_in)
dummycardguid1 = strToGUID(guid_in)
print(dummycardguid1)
guid_out = GUIDToStr(dummycardguid1)
print(guid_out)
if guid_in != guid_out:
print("Failure")
else:
print("Success")
return f"{{{uuid.UUID(bytes_le=bytes(g))}}}".upper()

0 comments on commit e95d58b

Please sign in to comment.