Imported Upstream version 0.6.27
[platform/upstream/libsolv.git] / ext / repo_pubkey.c
index 50066cc..eb83839 100644 (file)
@@ -14,8 +14,6 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <limits.h>
-#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -257,6 +255,12 @@ pgphashalgo2type(int algo)
     return REPOKEY_TYPE_SHA1;
   if (algo == 8)
     return REPOKEY_TYPE_SHA256;
+  if (algo == 9)
+    return REPOKEY_TYPE_SHA384;
+  if (algo == 10)
+    return REPOKEY_TYPE_SHA512;
+  if (algo == 11)
+    return REPOKEY_TYPE_SHA224;
   return 0;
 }
 
@@ -1148,7 +1152,7 @@ solvsig_free(Solvsig *ss)
 }
 
 static int
-repo_find_pubkeys_cmp(const void *va, const void *vb, void *dp)
+repo_find_all_pubkeys_cmp(const void *va, const void *vb, void *dp)
 {
   Pool *pool = dp;
   Id a = *(Id *)va;
@@ -1158,7 +1162,7 @@ repo_find_pubkeys_cmp(const void *va, const void *vb, void *dp)
 }
 
 void
-repo_find_pubkeys(Repo *repo, const char *keyid, Queue *q)
+repo_find_all_pubkeys(Repo *repo, const char *keyid, Queue *q)
 {
   Id p;
   Solvable *s;
@@ -1178,12 +1182,24 @@ repo_find_pubkeys(Repo *repo, const char *keyid, Queue *q)
         queue_push(q, p);
     }
   if (q->count > 1)
-    solv_sort(q->elements, q->count, sizeof(Id), repo_find_pubkeys_cmp, repo->pool);
+    solv_sort(q->elements, q->count, sizeof(Id), repo_find_all_pubkeys_cmp, repo->pool);
+}
+
+Id
+repo_find_pubkey(Repo *repo, const char *keyid)
+{
+  Queue q;
+  Id p;
+  queue_init(&q);
+  repo_find_all_pubkeys(repo, keyid, &q);
+  p = q.count ? q.elements[0] : 0;
+  queue_free(&q);
+  return p;
 }
 
 #ifdef ENABLE_PGPVRFY
 
-/* warning: does not check key expiry/revokation, like gpgv or rpm */
+/* warning: does not check key expiry/revokation, same as with gpgv or rpm */
 /* returns the Id of the pubkey that verified the signature */
 Id
 repo_verify_sigdata(Repo *repo, unsigned char *sigdata, int sigdatal, const char *keyid)
@@ -1195,7 +1211,7 @@ repo_verify_sigdata(Repo *repo, unsigned char *sigdata, int sigdatal, const char
   if (!sigdata || !keyid)
     return 0;
   queue_init(&q);
-  repo_find_pubkeys(repo, keyid, &q);
+  repo_find_all_pubkeys(repo, keyid, &q);
   for (i = 0; i < q.count; i++)
     {
       int pubdatal;