summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2020-11-06 10:31:35 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2020-11-06 10:31:35 +0100
commit4d10374ff7762d64c387b70edf9f31397eab4123 (patch)
treec2c1166aca58daacee67fe192d2308a77b7173ce /src
parenta4d89a695198036b2f8a2bc4a131295227d7d014 (diff)
added compact reading and writing for signatures
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/identity/identity_api.c64
-rw-r--r--src/include/gnunet_identity_service.h60
2 files changed, 97 insertions, 27 deletions
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index a277d8877..45c18b95c 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -991,6 +991,40 @@ GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key)
ssize_t
+GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key,
+ const void* buffer,
+ size_t len)
+{
+ if (len < sizeof (key->type))
+ return -1;
+ GNUNET_memcpy(&(key->type), buffer, sizeof (key->type));
+ const ssize_t length = GNUNET_IDENTITY_key_get_length(key);
+ if (len < length)
+ return -1;
+ if (length < 0)
+ return -2;
+ GNUNET_memcpy(&(key->ecdsa_key), buffer + sizeof (key->type), length - sizeof (key->type));
+ return length;
+}
+
+
+ssize_t
+GNUNET_IDENTITY_write_key_to_buffer (const struct GNUNET_IDENTITY_PublicKey *key,
+ void* buffer,
+ size_t len)
+{
+ const ssize_t length = GNUNET_IDENTITY_key_get_length(key);
+ if (len < length)
+ return -1;
+ if (length < 0)
+ return -2;
+ GNUNET_memcpy(buffer, &(key->type), sizeof (key->type));
+ GNUNET_memcpy(buffer + sizeof (key->type), &(key->ecdsa_key), length - sizeof (key->type));
+ return length;
+}
+
+
+ssize_t
GNUNET_IDENTITY_signature_get_length (const struct GNUNET_IDENTITY_Signature *sig)
{
switch (ntohl (sig->type))
@@ -1009,35 +1043,35 @@ GNUNET_IDENTITY_signature_get_length (const struct GNUNET_IDENTITY_Signature *si
ssize_t
-GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key,
- const void* buffer,
- size_t len)
+GNUNET_IDENTITY_read_signature_from_buffer (struct GNUNET_IDENTITY_Signature *sig,
+ const void* buffer,
+ size_t len)
{
- if (len < sizeof (key->type))
- return -1;
- GNUNET_memcpy(&(key->type), buffer, sizeof (key->type));
- const ssize_t length = GNUNET_IDENTITY_key_get_length(key);
+ if (len < sizeof (sig->type))
+ return -1;
+ GNUNET_memcpy(&(sig->type), buffer, sizeof (sig->type));
+ const ssize_t length = GNUNET_IDENTITY_signature_get_length(sig);
if (len < length)
return -1;
if (length < 0)
- return -2;
- GNUNET_memcpy(&(key->ecdsa_key), buffer + sizeof (key->type), length - sizeof (key->type));
+ return -2;
+ GNUNET_memcpy(&(sig->ecdsa_signature), buffer + sizeof (sig->type), length - sizeof (sig->type));
return length;
}
ssize_t
-GNUNET_IDENTITY_write_key_to_buffer (const struct GNUNET_IDENTITY_PublicKey *key,
- void* buffer,
- size_t len)
+GNUNET_IDENTITY_write_signature_to_buffer (const struct GNUNET_IDENTITY_Signature *sig,
+ void* buffer,
+ size_t len)
{
- const ssize_t length = GNUNET_IDENTITY_key_get_length(key);
+ const ssize_t length = GNUNET_IDENTITY_signature_get_length(sig);
if (len < length)
return -1;
if (length < 0)
return -2;
- GNUNET_memcpy(buffer, &(key->type), sizeof (key->type));
- GNUNET_memcpy(buffer + sizeof (key->type), &(key->ecdsa_key), length - sizeof (key->type));
+ GNUNET_memcpy(buffer, &(sig->type), sizeof (sig->type));
+ GNUNET_memcpy(buffer + sizeof (sig->type), &(sig->ecdsa_signature), length - sizeof (sig->type));
return length;
}
diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h
index 8084a3a98..64799f195 100644
--- a/src/include/gnunet_identity_service.h
+++ b/src/include/gnunet_identity_service.h
@@ -406,6 +406,42 @@ GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key);
/**
+ * Reads a #GNUNET_IDENTITY_PublicKey from a compact buffer.
+ * The buffer has to contain at least the compacted length of
+ * a #GNUNET_IDENTITY_PublicKey in bytes.
+ * If the buffer is too small, the function returns -1 as error.
+ * If the buffer does not contain a valid key, it returns -2 as error.
+ *
+ * @param key the key
+ * @param buffer the buffer
+ * @param len the length of buffer
+ * @return -1 or -2 on error, else the amount of bytes read from the buffer
+ */
+ssize_t
+GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key,
+ const void* buffer,
+ size_t len);
+
+
+/**
+ * Writes a #GNUNET_IDENTITY_PublicKey to a compact buffer.
+ * The buffer requires space for at least the compacted length of
+ * a #GNUNET_IDENTITY_PublicKey in bytes.
+ * If the buffer is too small, the function returns -1 as error.
+ * If the key is not valid, it returns -2 as error.
+ *
+ * @param key the key
+ * @param buffer the buffer
+ * @param len the length of buffer
+ * @return -1 or -2 on error, else the amount of bytes written to the buffer
+ */
+ssize_t
+GNUNET_IDENTITY_write_key_to_buffer (const struct GNUNET_IDENTITY_PublicKey *key,
+ void* buffer,
+ size_t len);
+
+
+/**
* Get the compacted length of a #GNUNET_IDENTITY_Signature.
* Compacted means that it returns the minimum number of bytes this
* signature is long, as opposed to the union structure inside
@@ -420,39 +456,39 @@ GNUNET_IDENTITY_signature_get_length (const struct GNUNET_IDENTITY_Signature *si
/**
- * Reads a #GNUNET_IDENTITY_PublicKey from a compact buffer.
+ * Reads a #GNUNET_IDENTITY_Signature from a compact buffer.
* The buffer has to contain at least the compacted length of
- * a #GNUNET_IDENTITY_PublicKey bytes.
+ * a #GNUNET_IDENTITY_Signature in bytes.
* If the buffer is too small, the function returns -1 as error.
* If the buffer does not contain a valid key, it returns -2 as error.
*
- * @param key the key
+ * @param sig the signature
* @param buffer the buffer
* @param len the length of buffer
* @return -1 or -2 on error, else the amount of bytes read from the buffer
*/
ssize_t
-GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key,
- const void* buffer,
- size_t len);
+GNUNET_IDENTITY_read_signature_from_buffer (struct GNUNET_IDENTITY_Signature *sig,
+ const void* buffer,
+ size_t len);
/**
- * Writes a #GNUNET_IDENTITY_PublicKey to a compact buffer.
+ * Writes a #GNUNET_IDENTITY_Signature to a compact buffer.
* The buffer requires space for at least the compacted length of
- * a #GNUNET_IDENTITY_PublicKey in bytes.
+ * a #GNUNET_IDENTITY_Signature in bytes.
* If the buffer is too small, the function returns -1 as error.
* If the key is not valid, it returns -2 as error.
*
- * @param key the key
+ * @param sig the signature
* @param buffer the buffer
* @param len the length of buffer
* @return -1 or -2 on error, else the amount of bytes written to the buffer
*/
ssize_t
-GNUNET_IDENTITY_write_key_to_buffer (const struct GNUNET_IDENTITY_PublicKey *key,
- void* buffer,
- size_t len);
+GNUNET_IDENTITY_write_signature_to_buffer (const struct GNUNET_IDENTITY_Signature *sig,
+ void* buffer,
+ size_t len);
/**