id_service_uuid.py
ofrak.service.id_service_uuid
UUIDService (IDServiceInterface)
generate_id(self)
Generate a unique ID.
This method guarantees that no two IDs it returns will be identical for the lifetime of
the instantiated IDServiceInterface
.
Returns:
Type | Description |
---|---|
bytes |
The unique ID that was generated. |
Source code in ofrak/service/id_service_uuid.py
def generate_id(self) -> bytes:
# Note: pseudo-random
return uuid.uuid4().bytes
generate_id_from_base(base_id, key)
staticmethod
Generate an ID based on a base ID and key.
This method returns the same ID each time it is called with the exact same parameters. It should therefore be used with caution: the callee needs to know that the parameters passed to this method are unique.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_id |
bytes |
An ID used to derive the generated ID. This ID can be assumed to have been generated by the |
required |
key |
str |
A key used to guarantee that the generated ID is unique. The callee is responsible for ensuring that this key is unique. |
required |
Returns:
Type | Description |
---|---|
bytes |
The ID that was generated. |
Source code in ofrak/service/id_service_uuid.py
@staticmethod
def generate_id_from_base(base_id: bytes, key: str) -> bytes:
return uuid.uuid5(uuid.UUID(bytes=base_id), key).bytes