winipedia-utils 0.1.60__py3-none-any.whl → 0.1.61__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of winipedia-utils might be problematic. Click here for more details.

@@ -13,7 +13,7 @@ from cryptography.fernet import Fernet
13
13
  from cryptography.hazmat.primitives.ciphers.aead import AESGCM
14
14
 
15
15
 
16
- def get_or_create_fernet(service_name: str, username: str) -> Fernet:
16
+ def get_or_create_fernet(service_name: str, username: str) -> tuple[Fernet, bytes]:
17
17
  """Get the app secret using keyring.
18
18
 
19
19
  If it does not exist, create it with a Fernet.
@@ -23,7 +23,7 @@ def get_or_create_fernet(service_name: str, username: str) -> Fernet:
23
23
  )
24
24
 
25
25
 
26
- def get_or_create_aes_gcm(service_name: str, username: str) -> AESGCM:
26
+ def get_or_create_aes_gcm(service_name: str, username: str) -> tuple[AESGCM, bytes]:
27
27
  """Get the app secret using keyring.
28
28
 
29
29
  If it does not exist, create it with a AESGCM.
@@ -38,17 +38,33 @@ def get_or_create_key[T](
38
38
  username: str,
39
39
  key_class: Callable[[bytes], T],
40
40
  generate_key_func: Callable[..., bytes],
41
- ) -> T:
41
+ ) -> tuple[T, bytes]:
42
42
  """Get the app secret using keyring.
43
43
 
44
44
  If it does not exist, create it with the generate_func.
45
45
  """
46
- service_name = f"{service_name}_{key_class.__name__}"
47
- key = keyring.get_password(service_name, username)
46
+ key = get_key_as_str(service_name, username, key_class)
48
47
  if key is None:
49
48
  binary_key = generate_key_func()
50
49
  key = b64encode(binary_key).decode("ascii")
51
- keyring.set_password(service_name, username, key)
50
+ modified_service_name = make_service_name(service_name, key_class)
51
+ keyring.set_password(modified_service_name, username, key)
52
52
 
53
53
  binary_key = b64decode(key)
54
- return key_class(binary_key)
54
+ return key_class(binary_key), binary_key
55
+
56
+
57
+ def get_key_as_str[T](
58
+ service_name: str, username: str, key_class: Callable[[bytes], T]
59
+ ) -> str | None:
60
+ """Get the app secret using keyring.
61
+
62
+ If it does not exist, create it with the generate_func.
63
+ """
64
+ service_name = make_service_name(service_name, key_class)
65
+ return keyring.get_password(service_name, username)
66
+
67
+
68
+ def make_service_name[T](service_name: str, key_class: Callable[[bytes], T]) -> str:
69
+ """Make a service name from a service name and a key class."""
70
+ return f"{service_name}_{key_class.__name__}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: winipedia-utils
3
- Version: 0.1.60
3
+ Version: 0.1.61
4
4
  Summary: A package with many utility functions
5
5
  License: MIT
6
6
  Author: Winipedia
@@ -72,7 +72,7 @@ winipedia_utils/resources/svgs/plus_icon.svg,sha256=CHjIzOUbDH4xHlwX5MbTsdL0Hnku
72
72
  winipedia_utils/resources/svgs/svg.py,sha256=-Dw6m7cm9CHT2076oZIMx7kTQw0v_ifJajXzWcpUtI0,430
73
73
  winipedia_utils/security/__init__.py,sha256=ZBa72J6MNtYumBFMoVc0ia4jsoS7oNgjaTCW0xDb6EI,53
74
74
  winipedia_utils/security/cryptography.py,sha256=zfxSDo7aE9ecmZNC6URMSEUYRpOuJ1iESg-WCSS5HP0,822
75
- winipedia_utils/security/keyring.py,sha256=35bCXBmsFWyd7Ja2w9zHElayABeRZEaNXoEDDRb8ItQ,1698
75
+ winipedia_utils/security/keyring.py,sha256=AKpIGRh7RAWzzdIjTLZRXndxgbsX5DJxdHaRk40zw7o,2343
76
76
  winipedia_utils/setup.py,sha256=F4NneO0wVTf7JCXLorWjTOdJl36N5fLSksoWMe4p86o,1650
77
77
  winipedia_utils/testing/__init__.py,sha256=kXhB5xw02ec5xpcW_KV--9CBKdyCjnuR-NZzAJ5tq0g,51
78
78
  winipedia_utils/testing/assertions.py,sha256=0JF4mqVTnLQ1qkAL_FuTwyN_idr00rvVlta7aDdnUXA,851
@@ -94,7 +94,7 @@ winipedia_utils/testing/tests/base/utils/utils.py,sha256=dUPDrgAxlfREQb33zz23Mfz
94
94
  winipedia_utils/testing/tests/conftest.py,sha256=8RounBlI8Jq1aLaLNpv84MW4ne8Qq0aavQextDOp5ng,920
95
95
  winipedia_utils/text/__init__.py,sha256=j2bwtK6kyeHI6SnoBjpRju0C1W2n2paXBDlNjNtaUxA,48
96
96
  winipedia_utils/text/string.py,sha256=pK_VQXxSZa8HqHY1a6oMKfmN-OKteFE32eZaweCI22E,3508
97
- winipedia_utils-0.1.60.dist-info/LICENSE,sha256=3PrKJ2CWNrnyyHaC_r0wPDSukVWgmjOxHr__eQVH7cw,1087
98
- winipedia_utils-0.1.60.dist-info/METADATA,sha256=ppNOIOy5iJyYteOhpFQYmveOH9n66IdigHgxeFc1k5M,12576
99
- winipedia_utils-0.1.60.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
100
- winipedia_utils-0.1.60.dist-info/RECORD,,
97
+ winipedia_utils-0.1.61.dist-info/LICENSE,sha256=3PrKJ2CWNrnyyHaC_r0wPDSukVWgmjOxHr__eQVH7cw,1087
98
+ winipedia_utils-0.1.61.dist-info/METADATA,sha256=i3pkb0PrD_YIkUnxzzeexIYtSQZ98BATj7GNLT_EFnk,12576
99
+ winipedia_utils-0.1.61.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
100
+ winipedia_utils-0.1.61.dist-info/RECORD,,