Skip to content

Commit fb0300d

Browse files
refactor(ffi): annotate Diplomat getters and setters (#538)
Adds the 174 getter/setter names the new Diplomat in #536 needs, so that PR only has the actual migration. The HIR backend doesn't turn `get_`/`set_` prefixes into properties anymore, so each name here should match the property already in `Generated/`. The `IDisposable` opt-ins are in #569, right above this one. The Diplomat we pin today drops these attrs, so there's no generated diff. I checked by regenerating with the pinned tool. Heads up, that tool can't regenerate master as-is: its syn chokes on `#[unsafe(no_mangle)]`, so I swapped in `#[no_mangle]` locally for the check. Tested: clippy clean, `Devolutions.Picky.Tests` 26/26 locally. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7341d53 commit fb0300d

18 files changed

Lines changed: 174 additions & 0 deletions

‎ffi/src/argon2.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,25 @@ pub mod ffi {
2323
}
2424

2525
/// Sets the memory size in 1 KiB blocks. Between 1 and (2^32)-1.
26+
#[diplomat::attr(auto, setter = "m_cost")]
2627
pub fn set_m_cost(&mut self, value: u32) {
2728
self.m_cost = value;
2829
}
2930

3031
/// Sets the number of iterations. Between 1 and (2^32)-1.
32+
#[diplomat::attr(auto, setter = "t_cost")]
3133
pub fn set_t_cost(&mut self, value: u32) {
3234
self.t_cost = value;
3335
}
3436

3537
/// Sets the degree of parallelism. Between 1 and 255.
38+
#[diplomat::attr(auto, setter = "p_cost")]
3639
pub fn set_p_cost(&mut self, value: u32) {
3740
self.p_cost = value;
3841
}
3942

4043
/// Sets the size of the KDF output in bytes. Default 32.
44+
#[diplomat::attr(auto, setter = "output_len")]
4145
pub fn set_output_len(&mut self, value: usize) {
4246
self.output_len = Some(value);
4347
}

‎ffi/src/date.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,38 @@ pub mod ffi {
2626
Ok(Box::new(date))
2727
}
2828

29+
#[diplomat::attr(auto, getter = "timestamp")]
2930
pub fn get_timestamp(&self) -> Result<i64, Box<PickyError>> {
3031
let date = time::OffsetDateTime::try_from(self.0.clone())?;
3132
Ok(date.unix_timestamp())
3233
}
3334

35+
#[diplomat::attr(auto, getter = "month")]
3436
pub fn get_month(&self) -> u8 {
3537
self.0.month()
3638
}
3739

40+
#[diplomat::attr(auto, getter = "day")]
3841
pub fn get_day(&self) -> u8 {
3942
self.0.day()
4043
}
4144

45+
#[diplomat::attr(auto, getter = "hour")]
4246
pub fn get_hour(&self) -> u8 {
4347
self.0.hour()
4448
}
4549

50+
#[diplomat::attr(auto, getter = "minute")]
4651
pub fn get_minute(&self) -> u8 {
4752
self.0.minute()
4853
}
4954

55+
#[diplomat::attr(auto, getter = "second")]
5056
pub fn get_second(&self) -> u8 {
5157
self.0.second()
5258
}
5359

60+
#[diplomat::attr(auto, getter = "year")]
5461
pub fn get_year(&self) -> u16 {
5562
self.0.year()
5663
}

‎ffi/src/error.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ pub mod ffi {
245245
}
246246

247247
/// Returns the error kind.
248+
#[diplomat::attr(auto, getter = "kind")]
248249
pub fn get_kind(&self) -> PickyErrorKind {
249250
self.0.kind
250251
}

‎ffi/src/jwt.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pub mod ffi {
111111

112112
/// Returns the content type.
113113
// TODO: support for optional string in return position
114+
#[diplomat::attr(auto, getter = "content_type")]
114115
pub fn get_content_type(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box<PickyError>> {
115116
write!(writeable, "{}", self.0.header.cty.as_deref().unwrap_or(""))?;
116117
writeable.flush();
@@ -119,13 +120,15 @@ pub mod ffi {
119120

120121
/// Returns the key ID.
121122
// TODO: support for optional string in return position
123+
#[diplomat::attr(auto, getter = "kid")]
122124
pub fn get_kid(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box<PickyError>> {
123125
write!(writeable, "{}", self.0.header.kid.as_deref().unwrap_or(""))?;
124126
writeable.flush();
125127
Ok(())
126128
}
127129

128130
/// Returns the header as a JSON encoded payload.
131+
#[diplomat::attr(auto, getter = "header")]
129132
pub fn get_header(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box<PickyError>> {
130133
let header = serde_json::to_string(&self.0.header)?;
131134
write!(writeable, "{header}")?;
@@ -134,6 +137,7 @@ pub mod ffi {
134137
}
135138

136139
/// Returns the claims as a JSON encoded payload.
140+
#[diplomat::attr(auto, getter = "claims")]
137141
pub fn get_claims(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box<PickyError>> {
138142
let claims = serde_json::to_string(&self.0.state.claims)?;
139143
write!(writeable, "{claims}")?;
@@ -183,14 +187,17 @@ pub mod ffi {
183187
}))
184188
}
185189

190+
#[diplomat::attr(auto, setter = "algorithm")]
186191
pub fn set_algorithm(&mut self, alg: JwsAlg) {
187192
self.0.alg = alg;
188193
}
189194

195+
#[diplomat::attr(auto, setter = "content_type")]
190196
pub fn set_content_type(&mut self, cty: &str) {
191197
self.0.cty = Some(cty.to_owned());
192198
}
193199

200+
#[diplomat::attr(auto, setter = "kid")]
194201
pub fn set_kid(&mut self, kid: &str) {
195202
self.0.kid = Some(kid.to_owned());
196203
}
@@ -247,6 +254,7 @@ pub mod ffi {
247254
/// Sets the given JSON payload.
248255
///
249256
/// Claims should be a valid JSON payload.
257+
#[diplomat::attr(auto, setter = "claims")]
250258
pub fn set_claims(&mut self, claims: &str) -> Result<(), Box<PickyError>> {
251259
let claims = serde_json::from_str(claims)?;
252260
self.0.claims = claims;

‎ffi/src/key.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ pub mod ffi {
165165
}
166166

167167
/// Retrieves the key kind for this private key.
168+
#[diplomat::attr(auto, getter = "kind")]
168169
pub fn get_kind(&self) -> KeyKind {
169170
self.0.kind().into()
170171
}
@@ -207,6 +208,7 @@ pub mod ffi {
207208
}
208209

209210
/// Retrieves the key kind for this public key.
211+
#[diplomat::attr(auto, getter = "kind")]
210212
pub fn get_kind(&self) -> KeyKind {
211213
self.0.kind().into()
212214
}

‎ffi/src/pem.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ pub mod ffi {
4343
// }
4444

4545
/// Returns the length of the data contained by this PEM object.
46+
#[diplomat::attr(auto, getter = "data_length")]
4647
pub fn get_data_length(&self) -> u64 {
4748
self.0.data().len() as u64
4849
}
4950

5051
/// Returns the label of this PEM object.
52+
#[diplomat::attr(auto, getter = "label")]
5153
pub fn get_label(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box<PickyError>> {
5254
write!(writeable, "{}", self.0.label())?;
5355
writeable.flush();

‎ffi/src/pkcs12.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ pub mod ffi {
9090

9191
/// Continue parsing even if conversion to high level picky data structure fails (e.g. due to
9292
/// unsupported private key or certificate kind)
93+
#[diplomat::attr(auto, setter = "skip_soft_parsing_errors")]
9394
pub fn set_skip_soft_parsing_errors(&mut self, value: bool) {
9495
self.0.skip_soft_parsing_errors = value;
9596
}
9697

9798
/// Continue parsing even if decryption fails and keep data in encrypted form
99+
#[diplomat::attr(auto, setter = "skip_decryption_errors")]
98100
pub fn set_skip_decryption_errors(&mut self, value: bool) {
99101
self.0.skip_decryption_errors = value;
100102
}
@@ -104,6 +106,7 @@ pub mod ffi {
104106
/// This is useful for parsing available unencrypted data from
105107
/// password-protected PFX files. Also could be useful if PFX integrity has been intentionally
106108
/// violated for testing purposes.
109+
#[diplomat::attr(auto, setter = "skip_mac_validation")]
107110
pub fn set_skip_mac_validation(&mut self, value: bool) {
108111
self.0.skip_mac_validation = value;
109112
}
@@ -151,6 +154,7 @@ pub mod ffi {
151154
Box::new(Self(pkcs12::Pkcs12Attribute::new_local_key_id(value.to_vec())))
152155
}
153156

157+
#[diplomat::attr(auto, getter = "kind")]
154158
pub fn get_kind(&self) -> Pkcs12AttributeKind {
155159
match self.0.kind() {
156160
pkcs12::Pkcs12AttributeKind::FriendlyName(..) => Pkcs12AttributeKind::FriendlyName,
@@ -159,6 +163,7 @@ pub mod ffi {
159163
}
160164
}
161165

166+
#[diplomat::attr(auto, getter = "friendly_name")]
162167
pub fn get_friendly_name(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box<PickyError>> {
163168
use std::fmt::Write as _;
164169

@@ -226,6 +231,7 @@ pub mod ffi {
226231
self.0.add_attribute(attribute.0.clone());
227232
}
228233

234+
#[diplomat::attr(auto, getter = "kind")]
229235
pub fn get_kind(&self) -> SafeBagKind {
230236
match self.0.kind() {
231237
pkcs12::SafeBagKind::PrivateKey(..) => SafeBagKind::PrivateKey,
@@ -239,6 +245,7 @@ pub mod ffi {
239245
}
240246
}
241247

248+
#[diplomat::attr(auto, getter = "private_key")]
242249
pub fn get_private_key(&self) -> Option<Box<PrivateKey>> {
243250
if let pkcs12::SafeBagKind::PrivateKey(key) | pkcs12::SafeBagKind::EncryptedPrivateKey { key, .. } =
244251
self.0.kind()
@@ -249,6 +256,7 @@ pub mod ffi {
249256
}
250257
}
251258

259+
#[diplomat::attr(auto, getter = "certificate")]
252260
pub fn get_certificate(&self) -> Option<Box<Cert>> {
253261
if let pkcs12::SafeBagKind::Certificate(cert) = self.0.kind() {
254262
Some(Box::new(Cert(cert.clone())))
@@ -354,6 +362,7 @@ pub mod ffi {
354362
Ok(())
355363
}
356364

365+
#[diplomat::attr(auto, setter = "hmac_algorithm")]
357366
pub fn set_hmac_algorithm(&mut self, mac_algorithm: &Pkcs12MacAlgorithmHmac) {
358367
self.hmac_algorithm = Some(mac_algorithm.0.clone());
359368
}

‎ffi/src/putty.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,14 @@ pub mod ffi {
170170
}
171171

172172
/// Get the public key from the PPK key file.
173+
#[diplomat::attr(auto, getter = "public_key")]
173174
pub fn get_public_key(&self) -> Result<Box<PublicKey>, Box<PickyError>> {
174175
let key = self.0.public_key()?;
175176
Ok(Box::new(PublicKey(key)))
176177
}
177178

178179
/// Get the private key from the PPK key file.
180+
#[diplomat::attr(auto, getter = "private_key")]
179181
pub fn get_private_key(&self) -> Result<Box<PrivateKey>, Box<PickyError>> {
180182
let key = self.0.private_key()?;
181183
Ok(Box::new(PrivateKey(key)))
@@ -188,16 +190,19 @@ pub mod ffi {
188190
}
189191

190192
/// Get the PPK key file version.
193+
#[diplomat::attr(auto, getter = "version")]
191194
pub fn get_version(&self) -> PuttyPpkVersion {
192195
self.0.version().into()
193196
}
194197

195198
/// Get the PPK key file algorithm.
199+
#[diplomat::attr(auto, getter = "algorithm")]
196200
pub fn get_algorithm(&self) -> PuttyPpkKeyAlgorithm {
197201
self.0.algorithm().into()
198202
}
199203

200204
/// Get the PPK key file comment.
205+
#[diplomat::attr(auto, getter = "comment")]
201206
pub fn get_comment(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box<PickyError>> {
202207
writeable.write_str(self.0.comment())?;
203208
writeable.flush();
@@ -272,6 +277,7 @@ pub mod ffi {
272277
}
273278

274279
/// Get the comment of the public key.
280+
#[diplomat::attr(auto, getter = "comment")]
275281
pub fn get_comment(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box<PickyError>> {
276282
writeable.write_str(self.0.comment())?;
277283
writeable.flush();
@@ -303,22 +309,27 @@ pub mod ffi {
303309
pub struct PuttyArgon2Params(picky::putty::Argon2Params);
304310

305311
impl PuttyArgon2Params {
312+
#[diplomat::attr(auto, getter = "flavor")]
306313
pub fn get_flavor(&self) -> PuttyArgon2Flavour {
307314
self.0.flavor.into()
308315
}
309316

317+
#[diplomat::attr(auto, getter = "memory")]
310318
pub fn get_memory(&self) -> u32 {
311319
self.0.memory
312320
}
313321

322+
#[diplomat::attr(auto, getter = "passes")]
314323
pub fn get_passes(&self) -> u32 {
315324
self.0.passes
316325
}
317326

327+
#[diplomat::attr(auto, getter = "parallelism")]
318328
pub fn get_parallelism(&self) -> u32 {
319329
self.0.parallelism
320330
}
321331

332+
#[diplomat::attr(auto, getter = "salt")]
322333
pub fn get_salt(&self) -> Box<VecU8> {
323334
Box::new(VecU8(self.0.salt.to_vec()))
324335
}
@@ -355,18 +366,22 @@ pub mod ffi {
355366
self.0.clone().argon2_flavour(argon2_flavour.into());
356367
}
357368

369+
#[diplomat::attr(auto, setter = "argon2_memory")]
358370
pub fn set_argon2_memory(&mut self, argon2_memory: u32) {
359371
self.0.clone().argon2_memory(argon2_memory);
360372
}
361373

374+
#[diplomat::attr(auto, setter = "argon2_passes")]
362375
pub fn set_argon2_passes(&mut self, argon2_passes: u32) {
363376
self.0.clone().argon2_passes(argon2_passes);
364377
}
365378

379+
#[diplomat::attr(auto, setter = "argon2_parallelism")]
366380
pub fn set_argon2_parallelism(&mut self, argon2_parallelism: u32) {
367381
self.0.clone().argon2_parallelism(argon2_parallelism);
368382
}
369383

384+
#[diplomat::attr(auto, setter = "argon2_salt_size")]
370385
pub fn set_argon2_salt_size(&mut self, argon2_salt_size: u32) {
371386
self.0.clone().argon2_salt_size(argon2_salt_size);
372387
}

0 commit comments

Comments
 (0)