xi-keyring

simple and extensible alternative for gnome-keyring
git clone https://git.ce9e.org/xi-keyring.git

commit
e73e6be734b40354774318e204c6e6c616c7b3ab
parent
c486ff3137e3b2f71806c3deb2d5f17c7af668a7
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2026-05-24 07:57
refactor: use pathlib

Diffstat

M xikeyring/__main__.py 4 ++--
M xikeyring/keyring.py 12 ++++++------

2 files changed, 8 insertions, 8 deletions


diff --git a/xikeyring/__main__.py b/xikeyring/__main__.py

@@ -33,6 +33,7 @@ def parse_args():
   33    33         '--store',
   34    34         '-s',
   35    35         help='path to the store file',
   -1    36         type=Path,
   36    37         default=get_data_home() / 'xikeyring.db',
   37    38     )
   38    39     parser.add_argument(
@@ -46,8 +47,7 @@ pr_set(dumpable=False)
   46    47 args = parse_args()
   47    48 keyring = KeyringProxy(args.store)
   48    49 if args.dump:
   49    -1     with open(keyring.path, 'rb') as fh:
   50    -1         encrypted = fh.read()
   -1    50     encrypted = keyring.path.read_bytes()
   51    51     decrypted = keyring.crypt.decrypt(encrypted)
   52    52     print(decrypted.decode('utf-8'))
   53    53 elif args.restore:

diff --git a/xikeyring/keyring.py b/xikeyring/keyring.py

@@ -2,6 +2,7 @@ import base64
    2     2 import json
    3     3 import os
    4     4 from dataclasses import dataclass
   -1     5 from pathlib import Path
    5     6 
    6     7 import argon2
    7     8 from cryptography.fernet import Fernet
@@ -30,7 +31,7 @@ class Item:
   30    31     app_id: str
   31    32 
   32    33 
   33    -1 def write_bytes(path: str, data: bytes) -> int:
   -1    34 def write_bytes(path: Path, data: bytes) -> int:
   34    35     flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC
   35    36     fd = os.open(path, flags, mode=0o600)
   36    37     try:
@@ -88,11 +89,11 @@ class Crypt:
   88    89 
   89    90 
   90    91 class Keyring:
   91    -1     def __init__(self, path: str):
   -1    92     def __init__(self, path: Path):
   92    93         self.path = path
   93    94         self.prompt = Prompt()
   94    95 
   95    -1         if os.path.exists(self.path):
   -1    96         if self.path.exists():
   96    97             while True:
   97    98                 self.crypt = self._get_crypt()
   98    99                 try:
@@ -114,8 +115,7 @@ class Keyring:
  114   115         return Crypt(password)
  115   116 
  116   117     def _read(self) -> dict[int, Item]:
  117    -1         with open(self.path, 'rb') as fh:
  118    -1             encrypted = fh.read()
   -1   118         encrypted = self.path.read_bytes()
  119   119         decrypted = self.crypt.decrypt(encrypted)
  120   120         raw = json.loads(decrypted)
  121   121         return {
@@ -206,7 +206,7 @@ class Keyring:
  206   206 
  207   207 
  208   208 class KeyringProxy:
  209    -1     def __init__(self, path):
   -1   209     def __init__(self, path: Path):
  210   210         self.path = path
  211   211         self.keyring = None
  212   212