Added silc_attribute_get_verify_data function.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 15 Oct 2002 18:33:31 +0000 (18:33 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 15 Oct 2002 18:33:31 +0000 (18:33 +0000)
lib/silccore/silcattrs.c
lib/silccore/silcattrs.h

index 32c7f3101b44754799ca66b38e7d8c0d3d484436..2ea2d411fcac49af8405c27eb0b812edcd0a3316 100644 (file)
@@ -401,6 +401,55 @@ const unsigned char *silc_attribute_get_data(SilcAttributePayload payload,
   return (const unsigned char *)payload->data;
 }
 
+/* Construct digital signature verification data */
+
+unsigned char *silc_attribute_get_verify_data(SilcDList attrs,
+                                             bool server_verification,
+                                             SilcUInt32 *data_len)
+{
+  SilcAttributePayload attr;
+  SilcBufferStruct buffer;
+  unsigned char *data = NULL;
+  SilcUInt32 len = 0;
+
+  silc_dlist_start(attrs);
+  while ((attr = silc_dlist_get(attrs)) != SILC_LIST_END) {
+    switch (attr->attribute) {
+    case SILC_ATTRIBUTE_SERVER_DIGITAL_SIGNATURE:
+      /* Server signature is never part of the verification data */
+      break;
+
+    case SILC_ATTRIBUTE_USER_DIGITAL_SIGNATURE:
+      /* For user signature verification this is not part of the data */
+      if (!server_verification)
+       break;
+
+      /* Fallback, for server signature verification, user digital signature
+        is part of verification data. */
+
+    default:
+      /* All other data is part of the verification data */
+      data = silc_realloc(data, sizeof(*data) * (4 + attr->data_len + len));
+      if (!data)
+       return NULL;
+      silc_buffer_set(&buffer, data + len, 4 + attr->data_len);
+      silc_buffer_format(&buffer, 
+                        SILC_STR_UI_CHAR(attr->attribute),
+                        SILC_STR_UI_CHAR(attr->flags),
+                        SILC_STR_UI_SHORT(attr->data_len),
+                        SILC_STR_UI_XNSTRING(attr->data, attr->data_len),
+                        SILC_STR_END);
+      len += 4 + attr->data_len;
+      break;
+    }
+  }
+
+  if (data_len)
+    *data_len = len;
+
+  return data;
+}
+
 /* Return parsed attribute object */
 
 bool silc_attribute_get_object(SilcAttributePayload payload,
index 529a0b7dd1234790739e8199b324fc5da1c281a8..c2c5a84adbf5a7119b8423be572991007ebd935d 100644 (file)
@@ -350,6 +350,30 @@ SilcAttributeFlags silc_attribute_get_flags(SilcAttributePayload payload);
 const unsigned char *silc_attribute_get_data(SilcAttributePayload payload,
                                             SilcUInt32 *data_len);
 
+/****f* silccore/SilcAttributesAPI/silc_attribute_get_verify_data
+ *
+ * SYNOPSIS
+ *
+ *    unsigned char *
+ *    silc_attribute_get_verify_data(SilcDList attrs,
+ *                                   bool server_verification,
+ *                                   SilcUInt32 *data_len);
+ *
+ * DESCRIPTION
+ *
+ *    Constructs the data to be verified with the sender's digital
+ *    signature and sender's public key.  This allocates the data from
+ *    the list of attribute payloads and returns the buffer.  The caller
+ *    must free it.  If `server_verification' is FALSE then data is
+ *    constructed for user's digital signature verification, if it is
+ *    TRUE then it is constructed for server's digital signature
+ *    verification.
+ *
+ ***/
+unsigned char *silc_attribute_get_verify_data(SilcDList attrs,
+                                             bool server_verification,
+                                             SilcUInt32 *data_len);
+
 /* Object structures */
 
 /****s* silccore/SilcAttributesAPI/SilcAttributesObjService