-renaming gnunet-gns to gnunet-namestore
[oweals/gnunet.git] / src / namestore / namestore_common.c
index c65fc76fe05a32fde4e28e24c6f83f801f23b96c..c1b5ddc1e0b776d6fd6e63e1ec89511bd81195a4 100644 (file)
@@ -95,7 +95,7 @@ GNUNET_NAMESTORE_records_get_size (unsigned int rd_count,
 /**
  * Serialize the given records to the given destination buffer.
  *
- * @param rd_cound number of records in the rd array
+ * @param rd_count number of records in the rd array
  * @param rd array of GNUNET_NAMESTORE_RecordData with rd_count elements
  * @param dest_size size of the destination array
  * @param dest where to write the result
@@ -131,13 +131,34 @@ GNUNET_NAMESTORE_records_serialize (unsigned int rd_count,
   return off;
 }
 
+/**
+ * Compares if two records are equal
+ *
+ * @param a record
+ * @param b record
+ *
+ * @return GNUNET_YES or GNUNET_NO
+ */
+int
+GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a,
+                              const struct GNUNET_NAMESTORE_RecordData *b)
+{
+  if ((a->record_type == b->record_type) &&
+      (a->expiration.abs_value == b->expiration.abs_value) &&
+      (a->data_size == b->data_size) &&
+      (0 == memcmp (a->data, b->data, a->data_size)))
+    return GNUNET_YES;
+  else
+    return GNUNET_NO;
+}
+
 
 /**
  * Deserialize the given records to the given destination.
  *
  * @param len size of the serialized record data
  * @param src the serialized record data
- * @param rd_cound number of records in the rd array
+ * @param rd_count number of records in the rd array
  * @param dest where to put the data
  *
  * @return GNUNET_OK on success, GNUNET_SYSERR on error
@@ -164,7 +185,7 @@ GNUNET_NAMESTORE_records_deserialize (size_t len,
     dest[i].flags = ntohl (rec.flags);
     off += sizeof (rec);
 
-    if (off + sizeof (dest[i].data_size) > len)
+    if (off + dest[i].data_size > len)
       return GNUNET_SYSERR;
     dest[i].data = &src[off];
     off += dest[i].data_size;
@@ -172,8 +193,21 @@ GNUNET_NAMESTORE_records_deserialize (size_t len,
   return GNUNET_OK; 
 }
 
+/**
+ * Sign name and records
+ *
+ * @param key the private key
+ * @param name the name
+ * @param rd record data
+ * @param rd_count number of records
+ *
+ * @return the signature
+ */
 struct GNUNET_CRYPTO_RsaSignature *
-GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_RsaPrivateKey *key, const char *name, struct GNUNET_NAMESTORE_RecordData *rd, unsigned int rd_count)
+GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
+    const char *name,
+    struct GNUNET_NAMESTORE_RecordData *rd,
+    unsigned int rd_count)
 {
   struct GNUNET_CRYPTO_RsaSignature *sig = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_RsaSignature));
   struct GNUNET_CRYPTO_RsaSignaturePurpose *sig_purpose;