1515
1616
1717class VortaDarwinKeyring (VortaKeyring ):
18- """Homemade macOS Keychain Service"""
18+ """
19+ Homemade macOS Keychain Service
20+
21+ TODO: Could use the newer API, as done here: https://github.com/jaraco/keyring/pull/522/files
22+ """
1923
2024 login_keychain = None
2125
@@ -42,6 +46,7 @@ def _set_keychain(self):
4246 b'i@I*I*o^Io^^{OpaquePassBuff}o^^{OpaqueSecKeychainItemRef}' ,
4347 ),
4448 ('SecKeychainGetStatus' , b'i^{OpaqueSecKeychainRef=}o^I' ),
49+ ('SecKeychainItemDelete' , b'i^{OpaqueSecKeychainItemRef=}o^I' ),
4550 ]
4651
4752 objc .loadBundleFunctions (Security , globals (), S_functions )
@@ -97,6 +102,26 @@ def get_password(self, service, repo_url):
97102 logger .debug (f"Retrieved password for repo { repo_url } " )
98103 return password
99104
105+ def remove_password (self , service , repo_url ):
106+ if not self .login_keychain :
107+ self ._set_keychain ()
108+
109+ (result , password_length , password_buffer , keychain_item ,) = SecKeychainFindGenericPassword (
110+ self .login_keychain ,
111+ len (service ),
112+ service .encode (),
113+ len (repo_url ),
114+ repo_url .encode (),
115+ None ,
116+ None ,
117+ None ,
118+ )
119+ password = None
120+ if (result == 0 ) and (password_length != 0 ):
121+ logger .debug (f"Found password for repo { repo_url } " )
122+ SecKeychainItemDelete (keychain_item , None )
123+
124+
100125 @property
101126 def is_unlocked (self ):
102127 kSecUnlockStateStatus = 1
0 commit comments