aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-15 20:27:28 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-15 20:27:28 +0000
commit424bdca04e523f86ff3b1a5db58e05fb6b2ff036 (patch)
treea8a5a9f35fc021653f93422815c5e1a3220d9dca
parente650e7a8fa7968f33c94eb9a389b3bef6aa4f929 (diff)
downloadgnunet-424bdca04e523f86ff3b1a5db58e05fb6b2ff036.tar.gz
gnunet-424bdca04e523f86ff3b1a5db58e05fb6b2ff036.zip
-finishing identity client library, at least in theory (untested)
-rw-r--r--src/identity/identity_api.c83
1 files changed, 79 insertions, 4 deletions
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index e35137cbe..8be81e124 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -641,8 +641,44 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *id,
641 GNUNET_IDENTITY_Continuation cont, 641 GNUNET_IDENTITY_Continuation cont,
642 void *cont_cls) 642 void *cont_cls)
643{ 643{
644 GNUNET_break (0); // FIXME 644 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
645 return NULL; 645 struct GNUNET_IDENTITY_Operation *op;
646 struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
647 char *str;
648 uint16_t enc_len;
649 size_t slen;
650
651 slen = strlen (service_name) + 1;
652 enc = GNUNET_CRYPTO_ecc_encode_key (ego->pk);
653 enc_len = ntohs (enc->size);
654
655 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) - enc_len)
656 {
657 GNUNET_break (0);
658 GNUNET_free (enc);
659 return NULL;
660 }
661 op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) +
662 sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) +
663 enc_len + slen);
664 op->cont = cont;
665 op->cls = cont_cls;
666 sdm = (struct GNUNET_IDENTITY_SetDefaultMessage *) &op[1];
667 sdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
668 sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) +
669 slen + enc_len);
670 sdm->name_len = htons (slen);
671 sdm->pk_len = htons (enc_len);
672 str = (char *) &sdm[1];
673 memcpy (str, enc, enc_len);
674 memcpy (&str[enc_len], service_name, slen);
675 op->msg = &sdm->header;
676 GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
677 id->op_tail,
678 op);
679 if (NULL == id->th)
680 transmit_next (id);
681 return op;
646} 682}
647 683
648 684
@@ -661,8 +697,47 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
661 GNUNET_IDENTITY_Callback cb, 697 GNUNET_IDENTITY_Callback cb,
662 void *cb_cls) 698 void *cb_cls)
663{ 699{
664 GNUNET_break (0); // FIXME 700 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
665 return NULL; 701 struct GNUNET_IDENTITY_Operation *op;
702 struct GNUNET_IDENTITY_CreateRequestMessage *crm;
703 struct GNUNET_CRYPTO_EccPrivateKey *pk;
704 char *str;
705 uint16_t enc_len;
706 size_t slen;
707
708 slen = strlen (identifier) + 1;
709 pk = GNUNET_CRYPTO_ecc_key_create ();
710 enc = GNUNET_CRYPTO_ecc_encode_key (pk);
711 GNUNET_CRYPTO_ecc_key_free (pk);
712 enc_len = ntohs (enc->size);
713
714 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) - enc_len)
715 {
716 GNUNET_break (0);
717 GNUNET_free (enc);
718 return NULL;
719 }
720 op = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_Operation) +
721 sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) +
722 enc_len + slen);
723 op->cb = cb;
724 op->cls = cb_cls;
725 crm = (struct GNUNET_IDENTITY_CreateRequestMessage *) &op[1];
726 crm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_CREATE);
727 crm->header.size = htons (sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) +
728 slen + enc_len);
729 crm->name_len = htons (slen);
730 crm->pk_len = htons (enc_len);
731 str = (char *) &crm[1];
732 memcpy (str, enc, enc_len);
733 memcpy (&str[enc_len], identifier, slen);
734 op->msg = &crm->header;
735 GNUNET_CONTAINER_DLL_insert_tail (id->op_head,
736 id->op_tail,
737 op);
738 if (NULL == id->th)
739 transmit_next (id);
740 return op;
666} 741}
667 742
668 743