Debian Codegraph @

keyrings/alt/file.py

raw symbols SCIP
1 import configparserscip-python python python-stdlib 3.11 configparser/__init__:
2 import getpassscip-python python python-stdlib 3.11 getpass/__init__:
3 import jsonscip-python python python-stdlib 3.11 json/__init__:
4 import osscip-python python python-stdlib 3.11 os/__init__:
5 import sysscip-python python python-stdlib 3.11 sys/__init__:
6
7 from jaraco.classesscip-python python keyrings.alt 5.0.2 `jaraco.classes`/__init__: import propertiesscip-python python keyrings.alt 5.0.2 `jaraco.classes.properties`/__init__:
8
9 from keyrings.alt.file_basescip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/__init__: import Keyringscip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/Keyring#, decodebytesscip-python python python-stdlib 3.11 base64/decodebytes()., encodebytesscip-python python python-stdlib 3.11 base64/encodebytes().
10
11 from .escapescip-python python keyrings.alt 5.0.2 escape/__init__: import escape as escape_for_iniscip-python python keyrings.alt 5.0.2 `keyrings.alt.escape`/escape().
12
13
14 class PlaintextKeyringscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#(Keyringscip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/Keyring#):
15 """Simple File Keyring with no encryption"""
16
17 priorityscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#priority. = 0.5 # type: ignore
18 "Applicable for all platforms, but not recommended"
19
20 filenamescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#filename. = 'keyring_pass.cfg'
21 schemescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#scheme. = 'no encyption'
22 versionscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#version. = '1.0'
23
24 def encryptscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#encrypt().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#encrypt().(self), passwordscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#encrypt().(password), assocscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#encrypt().(assoc)=None):
25 """Directly return the password itself, ignore associated data."""
26 return passwordscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#encrypt().(password)
27
28 def decryptscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#decrypt().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#decrypt().(self), password_encryptedscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#decrypt().(password_encrypted), assocscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#decrypt().(assoc)=None):
29 """Directly return encrypted password, ignore associated data."""
30 return password_encryptedscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/PlaintextKeyring#decrypt().(password_encrypted)
31
32
33 class Encryptedscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#:
34 """
35 PyCryptodome-backed Encryption support
36 """
37
38 schemescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#scheme. = '[PBKDF2] AES256.CFB'
39 versionscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#version. = '1.0'
40 block_sizescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#block_size. = 32
41
42 def __init__scip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#__init__().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#__init__().(self)):
43 varsscip-python python python-stdlib 3.11 builtins/vars().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#__init__().(self)).updatescip-python python python-stdlib 3.11 typing/MutableMapping#update().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#__init__().(self)._get_crypto_implscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_get_crypto_impl().())
44
45 @staticmethodscip-python python python-stdlib 3.11 builtins/staticmethod#
46 def _get_crypto_implscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_get_crypto_impl().():
47 try:
48 import Cryptodome.Random as Random # noqa: F401
49 from Cryptodome.Cipherscip-python python keyrings.alt 5.0.2 `Cryptodome.Cipher`/__init__: import AESscip-python python keyrings.alt 5.0.2 `Cryptodome.Cipher.AES`/__init__: # noqa: F401
50 from Cryptodome.Protocolscip-python python keyrings.alt 5.0.2 `Cryptodome.Protocol`/__init__: import KDFscip-python python keyrings.alt 5.0.2 `Cryptodome.Protocol.KDF`/__init__: # noqa: F401
51 except ImportErrorscip-python python python-stdlib 3.11 builtins/ImportError#:
52 import Crypto.Random as Random # noqa: F401
53 from Crypto.Cipherscip-python python keyrings.alt 5.0.2 `Crypto.Cipher`/__init__: import AESscip-python python keyrings.alt 5.0.2 `Cryptodome.Cipher.AES`/__init__: # noqa: F401
54 from Crypto.Protocolscip-python python keyrings.alt 5.0.2 `Crypto.Protocol`/__init__: import KDFscip-python python keyrings.alt 5.0.2 `Cryptodome.Protocol.KDF`/__init__: # noqa: F401
55 return locals()
56
57 def _create_cipherscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(self), passwordscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(password), saltscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(salt), IVscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(IV)):
58 """
59 Create the cipher object to encrypt or decrypt a payload.
60 """
61 pw = selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(self).KDF.PBKDF2(passwordscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(password), saltscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(salt), dkLen=selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(self).block_sizescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#block_size.)
62 return selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(self).AES.new(pw[: selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(self).block_sizescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#block_size.], selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(self).AES.MODE_CFB, IVscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(IV))
63
64 def _get_new_passwordscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_get_new_password().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_get_new_password().(self)):
65 while True:
66 password = getpassscip-python python python-stdlib 3.11 getpass/__init__:.getpassscip-python python python-stdlib 3.11 getpass/getpass().("Please set a password for your new keyring: ")
67 confirm = getpassscip-python python python-stdlib 3.11 getpass/__init__:.getpassscip-python python python-stdlib 3.11 getpass/getpass().('Please confirm the password: ')
68 if password != confirm: # pragma: no cover
69 sysscip-python python python-stdlib 3.11 sys/__init__:.stderrscip-python python python-stdlib 3.11 sys/stderr.stderr..writescip-python python python-stdlib 3.11 typing/IO#write().("Error: Your passwords didn't match\n")
70 continue
71 if '' == password.stripscip-python python python-stdlib 3.11 builtins/str#strip().(): # pragma: no cover
72 # forbid the blank password
73 sysscip-python python python-stdlib 3.11 sys/__init__:.stderrscip-python python python-stdlib 3.11 sys/stderr.stderr..writescip-python python python-stdlib 3.11 typing/IO#write().("Error: blank passwords aren't allowed.\n")
74 continue
75 return password
76
77
78 class EncryptedKeyringscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#(Encryptedscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#, Keyringscip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/Keyring#):
79 """PyCryptodome File Keyring"""
80
81 filenamescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#filename. = 'crypted_pass.cfg'
82 pw_prefixscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#pw_prefix. = b'pw:'
83
84 @propertiesscip-python python keyrings.alt 5.0.2 `jaraco.classes.properties`/__init__:.classproperty
85 def priorityscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#priority().(clsscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#priority().(cls)):
86 "Applicable for all platforms, but not recommended."
87 try:
88 clsscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#priority().(cls)._get_crypto_implscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_get_crypto_impl().()
89 except ImportErrorscip-python python python-stdlib 3.11 builtins/ImportError#: # pragma: no cover
90 raise RuntimeErrorscip-python python python-stdlib 3.11 builtins/RuntimeError#("pycryptodome/x required")
91 if not jsonscip-python python python-stdlib 3.11 json/__init__:: # pragma: no cover
92 raise RuntimeErrorscip-python python python-stdlib 3.11 builtins/RuntimeError#("JSON implementation such as simplejson required.")
93 return 0.6
94
95 @propertiesscip-python python keyrings.alt 5.0.2 `jaraco.classes.properties`/__init__:.NonDataProperty
96 def keyring_keyscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#keyring_key().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#keyring_key().(self)):
97 # _unlock or _init_file will set the key or raise an exception
98 if selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#keyring_key().(self)._check_filescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_file().():
99 selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#keyring_key().(self)._unlockscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_unlock().()
100 else:
101 selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#keyring_key().(self)._init_filescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_init_file().()
102 return selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#keyring_key().(self).keyring_keyscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#keyring_key().
103
104 def _init_filescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_init_file().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_init_file().(self)):
105 """
106 Initialize a new password file and set the reference password.
107 """
108 selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_init_file().(self).keyring_keyscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#keyring_key(). = selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_init_file().(self)._get_new_passwordscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_get_new_password().()
109 # set a reference password, used to check that the password provided
110 # matches for subsequent checks.
111 selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_init_file().(self).set_passwordscip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/Keyring#set_password().(
112 'keyring-setting', 'password reference', 'password reference value'
113 )
114 selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_init_file().(self)._write_config_valuescip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/Keyring#_write_config_value().('keyring-setting', 'scheme', selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_init_file().(self).schemescip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/FileBacked#scheme().)
115 selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_init_file().(self)._write_config_valuescip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/Keyring#_write_config_value().('keyring-setting', 'version', selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_init_file().(self).versionscip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/FileBacked#version().)
116
117 def _check_filescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_file().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_file().(self)):
118 """
119 Check if the file exists and has the expected password reference.
120 """
121 if not osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..existsscip-python python python-stdlib 3.11 genericpath/exists().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_file().(self).file_pathscip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/FileBacked#file_path().):
122 return False
123 selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_file().(self)._migratescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_migrate().()
124 config = configparserscip-python python python-stdlib 3.11 configparser/__init__:.RawConfigParserscip-python python python-stdlib 3.11 configparser/RawConfigParser#()
125 config.readscip-python python python-stdlib 3.11 configparser/RawConfigParser#read().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_file().(self).file_pathscip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/FileBacked#file_path()., encodingscip-python python python-stdlib 3.11 configparser/RawConfigParser#read().(encoding)='utf-8')
126 try:
127 config.getscip-python python python-stdlib 3.11 configparser/RawConfigParser#get().(
128 escape_for_iniscip-python python keyrings.alt 5.0.2 `keyrings.alt.escape`/escape().('keyring-setting'), escape_for_iniscip-python python keyrings.alt 5.0.2 `keyrings.alt.escape`/escape().('password reference')
129 )
130 except (configparserscip-python python python-stdlib 3.11 configparser/__init__:.NoSectionErrorscip-python python python-stdlib 3.11 configparser/NoSectionError#, configparserscip-python python python-stdlib 3.11 configparser/__init__:.NoOptionErrorscip-python python python-stdlib 3.11 configparser/NoOptionError#):
131 return False
132 try:
133 selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_file().(self)._check_schemescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_scheme().(config)
134 except AttributeErrorscip-python python python-stdlib 3.11 builtins/AttributeError#:
135 # accept a missing scheme
136 return True
137 return selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_file().(self)._check_versionscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_version().(config)
138
139 def _check_schemescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_scheme().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_scheme().(self), configscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_scheme().(config)):
140 """
141 check for a valid scheme
142
143 raise ValueError otherwise
144 raise AttributeError if missing
145 """
146 try:
147 scheme = configscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_scheme().(config).get(
148 escape_for_iniscip-python python keyrings.alt 5.0.2 `keyrings.alt.escape`/escape().('keyring-setting'), escape_for_iniscip-python python keyrings.alt 5.0.2 `keyrings.alt.escape`/escape().('scheme')
149 )
150 except (configparserscip-python python python-stdlib 3.11 configparser/__init__:.NoSectionErrorscip-python python python-stdlib 3.11 configparser/NoSectionError#, configparserscip-python python python-stdlib 3.11 configparser/__init__:.NoOptionErrorscip-python python python-stdlib 3.11 configparser/NoOptionError#):
151 raise AttributeErrorscip-python python python-stdlib 3.11 builtins/AttributeError#("Encryption scheme missing")
152
153 # remove pointless crypto module name
154 if scheme.startswith('PyCrypto '):
155 scheme = scheme[9:]
156
157 if scheme != selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_scheme().(self).schemescip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/FileBacked#scheme().:
158 raise ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#(
159 "Encryption scheme mismatch " f"(exp.: {selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_scheme().(self).schemescip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/FileBacked#scheme().}, found: {scheme})"
160 )
161
162 def _check_versionscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_version().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_version().(self), configscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_version().(config)):
163 """
164 check for a valid version
165 an existing scheme implies an existing version as well
166
167 return True, if version is valid, and False otherwise
168 """
169 try:
170 selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_version().(self).file_versionscip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/FileBacked#file_version(). = configscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_check_version().(config).get(
171 escape_for_iniscip-python python keyrings.alt 5.0.2 `keyrings.alt.escape`/escape().('keyring-setting'), escape_for_iniscip-python python keyrings.alt 5.0.2 `keyrings.alt.escape`/escape().('version')
172 )
173 except (configparserscip-python python python-stdlib 3.11 configparser/__init__:.NoSectionErrorscip-python python python-stdlib 3.11 configparser/NoSectionError#, configparserscip-python python python-stdlib 3.11 configparser/__init__:.NoOptionErrorscip-python python python-stdlib 3.11 configparser/NoOptionError#):
174 return False
175 return True
176
177 def _unlockscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_unlock().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_unlock().(self)):
178 """
179 Unlock this keyring by getting the password for the keyring from the
180 user.
181 """
182 selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_unlock().(self).keyring_keyscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#keyring_key(). = getpassscip-python python python-stdlib 3.11 getpass/__init__:.getpassscip-python python python-stdlib 3.11 getpass/getpass().(
183 'Please enter password for encrypted keyring: '
184 )
185 try:
186 ref_pw = selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_unlock().(self).get_passwordscip-python python keyrings.alt 5.0.2 `keyrings.alt.file_base`/Keyring#get_password().('keyring-setting', 'password reference')
187 assert ref_pw == 'password reference value'
188 except AssertionErrorscip-python python python-stdlib 3.11 builtins/AssertionError#:
189 selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_unlock().(self)._lockscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_lock().()
190 raise ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#("Incorrect Password")
191
192 def _lockscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_lock().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_lock().(self)):
193 """
194 Remove the keyring key from this instance.
195 """
196 del selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_lock().(self).keyring_keyscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#keyring_key().
197
198 def encryptscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#encrypt().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#encrypt().(self), passwordscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#encrypt().(password), assocscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#encrypt().(assoc)=None):
199 # encrypt password, ignore associated data
200 salt = selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#encrypt().(self).Random.get_random_bytes(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#encrypt().(self).block_sizescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#block_size.)
201 IV = selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#encrypt().(self).Random.get_random_bytes(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#encrypt().(self).AES.block_size)
202 cipher = selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#encrypt().(self)._create_cipherscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#encrypt().(self).keyring_keyscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#keyring_key()., salt, IV)
203 password_encrypted = cipher.encrypt(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#encrypt().(self).pw_prefixscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#pw_prefix. + passwordscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#encrypt().(password))
204 # Serialize the salt, IV, and encrypted password in a secure format
205 data = dictscip-python python python-stdlib 3.11 builtins/dict#(salt=salt, IV=IV, password_encrypted=password_encrypted)
206 for key in data:
207 # spare a few bytes: throw away newline from base64 encoding
208 data[key] = encodebytesscip-python python python-stdlib 3.11 base64/encodebytes().(data[key]).decodescip-python python python-stdlib 3.11 builtins/bytes#decode().()[:-1]
209 return jsonscip-python python python-stdlib 3.11 json/__init__:.dumpsscip-python python python-stdlib 3.11 json/dumps().(data).encodescip-python python python-stdlib 3.11 builtins/str#encode().()
210
211 def decryptscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#decrypt().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#decrypt().(self), password_encryptedscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#decrypt().(password_encrypted), assocscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#decrypt().(assoc)=None):
212 # unpack the encrypted payload, ignore associated data
213 data = jsonscip-python python python-stdlib 3.11 json/__init__:.loadsscip-python python python-stdlib 3.11 json/loads().(password_encryptedscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#decrypt().(password_encrypted).decode())
214 for key in data:
215 data[key] = decodebytesscip-python python python-stdlib 3.11 base64/decodebytes().(data[key].encode())
216 cipher = selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#decrypt().(self)._create_cipherscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/Encrypted#_create_cipher().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#decrypt().(self).keyring_keyscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#keyring_key()., data['salt'], data['IV'])
217 plaintext = cipher.decrypt(data['password_encrypted'])
218 assert plaintext.startswith(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#decrypt().(self).pw_prefixscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#pw_prefix.)
219 return plaintext[3:]
220
221 def _migratescip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_migrate().(selfscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_migrate().(self), keyring_passwordscip-python python keyrings.alt 5.0.2 `keyrings.alt.file`/EncryptedKeyring#_migrate().(keyring_password)=None):
222 """
223 Convert older keyrings to the current format.
224 """