From 83a36c914ba3bd2781247127965297fc00ea57b2 Mon Sep 17 00:00:00 2001 From: Junyi Ou Date: Tue, 29 Sep 2026 14:52:28 -0400 Subject: [PATCH] refactor(ffi): annotate Diplomat getters and setters Adds the `#[diplomat::attr(auto, getter/setter)]` markers the next Diplomat needs: 174 getter/setter names, since it no longer turns `get_`/`set_` prefixes into C# properties. The Diplomat pinned today drops these attributes, so the generated C# doesn't change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ffi/src/argon2.rs | 4 +++ ffi/src/date.rs | 7 +++++ ffi/src/error.rs | 1 + ffi/src/jwt.rs | 8 +++++ ffi/src/key.rs | 2 ++ ffi/src/pem.rs | 2 ++ ffi/src/pkcs12.rs | 9 ++++++ ffi/src/putty.rs | 15 ++++++++++ ffi/src/ssh.rs | 21 +++++++++++++ ffi/src/utils.rs | 1 + ffi/src/x509/algorithm_identifier.rs | 4 +++ ffi/src/x509/attribute.rs | 44 ++++++++++++++++++++++++++++ ffi/src/x509/extension.rs | 10 +++++++ ffi/src/x509/mod.rs | 16 ++++++++++ ffi/src/x509/name.rs | 5 ++++ ffi/src/x509/singer_info.rs | 10 +++++++ ffi/src/x509/string.rs | 3 ++ ffi/src/x509/time.rs | 12 ++++++++ 18 files changed, 174 insertions(+) diff --git a/ffi/src/argon2.rs b/ffi/src/argon2.rs index 14063d68..b3a2b810 100644 --- a/ffi/src/argon2.rs +++ b/ffi/src/argon2.rs @@ -23,21 +23,25 @@ pub mod ffi { } /// Sets the memory size in 1 KiB blocks. Between 1 and (2^32)-1. + #[diplomat::attr(auto, setter = "m_cost")] pub fn set_m_cost(&mut self, value: u32) { self.m_cost = value; } /// Sets the number of iterations. Between 1 and (2^32)-1. + #[diplomat::attr(auto, setter = "t_cost")] pub fn set_t_cost(&mut self, value: u32) { self.t_cost = value; } /// Sets the degree of parallelism. Between 1 and 255. + #[diplomat::attr(auto, setter = "p_cost")] pub fn set_p_cost(&mut self, value: u32) { self.p_cost = value; } /// Sets the size of the KDF output in bytes. Default 32. + #[diplomat::attr(auto, setter = "output_len")] pub fn set_output_len(&mut self, value: usize) { self.output_len = Some(value); } diff --git a/ffi/src/date.rs b/ffi/src/date.rs index 3b60ccc1..5a8366a9 100644 --- a/ffi/src/date.rs +++ b/ffi/src/date.rs @@ -26,31 +26,38 @@ pub mod ffi { Ok(Box::new(date)) } + #[diplomat::attr(auto, getter = "timestamp")] pub fn get_timestamp(&self) -> Result> { let date = time::OffsetDateTime::try_from(self.0.clone())?; Ok(date.unix_timestamp()) } + #[diplomat::attr(auto, getter = "month")] pub fn get_month(&self) -> u8 { self.0.month() } + #[diplomat::attr(auto, getter = "day")] pub fn get_day(&self) -> u8 { self.0.day() } + #[diplomat::attr(auto, getter = "hour")] pub fn get_hour(&self) -> u8 { self.0.hour() } + #[diplomat::attr(auto, getter = "minute")] pub fn get_minute(&self) -> u8 { self.0.minute() } + #[diplomat::attr(auto, getter = "second")] pub fn get_second(&self) -> u8 { self.0.second() } + #[diplomat::attr(auto, getter = "year")] pub fn get_year(&self) -> u16 { self.0.year() } diff --git a/ffi/src/error.rs b/ffi/src/error.rs index f8948687..d20e3ae4 100644 --- a/ffi/src/error.rs +++ b/ffi/src/error.rs @@ -245,6 +245,7 @@ pub mod ffi { } /// Returns the error kind. + #[diplomat::attr(auto, getter = "kind")] pub fn get_kind(&self) -> PickyErrorKind { self.0.kind } diff --git a/ffi/src/jwt.rs b/ffi/src/jwt.rs index 851c9369..c6200b56 100644 --- a/ffi/src/jwt.rs +++ b/ffi/src/jwt.rs @@ -111,6 +111,7 @@ pub mod ffi { /// Returns the content type. // TODO: support for optional string in return position + #[diplomat::attr(auto, getter = "content_type")] pub fn get_content_type(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { write!(writeable, "{}", self.0.header.cty.as_deref().unwrap_or(""))?; writeable.flush(); @@ -119,6 +120,7 @@ pub mod ffi { /// Returns the key ID. // TODO: support for optional string in return position + #[diplomat::attr(auto, getter = "kid")] pub fn get_kid(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { write!(writeable, "{}", self.0.header.kid.as_deref().unwrap_or(""))?; writeable.flush(); @@ -126,6 +128,7 @@ pub mod ffi { } /// Returns the header as a JSON encoded payload. + #[diplomat::attr(auto, getter = "header")] pub fn get_header(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { let header = serde_json::to_string(&self.0.header)?; write!(writeable, "{header}")?; @@ -134,6 +137,7 @@ pub mod ffi { } /// Returns the claims as a JSON encoded payload. + #[diplomat::attr(auto, getter = "claims")] pub fn get_claims(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { let claims = serde_json::to_string(&self.0.state.claims)?; write!(writeable, "{claims}")?; @@ -183,14 +187,17 @@ pub mod ffi { })) } + #[diplomat::attr(auto, setter = "algorithm")] pub fn set_algorithm(&mut self, alg: JwsAlg) { self.0.alg = alg; } + #[diplomat::attr(auto, setter = "content_type")] pub fn set_content_type(&mut self, cty: &str) { self.0.cty = Some(cty.to_owned()); } + #[diplomat::attr(auto, setter = "kid")] pub fn set_kid(&mut self, kid: &str) { self.0.kid = Some(kid.to_owned()); } @@ -247,6 +254,7 @@ pub mod ffi { /// Sets the given JSON payload. /// /// Claims should be a valid JSON payload. + #[diplomat::attr(auto, setter = "claims")] pub fn set_claims(&mut self, claims: &str) -> Result<(), Box> { let claims = serde_json::from_str(claims)?; self.0.claims = claims; diff --git a/ffi/src/key.rs b/ffi/src/key.rs index 5aa2a9a7..e881ae22 100644 --- a/ffi/src/key.rs +++ b/ffi/src/key.rs @@ -165,6 +165,7 @@ pub mod ffi { } /// Retrieves the key kind for this private key. + #[diplomat::attr(auto, getter = "kind")] pub fn get_kind(&self) -> KeyKind { self.0.kind().into() } @@ -207,6 +208,7 @@ pub mod ffi { } /// Retrieves the key kind for this public key. + #[diplomat::attr(auto, getter = "kind")] pub fn get_kind(&self) -> KeyKind { self.0.kind().into() } diff --git a/ffi/src/pem.rs b/ffi/src/pem.rs index e03c3451..3204fe1f 100644 --- a/ffi/src/pem.rs +++ b/ffi/src/pem.rs @@ -43,11 +43,13 @@ pub mod ffi { // } /// Returns the length of the data contained by this PEM object. + #[diplomat::attr(auto, getter = "data_length")] pub fn get_data_length(&self) -> u64 { self.0.data().len() as u64 } /// Returns the label of this PEM object. + #[diplomat::attr(auto, getter = "label")] pub fn get_label(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { write!(writeable, "{}", self.0.label())?; writeable.flush(); diff --git a/ffi/src/pkcs12.rs b/ffi/src/pkcs12.rs index cd184d1c..12ce57d7 100644 --- a/ffi/src/pkcs12.rs +++ b/ffi/src/pkcs12.rs @@ -90,11 +90,13 @@ pub mod ffi { /// Continue parsing even if conversion to high level picky data structure fails (e.g. due to /// unsupported private key or certificate kind) + #[diplomat::attr(auto, setter = "skip_soft_parsing_errors")] pub fn set_skip_soft_parsing_errors(&mut self, value: bool) { self.0.skip_soft_parsing_errors = value; } /// Continue parsing even if decryption fails and keep data in encrypted form + #[diplomat::attr(auto, setter = "skip_decryption_errors")] pub fn set_skip_decryption_errors(&mut self, value: bool) { self.0.skip_decryption_errors = value; } @@ -104,6 +106,7 @@ pub mod ffi { /// This is useful for parsing available unencrypted data from /// password-protected PFX files. Also could be useful if PFX integrity has been intentionally /// violated for testing purposes. + #[diplomat::attr(auto, setter = "skip_mac_validation")] pub fn set_skip_mac_validation(&mut self, value: bool) { self.0.skip_mac_validation = value; } @@ -151,6 +154,7 @@ pub mod ffi { Box::new(Self(pkcs12::Pkcs12Attribute::new_local_key_id(value.to_vec()))) } + #[diplomat::attr(auto, getter = "kind")] pub fn get_kind(&self) -> Pkcs12AttributeKind { match self.0.kind() { pkcs12::Pkcs12AttributeKind::FriendlyName(..) => Pkcs12AttributeKind::FriendlyName, @@ -159,6 +163,7 @@ pub mod ffi { } } + #[diplomat::attr(auto, getter = "friendly_name")] pub fn get_friendly_name(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { use std::fmt::Write as _; @@ -226,6 +231,7 @@ pub mod ffi { self.0.add_attribute(attribute.0.clone()); } + #[diplomat::attr(auto, getter = "kind")] pub fn get_kind(&self) -> SafeBagKind { match self.0.kind() { pkcs12::SafeBagKind::PrivateKey(..) => SafeBagKind::PrivateKey, @@ -239,6 +245,7 @@ pub mod ffi { } } + #[diplomat::attr(auto, getter = "private_key")] pub fn get_private_key(&self) -> Option> { if let pkcs12::SafeBagKind::PrivateKey(key) | pkcs12::SafeBagKind::EncryptedPrivateKey { key, .. } = self.0.kind() @@ -249,6 +256,7 @@ pub mod ffi { } } + #[diplomat::attr(auto, getter = "certificate")] pub fn get_certificate(&self) -> Option> { if let pkcs12::SafeBagKind::Certificate(cert) = self.0.kind() { Some(Box::new(Cert(cert.clone()))) @@ -354,6 +362,7 @@ pub mod ffi { Ok(()) } + #[diplomat::attr(auto, setter = "hmac_algorithm")] pub fn set_hmac_algorithm(&mut self, mac_algorithm: &Pkcs12MacAlgorithmHmac) { self.hmac_algorithm = Some(mac_algorithm.0.clone()); } diff --git a/ffi/src/putty.rs b/ffi/src/putty.rs index 0c3c60ce..1787d8ca 100644 --- a/ffi/src/putty.rs +++ b/ffi/src/putty.rs @@ -170,12 +170,14 @@ pub mod ffi { } /// Get the public key from the PPK key file. + #[diplomat::attr(auto, getter = "public_key")] pub fn get_public_key(&self) -> Result, Box> { let key = self.0.public_key()?; Ok(Box::new(PublicKey(key))) } /// Get the private key from the PPK key file. + #[diplomat::attr(auto, getter = "private_key")] pub fn get_private_key(&self) -> Result, Box> { let key = self.0.private_key()?; Ok(Box::new(PrivateKey(key))) @@ -188,16 +190,19 @@ pub mod ffi { } /// Get the PPK key file version. + #[diplomat::attr(auto, getter = "version")] pub fn get_version(&self) -> PuttyPpkVersion { self.0.version().into() } /// Get the PPK key file algorithm. + #[diplomat::attr(auto, getter = "algorithm")] pub fn get_algorithm(&self) -> PuttyPpkKeyAlgorithm { self.0.algorithm().into() } /// Get the PPK key file comment. + #[diplomat::attr(auto, getter = "comment")] pub fn get_comment(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { writeable.write_str(self.0.comment())?; writeable.flush(); @@ -272,6 +277,7 @@ pub mod ffi { } /// Get the comment of the public key. + #[diplomat::attr(auto, getter = "comment")] pub fn get_comment(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { writeable.write_str(self.0.comment())?; writeable.flush(); @@ -303,22 +309,27 @@ pub mod ffi { pub struct PuttyArgon2Params(picky::putty::Argon2Params); impl PuttyArgon2Params { + #[diplomat::attr(auto, getter = "flavor")] pub fn get_flavor(&self) -> PuttyArgon2Flavour { self.0.flavor.into() } + #[diplomat::attr(auto, getter = "memory")] pub fn get_memory(&self) -> u32 { self.0.memory } + #[diplomat::attr(auto, getter = "passes")] pub fn get_passes(&self) -> u32 { self.0.passes } + #[diplomat::attr(auto, getter = "parallelism")] pub fn get_parallelism(&self) -> u32 { self.0.parallelism } + #[diplomat::attr(auto, getter = "salt")] pub fn get_salt(&self) -> Box { Box::new(VecU8(self.0.salt.to_vec())) } @@ -355,18 +366,22 @@ pub mod ffi { self.0.clone().argon2_flavour(argon2_flavour.into()); } + #[diplomat::attr(auto, setter = "argon2_memory")] pub fn set_argon2_memory(&mut self, argon2_memory: u32) { self.0.clone().argon2_memory(argon2_memory); } + #[diplomat::attr(auto, setter = "argon2_passes")] pub fn set_argon2_passes(&mut self, argon2_passes: u32) { self.0.clone().argon2_passes(argon2_passes); } + #[diplomat::attr(auto, setter = "argon2_parallelism")] pub fn set_argon2_parallelism(&mut self, argon2_parallelism: u32) { self.0.clone().argon2_parallelism(argon2_parallelism); } + #[diplomat::attr(auto, setter = "argon2_salt_size")] pub fn set_argon2_salt_size(&mut self, argon2_salt_size: u32) { self.0.clone().argon2_salt_size(argon2_salt_size); } diff --git a/ffi/src/ssh.rs b/ffi/src/ssh.rs index f06e0089..50b1d99a 100644 --- a/ffi/src/ssh.rs +++ b/ffi/src/ssh.rs @@ -88,6 +88,7 @@ pub mod ffi { Ok(()) } + #[diplomat::attr(auto, getter = "comment")] pub fn get_comment(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { writeable.write_str(&self.0.comment)?; writeable.flush(); @@ -228,12 +229,14 @@ pub mod ffi { Ok(()) } + #[diplomat::attr(auto, getter = "cipher_name")] pub fn get_cipher_name(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { writeable.write_str(&self.0.cipher_name)?; writeable.flush(); Ok(()) } + #[diplomat::attr(auto, getter = "comment")] pub fn get_comment(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { writeable.write_str(&self.0.comment)?; writeable.flush(); @@ -276,51 +279,61 @@ pub mod ffi { } /// Required + #[diplomat::attr(auto, setter = "cert_key_type")] pub fn set_cert_key_type(&self, key_type: SshCertKeyType) { self.0.cert_key_type(key_type.into()); } /// Required + #[diplomat::attr(auto, setter = "key")] pub fn set_key(&self, key: &SshPublicKey) { self.0.key(key.0.clone()); } /// Optional (set to 0 by default) + #[diplomat::attr(auto, setter = "serial")] pub fn set_serial(&self, serial: u64) { self.0.serial(serial); } /// Required + #[diplomat::attr(auto, setter = "cert_type")] pub fn set_cert_type(&self, cert_type: SshCertType) { self.0.cert_type(cert_type.into()); } /// Optional + #[diplomat::attr(auto, setter = "key_id")] pub fn set_key_id(&self, key_id: &str) { self.0.key_id(key_id.to_owned()); } /// Required + #[diplomat::attr(auto, setter = "valid_before")] pub fn set_valid_before(&self, valid_before: u64) { self.0.valid_before(valid_before); } /// Required + #[diplomat::attr(auto, setter = "valid_after")] pub fn set_valid_after(&self, valid_after: u64) { self.0.valid_after(valid_after); } /// Required + #[diplomat::attr(auto, setter = "signature_key")] pub fn set_signature_key(&self, signature_key: &SshPrivateKey) { self.0.signature_key(signature_key.0.clone()); } /// Optional. RsaPkcs1v15 with SHA256 is used by default. + #[diplomat::attr(auto, setter = "signature_algo")] pub fn set_signature_algo(&self, signature_algo: &SignatureAlgorithm) { self.0.signature_algo(signature_algo.0); } /// Optional + #[diplomat::attr(auto, setter = "comment")] pub fn set_comment(&self, comment: &str) { self.0.comment(comment.to_owned()); } @@ -353,36 +366,44 @@ pub mod ffi { Ok(()) } + #[diplomat::attr(auto, getter = "public_key")] pub fn get_public_key(&self) -> Box { Box::new(SshPublicKey(self.0.public_key.clone())) } + #[diplomat::attr(auto, getter = "ssh_key_type")] pub fn get_ssh_key_type(&self) -> SshCertKeyType { self.0.cert_key_type.into() } + #[diplomat::attr(auto, getter = "cert_type")] pub fn get_cert_type(&self) -> SshCertType { self.0.cert_type.into() } + #[diplomat::attr(auto, getter = "valid_after")] pub fn get_valid_after(&self) -> u64 { self.0.valid_after.0 } + #[diplomat::attr(auto, getter = "valid_before")] pub fn get_valid_before(&self) -> u64 { self.0.valid_before.0 } + #[diplomat::attr(auto, getter = "signature_key")] pub fn get_signature_key(&self) -> Box { Box::new(SshPublicKey(self.0.signature_key.clone())) } + #[diplomat::attr(auto, getter = "key_id")] pub fn get_key_id(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { writeable.write_str(&self.0.key_id)?; writeable.flush(); Ok(()) } + #[diplomat::attr(auto, getter = "comment")] pub fn get_comment(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { writeable.write_str(&self.0.comment)?; writeable.flush(); diff --git a/ffi/src/utils.rs b/ffi/src/utils.rs index a565a267..5516c1ce 100644 --- a/ffi/src/utils.rs +++ b/ffi/src/utils.rs @@ -15,6 +15,7 @@ pub mod ffi { Box::new(VecU8(bytes.to_vec())) } + #[diplomat::attr(auto, getter = "length")] pub fn get_length(&self) -> usize { self.0.len() } diff --git a/ffi/src/x509/algorithm_identifier.rs b/ffi/src/x509/algorithm_identifier.rs index dea870ae..91d5c3ce 100644 --- a/ffi/src/x509/algorithm_identifier.rs +++ b/ffi/src/x509/algorithm_identifier.rs @@ -16,12 +16,14 @@ pub mod ffi { .is_a(picky::oid::ObjectIdentifier::try_from(other).map_err(|_| "invalid OID")?)) } + #[diplomat::attr(auto, getter = "oid")] pub fn get_oid(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { let string: String = self.0.oid().into(); write!(writable, "{string}")?; Ok(()) } + #[diplomat::attr(auto, getter = "parameters")] pub fn get_parameters<'a>(&'a self) -> Box> { Box::new(AlgorithmIdentifierParameters(self.0.parameters())) } @@ -40,6 +42,7 @@ pub mod ffi { } impl AlgorithmIdentifierParameters<'_> { + #[diplomat::attr(auto, getter = "type")] pub fn get_type(&self) -> AlgorithmIdentifierParametersType { match self.0 { picky_asn1_x509::AlgorithmIdentifierParameters::None => AlgorithmIdentifierParametersType::None, @@ -96,6 +99,7 @@ pub mod ffi { } impl AesParameters { + #[diplomat::attr(auto, getter = "type")] pub fn get_type(&self) -> AesParametersType { match self.0 { picky_asn1_x509::AesParameters::Null => AesParametersType::Null, diff --git a/ffi/src/x509/attribute.rs b/ffi/src/x509/attribute.rs index 9d1190cf..223a31ff 100644 --- a/ffi/src/x509/attribute.rs +++ b/ffi/src/x509/attribute.rs @@ -14,12 +14,14 @@ pub mod ffi { pub struct Attribute(pub picky_asn1_x509::Attribute); impl Attribute { + #[diplomat::attr(auto, getter = "type")] pub fn get_type(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { let oid: String = self.0.ty.0.clone().into(); write!(writable, "{oid}")?; Ok(()) } + #[diplomat::attr(auto, getter = "values")] pub fn get_values(&self) -> Box { Box::new(AttributeValues(self.0.value.clone())) } @@ -48,6 +50,7 @@ pub mod ffi { } impl AttributeValues { + #[diplomat::attr(auto, getter = "type")] pub fn get_type(&self) -> AttributeValueType { match &self.0 { picky_asn1_x509::AttributeValues::Extensions(_) => AttributeValueType::Extensions, @@ -142,6 +145,7 @@ pub mod ffi { pub struct SpcSpOpusInfo(picky_asn1_x509::pkcs7::content_info::SpcSpOpusInfo); impl SpcSpOpusInfo { + #[diplomat::attr(auto, getter = "program_name")] pub fn get_program_name(&self) -> Option> { self.0 .program_name @@ -149,6 +153,7 @@ pub mod ffi { .map(|program_name| Box::new(SpcString(program_name.0.clone()))) } + #[diplomat::attr(auto, getter = "more_info")] pub fn get_more_info(&self) -> Option> { self.0 .more_info @@ -166,6 +171,7 @@ pub mod ffi { } impl SpcString { + #[diplomat::attr(auto, getter = "type")] pub fn get_type(&self) -> SpcStringType { match &self.0 { picky_asn1_x509::pkcs7::content_info::SpcString::Unicode(_) => SpcStringType::Unicode, @@ -173,6 +179,7 @@ pub mod ffi { } } + #[diplomat::attr(auto, getter = "as_string")] pub fn get_as_string(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { match &self.0 { picky_asn1_x509::pkcs7::content_info::SpcString::Unicode(unicode) => { @@ -185,6 +192,7 @@ pub mod ffi { Ok(()) } + #[diplomat::attr(auto, getter = "as_bytes")] pub fn get_as_bytes(&self) -> Box { match &self.0 { picky_asn1_x509::pkcs7::content_info::SpcString::Unicode(unicode) => { @@ -207,6 +215,7 @@ pub mod ffi { } impl SpcLink { + #[diplomat::attr(auto, getter = "type")] pub fn get_type(&self) -> SpcLinkType { match &self.0 { picky_asn1_x509::pkcs7::content_info::SpcLink::Url(_) => SpcLinkType::Url, @@ -215,6 +224,7 @@ pub mod ffi { } } + #[diplomat::attr(auto, getter = "url")] pub fn get_url(&self) -> Option> { match &self.0 { picky_asn1_x509::pkcs7::content_info::SpcLink::Url(url) => { @@ -225,6 +235,7 @@ pub mod ffi { } } + #[diplomat::attr(auto, getter = "moniker")] pub fn get_moniker(&self) -> Option> { match &self.0 { picky_asn1_x509::pkcs7::content_info::SpcLink::Moniker(moniker) => { @@ -234,6 +245,7 @@ pub mod ffi { } } + #[diplomat::attr(auto, getter = "file")] pub fn get_file(&self) -> Option> { match &self.0 { picky_asn1_x509::pkcs7::content_info::SpcLink::File(file) => { @@ -249,10 +261,12 @@ pub mod ffi { pub struct SpcSerializedObject(picky_asn1_x509::pkcs7::content_info::SpcSerializedObject); impl SpcSerializedObject { + #[diplomat::attr(auto, getter = "class_id")] pub fn get_class_id(&self) -> Box { VecU8::from_bytes(&self.0.class_id.0.0).boxed() } + #[diplomat::attr(auto, getter = "object_id")] pub fn get_object_id(&self) -> Box { VecU8::from_bytes(&self.0.serialized_data.0).boxed() } @@ -292,12 +306,14 @@ pub mod ffi { pub struct AttributeTypeAndValue(pub picky_asn1_x509::attribute_type_and_value::AttributeTypeAndValue); impl AttributeTypeAndValue { + #[diplomat::attr(auto, getter = "type_id")] pub fn get_type_id(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { let oid: String = self.0.ty.0.clone().into(); write!(writable, "{oid}")?; Ok(()) } + #[diplomat::attr(auto, getter = "value")] pub fn get_value(&self) -> Box { Box::new(AttributeTypeAndValueParameters(self.0.value.clone())) } @@ -325,6 +341,7 @@ pub mod ffi { } impl AttributeTypeAndValueParameters { + #[diplomat::attr(auto, getter = "type")] pub fn get_type(&self) -> AttributeTypeAndValueParametersType { match &self.0 { picky_asn1_x509::attribute_type_and_value::AttributeTypeAndValueParameters::CommonName(_) => { @@ -494,12 +511,14 @@ pub mod ffi { pub struct UnsignedAttribute(pub picky_asn1_x509::signer_info::UnsignedAttribute); impl UnsignedAttribute { + #[diplomat::attr(auto, getter = "type")] pub fn get_type(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { let oid: String = self.0.ty.0.clone().into(); write!(writable, "{oid}")?; Ok(()) } + #[diplomat::attr(auto, getter = "values")] pub fn get_values(&self) -> Box { Box::new(UnsignedAttributeValue(self.0.value.clone())) } @@ -523,6 +542,7 @@ pub mod ffi { } impl UnsignedAttributeValue { + #[diplomat::attr(auto, getter = "type")] pub fn get_type(&self) -> UnsignedAttributeValueType { match &self.0 { picky_asn1_x509::signer_info::UnsignedAttributeValue::MsCounterSign(_) => { @@ -567,12 +587,14 @@ pub mod ffi { pub struct MsCounterSign(picky_asn1_x509::Pkcs7Certificate); impl MsCounterSign { + #[diplomat::attr(auto, getter = "oid")] pub fn get_oid(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { let oid_string: String = self.0.oid.0.clone().into(); write!(writable, "{oid_string}")?; Ok(()) } + #[diplomat::attr(auto, getter = "signed_data")] pub fn get_signed_data(&self) -> Box { Box::new(SignedData(self.0.signed_data.0.clone())) } @@ -582,19 +604,23 @@ pub mod ffi { pub struct SignedData(pub picky_asn1_x509::pkcs7::signed_data::SignedData); impl SignedData { + #[diplomat::attr(auto, getter = "version")] pub fn get_version(&self) -> CmsVersion { self.0.version.into() } + #[diplomat::attr(auto, getter = "digest_algorithms")] pub fn get_digest_algorithms(&self) -> Box { let vec: Vec<_> = self.0.digest_algorithms.0.iter().cloned().collect(); Box::new(AlgorithmIdentifierIterator(vec)) } + #[diplomat::attr(auto, getter = "content_info")] pub fn get_content_info(&self) -> Box { Box::new(EncapsulatedContentInfo(self.0.content_info.clone())) } + #[diplomat::attr(auto, getter = "crls")] pub fn get_crls(&self) -> Option> { self.0 .crls @@ -602,10 +628,12 @@ pub mod ffi { .map(|crls| Box::new(RevocationInfoChoiceIterator(crls.clone()))) } + #[diplomat::attr(auto, getter = "certificates")] pub fn get_certificates(&self) -> Box { Box::new(CertificateChoicesIterator(self.0.certificates.0.clone())) } + #[diplomat::attr(auto, getter = "signers_infos")] pub fn get_signers_infos(&self) -> Box { let signer_infos = &self.0.signers_infos; let vec_signer_infos: Vec<_> = signer_infos.0.iter().cloned().map(SignerInfo).collect(); @@ -637,6 +665,7 @@ pub mod ffi { pub struct CertificateChoices(pub picky_asn1_x509::signed_data::CertificateChoices); impl CertificateChoices { + #[diplomat::attr(auto, getter = "certificate")] pub fn get_certificate(&self) -> Option> { match &self.0 { picky_asn1_x509::signed_data::CertificateChoices::Certificate(der) => { @@ -646,6 +675,7 @@ pub mod ffi { } } + #[diplomat::attr(auto, getter = "other")] pub fn get_other(&self) -> Option> { match &self.0 { picky_asn1_x509::signed_data::CertificateChoices::Other(der) => Some(VecU8::from_bytes(&der.0).boxed()), @@ -674,6 +704,7 @@ pub mod ffi { pub struct RevocationInfoChoice(pub picky_asn1_x509::crls::RevocationInfoChoice); impl RevocationInfoChoice { + #[diplomat::attr(auto, getter = "crl")] pub fn get_crl(&self) -> Option> { match &self.0 { picky_asn1_x509::crls::RevocationInfoChoice::Crl(crl) => Some(Box::new(CertificateList(crl.clone()))), @@ -686,14 +717,17 @@ pub mod ffi { pub struct CertificateList(pub picky_asn1_x509::crls::CertificateList); impl CertificateList { + #[diplomat::attr(auto, getter = "tbs_cert_list")] pub fn get_tbs_cert_list(&self) -> Box { Box::new(TbsCertList(self.0.tbs_cert_list.clone())) } + #[diplomat::attr(auto, getter = "signature_algorithm")] pub fn get_signature_algorithm(&self) -> Box { Box::new(AlgorithmIdentifier(self.0.signature_algorithm.clone())) } + #[diplomat::attr(auto, getter = "signature_value")] pub fn get_signature_value(&self) -> Box { VecU8::from_bytes(self.0.signature_value.clone().payload_view()).boxed() } @@ -702,6 +736,7 @@ pub mod ffi { pub struct TbsCertList(pub picky_asn1_x509::crls::TbsCertList); impl TbsCertList { + #[diplomat::attr(auto, getter = "version")] pub fn get_version(&self) -> Version { match self.0.version.map(|v| match v { picky_asn1_x509::Version::V1 => Version::V1, @@ -713,24 +748,29 @@ pub mod ffi { } } + #[diplomat::attr(auto, getter = "signature_algorithm")] pub fn get_signature_algorithm(&self) -> Box { Box::new(AlgorithmIdentifier(self.0.signature.clone())) } + #[diplomat::attr(auto, getter = "issuer")] pub fn get_issuer(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { let name_string = format!("{}", self.0.issuer); write!(writable, "{name_string}")?; Ok(()) } + #[diplomat::attr(auto, getter = "this_upate")] pub fn get_this_upate(&self) -> Box