22>>> from uid2_client import SharingClient
33"""
44import base64
5+ import datetime as dt
56
6- from .encryption import encrypt , decrypt_token
77from .client_type import ClientType
8+ from .encryption import encrypt , decrypt_token
89from .refresh_keys_util import refresh_sharing_keys
910
1011
@@ -36,23 +37,25 @@ def __init__(self, base_url, auth_key, secret_key):
3637 self ._auth_key = auth_key
3738 self ._secret_key = base64 .b64decode (secret_key )
3839
39- def encrypt_raw_uid_into_sharing_token (self , uid2 , keyset_id = None ):
40+ def encrypt_raw_uid_into_sharing_token (self , uid2 , keyset_id = None , now = dt . datetime . now ( tz = dt . timezone . utc ) ):
4041 """ Encrypt a UID2 into a sharing token
4142
4243 Args:
4344 uid2: the UID2 or EUID to be encrypted
4445 keys (EncryptionKeysCollection): collection of keys to choose from for encryption
4546 keyset_id (int) : An optional keyset id to use for the encryption. Will use default keyset if left blank
47+ now (Datetime): the datettime to use for now. Defaults to utc now
4648
4749 Returns (str): Sharing Token
4850 """
49- return encrypt (uid2 , None , self ._keys , keyset_id )
51+ return encrypt (uid2 , None , self ._keys , keyset_id , now = now )
5052
51- def decrypt_sharing_token_into_raw_uid (self , token ):
53+ def decrypt_sharing_token_into_raw_uid (self , token , now = dt . datetime . now ( tz = dt . timezone . utc ) ):
5254 """Decrypt sharing token to extract UID2 details.
5355
5456 Args:
5557 token (str): sharing token to decrypt
58+ now (datetime): date/time to use as "now" when doing token expiration check
5659
5760 Returns:
5861 DecryptedToken: details extracted from the sharing token
@@ -61,7 +64,7 @@ def decrypt_sharing_token_into_raw_uid(self, token):
6164 EncryptionError: if token version is not supported, the token has expired,
6265 or no required decryption keys present in the keys collection
6366 """
64- return decrypt_token (token , self ._keys , None , ClientType .Sharing )
67+ return decrypt_token (token , self ._keys , None , ClientType .Sharing , now )
6568
6669 def refresh_keys (self ):
6770 """Get the latest encryption keys for sharing tokens.
0 commit comments