@@ -12,10 +12,10 @@ unsupported.
12
12
Why?
13
13
####
14
14
15
- Existing `keyring https://pypi.org/project/keyring/ ` package is very powerful, but somewhat complex
15
+ Existing `keyring < https://pypi.org/project/keyring/ >`_ package is very powerful, but somewhat complex
16
16
and heavy.
17
17
18
- `keyctl https://pypi.org/project/keyctl/ ` uses subprocess instead of system call, which introduces
18
+ `keyctl < https://pypi.org/project/keyctl/ >`_ uses subprocess instead of system call, which introduces
19
19
possible points of failure and requires keyctl utility.
20
20
21
21
This package uses rust and PyO3 to make system calls directly to the kernel.
@@ -26,12 +26,37 @@ Usage
26
26
27
27
Use following code snippet for inspiration::
28
28
29
- import python_linux_keyutils
29
+ from python_linux_keyutils import get_secret, set_secret, invalidate_secret, KeyRingIdentifier
30
30
31
- python_linux_keyutils.set_session_secret("secret_name","secret_value")
32
- python_linux_keyutils.get_session_secret("secret_name")
33
- python_linux_keyutils.invalidate_session_secret("secret_name")
31
+ # By default, Session keyring is used
32
+ set_secret("test_key", b"test value")
33
+ print(get_secret("test_key"))
34
+ # b'test value'
34
35
36
+ # You can also specify a different keyring
37
+ set_secret("test_key_2", b"\0\0\0", key_ring=KeyRingIdentifier.User)
38
+ print(get_secret("test_key_2", key_ring=KeyRingIdentifier.User))
39
+ # b'\x00\x00\x00'
40
+
41
+ # set_secret doesn't automatically create keyring if it doesn't exist, but this can be changed with
42
+ # `create` keyword argument
43
+ set_secret("test_key_3", b"Hello kernel secrets", key_ring=KeyRingIdentifier.Process)
44
+ # Raises KeyError
45
+ set_secret("test_key_3", b"Hello kernel secrets", key_ring=KeyRingIdentifier.Process, create=True)
46
+ get_secret("test_key_3", key_ring=KeyRingIdentifier.Process)
47
+ # b'Hello kernel secrets'
48
+
49
+ **********
50
+ Exceptions
51
+ **********
52
+
53
+ The module may raise following exceptions
54
+
55
+ - **OSError **: If system call fails due to access being denied, quota exceeded, bad address, write error, etc.
56
+ - **ValueError **: If key name is invalid
57
+ - **KeyError **: If key doesn't exist, or is expired, or keyring doesn't exist
58
+ - **MemoryError **: If memory allocation fails
59
+ - **RuntimeError **: If underlying rust library reports that operation is not supported
35
60
36
61
############
37
62
Contributing
0 commit comments