diff options
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/identity/identity_api.c | 64 | ||||
-rw-r--r-- | 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 | |||
523 | src/zonemaster/gnunet-service-zonemaster-monitor.c | 523 | src/zonemaster/gnunet-service-zonemaster-monitor.c |
524 | src/zonemaster/gnunet-service-zonemaster.c | 524 | src/zonemaster/gnunet-service-zonemaster.c |
525 | src/fs/fs_api.h | 525 | src/fs/fs_api.h |
526 | src/include/gnunet_identity_service.h | ||
526 | src/testbed/testbed_api.h | 527 | src/testbed/testbed_api.h |
527 | src/testbed/testbed_api_operations.h | 528 | 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 | |||
@@ -991,6 +991,40 @@ GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key) | |||
991 | 991 | ||
992 | 992 | ||
993 | ssize_t | 993 | ssize_t |
994 | GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key, | ||
995 | const void* buffer, | ||
996 | size_t len) | ||
997 | { | ||
998 | if (len < sizeof (key->type)) | ||
999 | return -1; | ||
1000 | GNUNET_memcpy(&(key->type), buffer, sizeof (key->type)); | ||
1001 | const ssize_t length = GNUNET_IDENTITY_key_get_length(key); | ||
1002 | if (len < length) | ||
1003 | return -1; | ||
1004 | if (length < 0) | ||
1005 | return -2; | ||
1006 | GNUNET_memcpy(&(key->ecdsa_key), buffer + sizeof (key->type), length - sizeof (key->type)); | ||
1007 | return length; | ||
1008 | } | ||
1009 | |||
1010 | |||
1011 | ssize_t | ||
1012 | GNUNET_IDENTITY_write_key_to_buffer (const struct GNUNET_IDENTITY_PublicKey *key, | ||
1013 | void* buffer, | ||
1014 | size_t len) | ||
1015 | { | ||
1016 | const ssize_t length = GNUNET_IDENTITY_key_get_length(key); | ||
1017 | if (len < length) | ||
1018 | return -1; | ||
1019 | if (length < 0) | ||
1020 | return -2; | ||
1021 | GNUNET_memcpy(buffer, &(key->type), sizeof (key->type)); | ||
1022 | GNUNET_memcpy(buffer + sizeof (key->type), &(key->ecdsa_key), length - sizeof (key->type)); | ||
1023 | return length; | ||
1024 | } | ||
1025 | |||
1026 | |||
1027 | ssize_t | ||
994 | GNUNET_IDENTITY_signature_get_length (const struct GNUNET_IDENTITY_Signature *sig) | 1028 | GNUNET_IDENTITY_signature_get_length (const struct GNUNET_IDENTITY_Signature *sig) |
995 | { | 1029 | { |
996 | switch (ntohl (sig->type)) | 1030 | switch (ntohl (sig->type)) |
@@ -1009,35 +1043,35 @@ GNUNET_IDENTITY_signature_get_length (const struct GNUNET_IDENTITY_Signature *si | |||
1009 | 1043 | ||
1010 | 1044 | ||
1011 | ssize_t | 1045 | ssize_t |
1012 | GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key, | 1046 | GNUNET_IDENTITY_read_signature_from_buffer (struct GNUNET_IDENTITY_Signature *sig, |
1013 | const void* buffer, | 1047 | const void* buffer, |
1014 | size_t len) | 1048 | size_t len) |
1015 | { | 1049 | { |
1016 | if (len < sizeof (key->type)) | 1050 | if (len < sizeof (sig->type)) |
1017 | return -1; | 1051 | return -1; |
1018 | GNUNET_memcpy(&(key->type), buffer, sizeof (key->type)); | 1052 | GNUNET_memcpy(&(sig->type), buffer, sizeof (sig->type)); |
1019 | const ssize_t length = GNUNET_IDENTITY_key_get_length(key); | 1053 | const ssize_t length = GNUNET_IDENTITY_signature_get_length(sig); |
1020 | if (len < length) | 1054 | if (len < length) |
1021 | return -1; | 1055 | return -1; |
1022 | if (length < 0) | 1056 | if (length < 0) |
1023 | return -2; | 1057 | return -2; |
1024 | GNUNET_memcpy(&(key->ecdsa_key), buffer + sizeof (key->type), length - sizeof (key->type)); | 1058 | GNUNET_memcpy(&(sig->ecdsa_signature), buffer + sizeof (sig->type), length - sizeof (sig->type)); |
1025 | return length; | 1059 | return length; |
1026 | } | 1060 | } |
1027 | 1061 | ||
1028 | 1062 | ||
1029 | ssize_t | 1063 | ssize_t |
1030 | GNUNET_IDENTITY_write_key_to_buffer (const struct GNUNET_IDENTITY_PublicKey *key, | 1064 | GNUNET_IDENTITY_write_signature_to_buffer (const struct GNUNET_IDENTITY_Signature *sig, |
1031 | void* buffer, | 1065 | void* buffer, |
1032 | size_t len) | 1066 | size_t len) |
1033 | { | 1067 | { |
1034 | const ssize_t length = GNUNET_IDENTITY_key_get_length(key); | 1068 | const ssize_t length = GNUNET_IDENTITY_signature_get_length(sig); |
1035 | if (len < length) | 1069 | if (len < length) |
1036 | return -1; | 1070 | return -1; |
1037 | if (length < 0) | 1071 | if (length < 0) |
1038 | return -2; | 1072 | return -2; |
1039 | GNUNET_memcpy(buffer, &(key->type), sizeof (key->type)); | 1073 | GNUNET_memcpy(buffer, &(sig->type), sizeof (sig->type)); |
1040 | GNUNET_memcpy(buffer + sizeof (key->type), &(key->ecdsa_key), length - sizeof (key->type)); | 1074 | GNUNET_memcpy(buffer + sizeof (sig->type), &(sig->ecdsa_signature), length - sizeof (sig->type)); |
1041 | return length; | 1075 | return length; |
1042 | } | 1076 | } |
1043 | 1077 | ||
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); | |||
406 | 406 | ||
407 | 407 | ||
408 | /** | 408 | /** |
409 | * Reads a #GNUNET_IDENTITY_PublicKey from a compact buffer. | ||
410 | * The buffer has to contain at least the compacted length of | ||
411 | * a #GNUNET_IDENTITY_PublicKey in bytes. | ||
412 | * If the buffer is too small, the function returns -1 as error. | ||
413 | * If the buffer does not contain a valid key, it returns -2 as error. | ||
414 | * | ||
415 | * @param key the key | ||
416 | * @param buffer the buffer | ||
417 | * @param len the length of buffer | ||
418 | * @return -1 or -2 on error, else the amount of bytes read from the buffer | ||
419 | */ | ||
420 | ssize_t | ||
421 | GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key, | ||
422 | const void* buffer, | ||
423 | size_t len); | ||
424 | |||
425 | |||
426 | /** | ||
427 | * Writes a #GNUNET_IDENTITY_PublicKey to a compact buffer. | ||
428 | * The buffer requires space for at least the compacted length of | ||
429 | * a #GNUNET_IDENTITY_PublicKey in bytes. | ||
430 | * If the buffer is too small, the function returns -1 as error. | ||
431 | * If the key is not valid, it returns -2 as error. | ||
432 | * | ||
433 | * @param key the key | ||
434 | * @param buffer the buffer | ||
435 | * @param len the length of buffer | ||
436 | * @return -1 or -2 on error, else the amount of bytes written to the buffer | ||
437 | */ | ||
438 | ssize_t | ||
439 | GNUNET_IDENTITY_write_key_to_buffer (const struct GNUNET_IDENTITY_PublicKey *key, | ||
440 | void* buffer, | ||
441 | size_t len); | ||
442 | |||
443 | |||
444 | /** | ||
409 | * Get the compacted length of a #GNUNET_IDENTITY_Signature. | 445 | * Get the compacted length of a #GNUNET_IDENTITY_Signature. |
410 | * Compacted means that it returns the minimum number of bytes this | 446 | * Compacted means that it returns the minimum number of bytes this |
411 | * signature is long, as opposed to the union structure inside | 447 | * 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 | |||
420 | 456 | ||
421 | 457 | ||
422 | /** | 458 | /** |
423 | * Reads a #GNUNET_IDENTITY_PublicKey from a compact buffer. | 459 | * Reads a #GNUNET_IDENTITY_Signature from a compact buffer. |
424 | * The buffer has to contain at least the compacted length of | 460 | * The buffer has to contain at least the compacted length of |
425 | * a #GNUNET_IDENTITY_PublicKey bytes. | 461 | * a #GNUNET_IDENTITY_Signature in bytes. |
426 | * If the buffer is too small, the function returns -1 as error. | 462 | * If the buffer is too small, the function returns -1 as error. |
427 | * If the buffer does not contain a valid key, it returns -2 as error. | 463 | * If the buffer does not contain a valid key, it returns -2 as error. |
428 | * | 464 | * |
429 | * @param key the key | 465 | * @param sig the signature |
430 | * @param buffer the buffer | 466 | * @param buffer the buffer |
431 | * @param len the length of buffer | 467 | * @param len the length of buffer |
432 | * @return -1 or -2 on error, else the amount of bytes read from the buffer | 468 | * @return -1 or -2 on error, else the amount of bytes read from the buffer |
433 | */ | 469 | */ |
434 | ssize_t | 470 | ssize_t |
435 | GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key, | 471 | GNUNET_IDENTITY_read_signature_from_buffer (struct GNUNET_IDENTITY_Signature *sig, |
436 | const void* buffer, | 472 | const void* buffer, |
437 | size_t len); | 473 | size_t len); |
438 | 474 | ||
439 | 475 | ||
440 | /** | 476 | /** |
441 | * Writes a #GNUNET_IDENTITY_PublicKey to a compact buffer. | 477 | * Writes a #GNUNET_IDENTITY_Signature to a compact buffer. |
442 | * The buffer requires space for at least the compacted length of | 478 | * The buffer requires space for at least the compacted length of |
443 | * a #GNUNET_IDENTITY_PublicKey in bytes. | 479 | * a #GNUNET_IDENTITY_Signature in bytes. |
444 | * If the buffer is too small, the function returns -1 as error. | 480 | * If the buffer is too small, the function returns -1 as error. |
445 | * If the key is not valid, it returns -2 as error. | 481 | * If the key is not valid, it returns -2 as error. |
446 | * | 482 | * |
447 | * @param key the key | 483 | * @param sig the signature |
448 | * @param buffer the buffer | 484 | * @param buffer the buffer |
449 | * @param len the length of buffer | 485 | * @param len the length of buffer |
450 | * @return -1 or -2 on error, else the amount of bytes written to the buffer | 486 | * @return -1 or -2 on error, else the amount of bytes written to the buffer |
451 | */ | 487 | */ |
452 | ssize_t | 488 | ssize_t |
453 | GNUNET_IDENTITY_write_key_to_buffer (const struct GNUNET_IDENTITY_PublicKey *key, | 489 | GNUNET_IDENTITY_write_signature_to_buffer (const struct GNUNET_IDENTITY_Signature *sig, |
454 | void* buffer, | 490 | void* buffer, |
455 | size_t len); | 491 | size_t len); |
456 | 492 | ||
457 | 493 | ||
458 | /** | 494 | /** |