Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ffi/src/argon2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions ffi/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,38 @@ pub mod ffi {
Ok(Box::new(date))
}

#[diplomat::attr(auto, getter = "timestamp")]
pub fn get_timestamp(&self) -> Result<i64, Box<PickyError>> {
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()
}
Expand Down
1 change: 1 addition & 0 deletions ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions ffi/src/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PickyError>> {
write!(writeable, "{}", self.0.header.cty.as_deref().unwrap_or(""))?;
writeable.flush();
Expand All @@ -119,13 +120,15 @@ 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<PickyError>> {
write!(writeable, "{}", self.0.header.kid.as_deref().unwrap_or(""))?;
writeable.flush();
Ok(())
}

/// Returns the header as a JSON encoded payload.
#[diplomat::attr(auto, getter = "header")]
pub fn get_header(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box<PickyError>> {
let header = serde_json::to_string(&self.0.header)?;
write!(writeable, "{header}")?;
Expand All @@ -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<PickyError>> {
let claims = serde_json::to_string(&self.0.state.claims)?;
write!(writeable, "{claims}")?;
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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<PickyError>> {
let claims = serde_json::from_str(claims)?;
self.0.claims = claims;
Expand Down
2 changes: 2 additions & 0 deletions ffi/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down
2 changes: 2 additions & 0 deletions ffi/src/pem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PickyError>> {
write!(writeable, "{}", self.0.label())?;
writeable.flush();
Expand Down
9 changes: 9 additions & 0 deletions ffi/src/pkcs12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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,
Expand All @@ -159,6 +163,7 @@ pub mod ffi {
}
}

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

Expand Down Expand Up @@ -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,
Expand All @@ -239,6 +245,7 @@ pub mod ffi {
}
}

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

#[diplomat::attr(auto, getter = "certificate")]
pub fn get_certificate(&self) -> Option<Box<Cert>> {
if let pkcs12::SafeBagKind::Certificate(cert) = self.0.kind() {
Some(Box::new(Cert(cert.clone())))
Expand Down Expand Up @@ -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());
}
Expand Down
15 changes: 15 additions & 0 deletions ffi/src/putty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PublicKey>, Box<PickyError>> {
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<PrivateKey>, Box<PickyError>> {
let key = self.0.private_key()?;
Ok(Box::new(PrivateKey(key)))
Expand All @@ -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<PickyError>> {
writeable.write_str(self.0.comment())?;
writeable.flush();
Expand Down Expand Up @@ -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<PickyError>> {
writeable.write_str(self.0.comment())?;
writeable.flush();
Expand Down Expand Up @@ -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<VecU8> {
Box::new(VecU8(self.0.salt.to_vec()))
}
Expand Down Expand Up @@ -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);
}
Expand Down
Loading
Loading