[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 04/04: added compact reading and writing for signatures
From: |
gnunet |
Subject: |
[gnunet] 04/04: added compact reading and writing for signatures |
Date: |
Sat, 07 Nov 2020 10:39:56 +0100 |
This is an automated email from the git hooks/post-receive script.
thejackimonster pushed a commit to branch master
in repository gnunet.
commit 4d10374ff7762d64c387b70edf9f31397eab4123
Author: TheJackiMonster <thejackimonster@gmail.com>
AuthorDate: Fri Nov 6 10:31:35 2020 +0100
added compact reading and writing for signatures
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
---
po/POTFILES.in | 1 +
src/identity/identity_api.c | 64 +++++++++++++++++++++++++++--------
src/include/gnunet_identity_service.h | 60 +++++++++++++++++++++++++-------
3 files changed, 98 insertions(+), 27 deletions(-)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6aab56d14..1f577e139 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -523,5 +523,6 @@ src/vpn/vpn_api.c
src/zonemaster/gnunet-service-zonemaster-monitor.c
src/zonemaster/gnunet-service-zonemaster.c
src/fs/fs_api.h
+src/include/gnunet_identity_service.h
src/testbed/testbed_api.h
src/testbed/testbed_api_operations.h
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
@@ -990,6 +990,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)
{
@@ -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
@@ -405,6 +405,42 @@ ssize_t
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
@@ -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);
/**
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.