aboutsummaryrefslogtreecommitdiff
path: root/src/pki.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-09-18 22:04:03 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-10-29 19:58:28 +0200
commit2c04994443384224161d895d00255b5788e8376d (patch)
treed07f4eb26408d4e0f8b76d96212e11f23b20f699 /src/pki.c
parente799c0ce7d046606d9391d826461c2782f072fa0 (diff)
downloadlibssh-2c04994443384224161d895d00255b5788e8376d.tar.gz
libssh-2c04994443384224161d895d00255b5788e8376d.tar.xz
libssh-2c04994443384224161d895d00255b5788e8376d.zip
pki: Add a ssh_key_cmp() function.
Diffstat (limited to 'src/pki.c')
-rw-r--r--src/pki.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/pki.c b/src/pki.c
index c6f0e5f8..c3ff3394 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -257,6 +257,40 @@ int ssh_key_is_private(const ssh_key k) {
return (k->flags & SSH_KEY_FLAG_PRIVATE);
}
+/**
+ * @brief Compare keys if they are equal.
+ *
+ * @param[in] k1 The first key to compare.
+ *
+ * @param[in] k2 The second key to compare.
+ *
+ * @param[in] what What part or type of the key do you want to compare.
+ *
+ * @return 0 if equal, 1 if not.
+ */
+int ssh_key_cmp(const ssh_key k1,
+ const ssh_key k2,
+ enum ssh_keycmp_e what)
+{
+ if (k1 == NULL || k2 == NULL) {
+ return 1;
+ }
+
+ if (k1->type != k2->type) {
+ ssh_pki_log("key types don't macth!");
+ return 1;
+ }
+
+ if (what == SSH_KEY_CMP_PRIVATE) {
+ if (!ssh_key_is_private(k1) ||
+ !ssh_key_is_private(k2)) {
+ return 1;
+ }
+ }
+
+ return pki_key_compare(k1, k2, what);
+}
+
ssh_signature ssh_signature_new(void)
{
struct ssh_signature_struct *sig;