@@ -12,10 +12,10 @@ unsupported.
1212Why?
1313####
1414
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
1616and heavy.
1717
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
1919possible points of failure and requires keyctl utility.
2020
2121This package uses rust and PyO3 to make system calls directly to the kernel.
@@ -26,12 +26,37 @@ Usage
2626
2727Use following code snippet for inspiration::
2828
29- import python_linux_keyutils
29+ from python_linux_keyutils import get_secret, set_secret, invalidate_secret, KeyRingIdentifier
3030
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'
3435
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
3560
3661############
3762Contributing
0 commit comments