diff options
author | Neal H. Walfield <neal@pep.foundation> | 2018-12-17 21:55:23 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2018-12-17 21:57:46 +0100 |
commit | 31548a68d94cb4b9067ef7a5382cd3f85fa2983f (patch) | |
tree | 3e3a4861dbc428f2ff9c3df9a5db46ebb7c3db04 | |
parent | 135020a511c62440f53c742656b950092bebe5cf (diff) |
ffi: Add function to query a Key's the public key algo.
- Add sq_p_key_public_key_algo for returning the algorithm and
sq_p_key_public_key_bits for returning the strength.
-rw-r--r-- | ffi/include/sequoia/openpgp.h | 61 | ||||
-rw-r--r-- | ffi/src/openpgp.rs | 29 |
2 files changed, 90 insertions, 0 deletions
diff --git a/ffi/include/sequoia/openpgp.h b/ffi/include/sequoia/openpgp.h index fd47ac87..6e972f80 100644 --- a/ffi/include/sequoia/openpgp.h +++ b/ffi/include/sequoia/openpgp.h @@ -1076,6 +1076,67 @@ int sq_p_key_alive(sq_p_key_t key, sq_signature_t self_signature); int sq_p_key_alive_at(sq_p_key_t key, sq_signature_t self_signature, time_t when); +typedef enum sq_public_key_algorithm { + /*/ + /// RSA (Encrypt or Sign) + /*/ + SQ_PUBLIC_KEY_ALGO_RSA_ENCRYPT_SIGN, + + /*/ + /// RSA Encrypt-Only + /*/ + SQ_PUBLIC_KEY_ALGO_RSA_ENCRYPT, + + /*/ + /// RSA Sign-Only + /*/ + SQ_PUBLIC_KEY_ALGO_RSA_SIGN, + + /*/ + /// Elgamal (Encrypt-Only) + /*/ + SQ_PUBLIC_KEY_ALGO_ELGAMAL_ENCRYPT, + + /*/ + /// DSA (Digital Signature Algorithm) + /*/ + SQ_PUBLIC_KEY_ALGO_DSA, + + /*/ + /// Elliptic curve DH + /*/ + SQ_PUBLIC_KEY_ALGO_ECDH, + + /*/ + /// Elliptic curve DSA + /*/ + SQ_PUBLIC_KEY_ALGO_ECDSA, + + /*/ + /// Elgamal (Encrypt or Sign) + /*/ + SQ_PUBLIC_KEY_ALGO_ELGAMAL_ENCRYPT_SIGN, + + /*/ + /// "Twisted" Edwards curve DSA + /*/ + SQ_PUBLIC_KEY_ALGO_EDDSA, + + /* Dummy value to make sure the enumeration has a defined size. Do + not use this value. */ + SQ_PUBLIC_KEY_ALGO_FORCE_WIDTH = INT_MAX, +} sq_public_key_algo_t; + +/*/ +/// Returns the key's public key algorithm. +/*/ +sq_public_key_algo_t sq_p_key_public_key_algo(sq_p_key_t key); + +/*/ +/// Returns the public key's size in bits. +/*/ +int sq_p_key_public_key_bits(sq_p_key_t key); + /*/ /// Returns the value of the User ID Packet. /// diff --git a/ffi/src/openpgp.rs b/ffi/src/openpgp.rs index d73a3d92..c718ef1b 100644 --- a/ffi/src/openpgp.rs +++ b/ffi/src/openpgp.rs @@ -1699,6 +1699,35 @@ pub extern "system" fn sq_p_key_creation_time(key: Option<&packet::Key>) ct.to_timespec().sec as u32 } +/// Returns the key's public key algorithm. +#[no_mangle] +pub extern "system" fn sq_p_key_public_key_algo(key: Option<&packet::Key>) + -> c_int +{ + let key = key.expect("Key is NULL"); + let pk_algo : u8 = key.pk_algo().into(); + pk_algo as c_int +} + +/// Returns the public key's size in bits. +#[no_mangle] +pub extern "system" fn sq_p_key_public_key_bits(key: Option<&packet::Key>) + -> c_int +{ + use self::openpgp::crypto::mpis::PublicKey::*; + + let key = key.expect("Key is NULL"); + match key.mpis() { + RSA { e: _, n } => n.bits as c_int, + DSA { p: _, q: _, g: _, y } => y.bits as c_int, + Elgamal { p: _, g: _, y } => y.bits as c_int, + EdDSA { curve: _, q } => q.bits as c_int, + ECDSA { curve: _, q } => q.bits as c_int, + ECDH { curve: _, q, hash: _, sym: _ } => q.bits as c_int, + Unknown { mpis: _, rest: _ } => 0, + } +} + /// Returns the value of the User ID Packet. /// /// The returned pointer is valid until `uid` is deallocated. If |