Sort the pcr entries list everytime new entry is added
authorSansar Choinyambuu <schoinya@hsr.ch>
Mon, 24 Oct 2011 10:43:38 +0000 (12:43 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Mon, 28 Nov 2011 13:39:52 +0000 (14:39 +0100)
src/libpts/pts/pts.c

index a4dda7f..ec5d303 100644 (file)
@@ -934,6 +934,20 @@ METHOD(pts_t, quote_tpm, bool,
        return FALSE;
 }
 
        return FALSE;
 }
 
+/**
+ * Comparison function for pcr_entry_t struct
+ */
+static int pcr_entry_compare(const pcr_entry_t *a, const pcr_entry_t *b)
+{
+       return (a->pcr_number - b->pcr_number);
+}
+
+static int pcr_entry_compare_qsort(const void *a, const void *b)
+{
+       return pcr_entry_compare(*(const pcr_entry_t *const *)a
+                                                       , *(const pcr_entry_t *const *)b);
+}
+
 METHOD(pts_t, add_pcr_entry, void,
        private_pts_t *this, pcr_entry_t *new)
 {
 METHOD(pts_t, add_pcr_entry, void,
        private_pts_t *this, pcr_entry_t *new)
 {
@@ -961,7 +975,8 @@ METHOD(pts_t, add_pcr_entry, void,
        
        this->pcrs->insert_last(this->pcrs, new);
 
        
        this->pcrs->insert_last(this->pcrs, new);
 
-       /* TODO: Sort pcr entries with pcr index */
+       qsort(this->pcrs, this->pcrs->get_count(this->pcrs),
+                 sizeof(pcr_entry_t *), pcr_entry_compare_qsort);
 }
 
 /**
 }
 
 /**