@@ -83,7 +83,9 @@ mod linux {
83
83
...
84
84
) -> * mut gchar ;
85
85
86
- pub struct LibSecretCredential ;
86
+ pub struct LibSecretCredential {
87
+ libsecret : Library ,
88
+ }
87
89
88
90
fn label ( index_url : & str ) -> CString {
89
91
CString :: new ( format ! ( "cargo-registry:{}" , index_url) ) . unwrap ( )
@@ -105,31 +107,41 @@ mod linux {
105
107
}
106
108
}
107
109
110
+ impl LibSecretCredential {
111
+ pub fn new ( ) -> Result < LibSecretCredential , Error > {
112
+ // Dynamically load libsecret to avoid users needing to install
113
+ // additional -dev packages when building this provider.
114
+ let libsecret = unsafe { Library :: new ( "libsecret-1.so.0" ) } . context (
115
+ "failed to load libsecret: try installing the `libsecret` \
116
+ or `libsecret-1-0` package with the system package manager",
117
+ ) ?;
118
+ Ok ( Self { libsecret } )
119
+ }
120
+ }
121
+
108
122
impl Credential for LibSecretCredential {
109
123
fn perform (
110
124
& self ,
111
125
registry : & RegistryInfo < ' _ > ,
112
126
action : & Action < ' _ > ,
113
127
_args : & [ & str ] ,
114
128
) -> Result < CredentialResponse , Error > {
115
- // Dynamically load libsecret to avoid users needing to install
116
- // additional -dev packages when building this provider.
117
- let lib;
118
129
let secret_password_lookup_sync: Symbol < ' _ , SecretPasswordLookupSync > ;
119
130
let secret_password_store_sync: Symbol < ' _ , SecretPasswordStoreSync > ;
120
131
let secret_password_clear_sync: Symbol < ' _ , SecretPasswordClearSync > ;
121
132
unsafe {
122
- lib = Library :: new ( "libsecret-1.so.0" ) . context (
123
- "failed to load libsecret: try installing the `libsecret` \
124
- or `libsecret-1-0` package with the system package manager",
125
- ) ?;
126
- secret_password_lookup_sync = lib
133
+ secret_password_lookup_sync = self
134
+ . libsecret
127
135
. get ( b"secret_password_lookup_sync\0 " )
128
136
. map_err ( Box :: new) ?;
129
- secret_password_store_sync =
130
- lib. get ( b"secret_password_store_sync\0 " ) . map_err ( Box :: new) ?;
131
- secret_password_clear_sync =
132
- lib. get ( b"secret_password_clear_sync\0 " ) . map_err ( Box :: new) ?;
137
+ secret_password_store_sync = self
138
+ . libsecret
139
+ . get ( b"secret_password_store_sync\0 " )
140
+ . map_err ( Box :: new) ?;
141
+ secret_password_clear_sync = self
142
+ . libsecret
143
+ . get ( b"secret_password_clear_sync\0 " )
144
+ . map_err ( Box :: new) ?;
133
145
}
134
146
135
147
let index_url_c = CString :: new ( registry. index_url ) . unwrap ( ) ;
0 commit comments