Skip to content

Commit 137ddba

Browse files
authored
stop mentioning sample_encryption.py (#12)
* - stop mentioning sample_encryption.py as data encryption/decryption should be unused these days - removed sample_encryption app from "make examples" building - add encrypt() function example into sample_client.py. - more comments in general * fixed mentioning of old decrypt method in readme * fixed missing IdentityScope param and typos
1 parent f645bea commit 137ddba

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test:
66
shell:
77
docker run -it -w $(PWD) -v $(PWD):$(PWD) -u `id -u`:`id -g` $(DOCKERIMAGE) /bin/bash
88

9-
examples: example_client example_auto_refresh example_encryption
9+
examples: example_client example_auto_refresh
1010

1111
example_client:
1212
docker run -w $(PWD) -v $(PWD):$(PWD) -u `id -u`:`id -g` -e PYTHONPATH=$(PWD) $(DOCKERIMAGE) python3 examples/sample_client.py "$(BASE_URL)" "$(AUTH_KEY)" "$(SECRET_KEY)" "$(AD_TOKEN)"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ This SDK supports Python 3.6 and above.
1313
Connect to the UID2 service, refresh the encryption keys, and then use the keys to decrypt an advertising token, to arrive at the corresponding advertising ID:
1414

1515
```
16-
from uid2_client import Uid2Client, decrypt_token
16+
from uid2_client import Uid2Client, decrypt
1717
1818
client = Uid2Client('https://prod.uidapi.com', 'my-auth-token', 'my-secret-key')
1919
keys = client.refresh_keys()
2020
advertising_token = 'AgAAAANRdREk+IWqqnQkZ2rZdK0TgSUP/owLryysSkUGZJT+Gy551L1WJMAZA/G2B1UMDQ20WAqwwTu6o9TexWyux0lg0HHIbmJjN6IYwo+42KC8ugaR+PX0y18qQ+3yzkxmJ/ee//4IGu/1Yq4AmO4ArXN6CeszPTxByTkysVqyQVNY2A=='
21-
decrypted_token = decrypt_token(advertising_token, keys)
21+
decrypted_token = decrypt(advertising_token, keys)
2222
print(decrypted_token.uid2)
2323
```
2424

2525
Additional examples are in the [examples] directory:
2626
* [sample_auto_refresh.py](examples/sample_auto_refresh.py)
2727
* [sample_client.py](examples/sample_client.py)
28-
* [sample_encryption.py](examples/sample_encryption.py)
28+
* Includes an example to encrypt a raw UID2 into an advertising token for UID2 sharing.
2929

3030
## Development
3131

examples/sample_client.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
from uid2_client import Uid2Client
44
from uid2_client import decrypt
5+
from uid2_client import encrypt
6+
from uid2_client.identity_scope import IdentityScope
57

8+
# this sample client decrypts an advertising token into a raw UID2
9+
# and then encrypts it into a new advertising token
10+
# to demonstrate decryption (for DSPs and sharers) and encryption (sharers only).
611

712
def _usage():
813
print('Usage: python3 sample_client.py <base_url> <auth_key> <secret_key> <ad_token>', file=sys.stderr)
@@ -19,9 +24,15 @@ def _usage():
1924

2025
client = Uid2Client(base_url, auth_key, secret_key)
2126
keys = client.refresh_keys()
22-
result = decrypt(ad_token, keys)
23-
24-
print('UID2 =', result.uid2)
25-
print('Established =', result.established)
26-
print('Site ID =', result.site_id)
27-
print('Site Key Site ID =', result.site_key_site_id)
27+
decrypt_result = decrypt(ad_token, keys)
28+
29+
print('UID2 =', decrypt_result.uid2)
30+
print('Established =', decrypt_result.established)
31+
print('Site ID =', decrypt_result.site_id)
32+
print('Site Key Site ID =', decrypt_result.site_key_site_id)
33+
34+
# Not required for DSPs, but for those using UID2 sharing functionality this shows how to encrypt a raw UID2 into
35+
# a new advertising token.
36+
# IdentityScope could be UID2 or EUID
37+
new_ad_token = encrypt(ad_token, IdentityScope.UID2, decrypt_result.uid2)
38+
print('New Ad Token =', new_ad_token)

examples/sample_encryption.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from uid2_client import Uid2Client, IdentityScope
55
from uid2_client import encrypt_data, decrypt_data
66

7+
# THIS FILE IS DEPRECATED!
8+
# To learn how to encrypt and decrypt a UID2 advertising token, see sample_client.py.
79

810
def _usage():
911
print('Usage: python3 sample_encryption.py <base_url> <auth_key> <secret_key> <ad_token> <data>', file=sys.stderr)

uid2_client/encryption.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ def _encrypt_token(uid2, identity_scope, master_key, site_key, site_id, now, tok
191191

192192

193193

194-
def encrypt(uid2, indentity_scope, keys, keyset_id=None, **kwargs):
194+
def encrypt(uid2, identity_scope, keys, keyset_id=None, **kwargs):
195195
""" Encrypt an UID2 into a sharing token
196196
197197
Args:
198198
uid2: the UID2 or EUID to be encrypted
199-
indentity_scope (IdentityScope): indicates whether the output will be for UID2 or EUID
199+
identity_scope (IdentityScope): indicates whether the output will be for UID2 or EUID
200200
keys (EncryptionKeysCollection): collection of keys to choose from for encryption
201201
keyset_id (int) : An optional keyset id to use for the encryption. Will use default keyset if left blank
202202
@@ -229,7 +229,7 @@ def encrypt(uid2, indentity_scope, keys, keyset_id=None, **kwargs):
229229
if key is None:
230230
raise EncryptionError("No Keyset Key Found")
231231

232-
return _encrypt_token(uid2, indentity_scope, master_key, key, site_id, now, token_expiry, ad_token_version)
232+
return _encrypt_token(uid2, identity_scope, master_key, key, site_id, now, token_expiry, ad_token_version)
233233

234234

235235
def encrypt_data(data, identity_scope, **kwargs):

0 commit comments

Comments
 (0)