summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-03-21 14:26:51 +0100
committerNeal H. Walfield <neal@pep.foundation>2019-03-21 14:26:51 +0100
commitc04b985e0fe6f6b92b799702b290a521a8f5a912 (patch)
treea56ec35bd65863c52b3b03eed731f0affd82a51d /openpgp-ffi
parentaba46b434dd0d344a916a610e250d6469c261d12 (diff)
openpgp-ffi: Allow passing 0 to select the default algorithm
- 01db33b and 97cdc30 changed the Encryption::new and Signer::new APIs to optionally provide the algorithm to use for encryption and hashing. Also make it optional in the C API by recognizing 0 as meaning the default algorithm.
Diffstat (limited to 'openpgp-ffi')
-rw-r--r--openpgp-ffi/src/serialize.rs33
1 files changed, 28 insertions, 5 deletions
diff --git a/openpgp-ffi/src/serialize.rs b/openpgp-ffi/src/serialize.rs
index f39a069d..63a3198e 100644
--- a/openpgp-ffi/src/serialize.rs
+++ b/openpgp-ffi/src/serialize.rs
@@ -18,6 +18,8 @@ use self::openpgp::{
};
use self::openpgp::constants::{
DataFormat,
+ HashAlgorithm,
+ SymmetricAlgorithm,
};
use error::Status;
@@ -140,6 +142,10 @@ pub extern "system" fn pgp_arbitrary_writer_new
/// For every signing key, a signer writes a one-pass-signature
/// packet, then hashes and emits the data stream, then for every key
/// writes a signature packet.
+///
+/// The hash is performed using the algorithm specificed in
+/// `hash_algo`. Pass 0 for the default (which is what you usually
+/// want).
#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
pub extern "system" fn pgp_signer_new
(errp: Option<&mut *mut ::error::Error>,
@@ -161,10 +167,17 @@ pub extern "system" fn pgp_signer_new
ffi_param_ref_mut!(signer).as_mut()
}
).collect();
- ffi_try_box!(Signer::new(*inner, signers, Some(hash_algo.into())))
+ let hash_algo : Option<HashAlgorithm> = if hash_algo == 0 {
+ None
+ } else {
+ Some(hash_algo.into())
+ };
+ ffi_try_box!(Signer::new(*inner, signers, hash_algo))
}
/// Creates a signer for a detached signature.
+///
+/// See `pgp_signer_new` for details.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
pub extern "system" fn pgp_signer_new_detached
(errp: Option<&mut *mut ::error::Error>,
@@ -186,7 +199,12 @@ pub extern "system" fn pgp_signer_new_detached
ffi_param_ref_mut!(signer).as_mut()
}
).collect();
- ffi_try_box!(Signer::detached(*inner, signers, Some(hash_algo.into())))
+ let hash_algo : Option<HashAlgorithm> = if hash_algo == 0 {
+ None
+ } else {
+ Some(hash_algo.into())
+ };
+ ffi_try_box!(Signer::detached(*inner, signers, hash_algo))
}
/// Writes a literal data packet.
@@ -213,8 +231,8 @@ pub extern "system" fn pgp_literal_writer_new
/// which will be encrypted using the given passwords, and all
/// encryption-capable subkeys of the given TPKs.
///
-/// The stream is encrypted using AES256, regardless of any key
-/// preferences.
+/// The stream is encrypted using `cipher_algo`. Pass 0 for the
+/// default (which is what you usually want).
#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
pub extern "system" fn pgp_encryptor_new
(errp: Option<&mut *mut ::error::Error>,
@@ -253,9 +271,14 @@ pub extern "system" fn pgp_encryptor_new
1 => EncryptionMode::ForTransport,
_ => panic!("Bad encryption mode: {}", encryption_mode),
};
+ let cipher_algo : Option<SymmetricAlgorithm> = if cipher_algo == 0 {
+ None
+ } else {
+ Some(cipher_algo.into())
+ };
ffi_try_box!(Encryptor::new(*inner,
&passwords_.iter().collect::<Vec<&Password>>(),
&recipients[..],
encryption_mode,
- Some(cipher_algo.into())))
+ cipher_algo))
}