Merge branch 'master' into getopt
[oweals/gnunet.git] / src / identity-provider / identity_token.h
index a51f8ca84356650f879970ccd64cfd99a8d9e832..7ded6662ee99f615137463e71fd59de4af29c388 100644 (file)
@@ -1,6 +1,6 @@
 /*
    This file is part of GNUnet.
-   Copyright (C) 2012-2015 Christian Grothoff (and other contributing authors)
+   Copyright (C) 2012-2015 GNUnet e.V.
 
    GNUnet is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published
@@ -19,7 +19,7 @@
    */
 /**
  * @author Martin Schanzenbach
- * @file include/gnunet_identity_provider_lib.h
+ * @file identity-provider/identity_token.h
  * @brief GNUnet Identity Provider library
  *
  */
 struct IdentityToken
 {
   /**
-   * JSON header
+   * DLL
    */
-  json_t *header;
+  struct TokenAttr *attr_head;
 
   /**
-   * JSON Payload
+   * DLL
    */
-  json_t *payload;
+  struct TokenAttr *attr_tail;
 
   /**
    * Token Signature
@@ -52,12 +52,65 @@ struct IdentityToken
   struct GNUNET_CRYPTO_EcdsaPublicKey aud_key;
 };
 
+struct TokenAttr
+{
+  /**
+   * DLL
+   */
+  struct TokenAttr *next;
+
+  /**
+   * DLL
+   */
+  struct TokenAttr *prev;
+
+  /**
+   * Attribute name
+   */
+  char *name;
+
+  /**
+   * Attribute value DLL
+   */
+  struct TokenAttrValue *val_head;
+
+  /**
+   * Attribute value DLL
+   */
+  struct TokenAttrValue *val_tail;
+
+};
+
+struct TokenAttrValue
+{
+  /**
+   * DLL
+   */
+  struct TokenAttrValue *next;
+
+  /**
+   * DLL
+   */
+  struct TokenAttrValue *prev;
+
+  /**
+   * Attribute value
+   */
+  char *value;
+
+  /**
+   * Attribute int value
+   * used if NULL == value
+   */
+  uint64_t int_value;
+};
+
 struct TokenTicketPayload
 {
   /**
    * Nonce
    */
-  char* nonce;
+  uint64_t nonce;
 
   /**
    * Label
@@ -124,9 +177,33 @@ token_destroy (struct IdentityToken*token);
  * @param value the value
  */
 void
-token_add_attr (const struct IdentityToken *token,
-                                         const char* key,
-                                         const char* value);
+token_add_attr (struct IdentityToken *token,
+                const char* key,
+                const char* value);
+
+/**
+ * Add a new key value pair to the token
+ * 
+ * @param token the token to modify
+ * @param key the key
+ * @param value the value
+ */
+void
+token_add_attr_int (struct IdentityToken *token,
+                      const char* key,
+                      uint64_t value);
+
+
+
+/**
+ * Add a value to a TokenAttribute
+ *
+ * @param attr the token attribute
+ * @param value value to add
+ */
+  void
+  token_attr_add_value (const struct TokenAttr *attr,
+                        const char *value);
 
 /**
  * Add a new key value pair to the token with the value as json
@@ -136,10 +213,10 @@ token_add_attr (const struct IdentityToken *token,
  * @param value the value
  *
  */
-void
-token_add_json (const struct IdentityToken *token,
-                         const char* key,
-                         json_t* value);
+  void
+  token_add_json (const struct IdentityToken *token,
+                  const char* key,
+                  json_t* value);
 
 /**
  * Serialize a token. The token will be signed and base64 according to the
@@ -157,11 +234,11 @@ token_add_json (const struct IdentityToken *token,
  *
  * @return GNUNET_OK on success
  */
-int 
-token_serialize (const struct IdentityToken*token,
-                          const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
-                          struct GNUNET_CRYPTO_EcdhePrivateKey **ecdhe_privkey,
-                          char **result);
+  int 
+  token_serialize (const struct IdentityToken*token,
+                   const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
+                   struct GNUNET_CRYPTO_EcdhePrivateKey **ecdhe_privkey,
+                   char **result);
 
 /**
  * Parses the serialized token and returns a token
@@ -172,10 +249,10 @@ token_serialize (const struct IdentityToken*token,
  *
  * @return GNUNET_OK on success
  */
-int
-token_parse (const char* data,
-             const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
-             struct IdentityToken **result);
+               int
+               token_parse (const char* data,
+                            const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
+                            struct IdentityToken **result);
 
 /**
  * Parses the serialized token and returns a token
@@ -189,11 +266,11 @@ token_parse (const char* data,
  *
  * @return GNUNET_OK on success
  */
-  int
-  token_parse2 (const char* data,
-                const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_key,
-                const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
-                struct IdentityToken **result);
+int
+token_parse2 (const char* data,
+              const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_key,
+              const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
+              struct IdentityToken **result);
 
 
 /**
@@ -216,7 +293,7 @@ token_parse (const char* data,
  * Creates a ticket that can be exchanged by the audience for 
  * the token. The token must be placed under the label
  *
- * @param nonce_str nonce provided by the audience that requested the ticket
+ * @param nonce nonce provided by the audience that requested the ticket
  * @param iss_pkey the issuer pubkey used to sign the ticket
  * @param label the label encoded in the ticket
  * @param aud_ley the audience pubkey used to encrypt the ticket payload
@@ -224,7 +301,7 @@ token_parse (const char* data,
  * @return the ticket
  */
 struct TokenTicket*
-ticket_create (const char* nonce_str,
+ticket_create (uint64_t nonce,
                const struct GNUNET_CRYPTO_EcdsaPublicKey* iss_pkey,
                const char* lbl_str,
                const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key);
@@ -239,10 +316,10 @@ ticket_create (const char* nonce_str,
  *
  * @return GNUNET_OK on success
  */
-int
-ticket_serialize (struct TokenTicket *ticket,
-                  const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
-                  char **result);
+  int
+  ticket_serialize (struct TokenTicket *ticket,
+                    const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
+                    char **result);
 
 /**
  * Destroys a ticket
@@ -261,9 +338,9 @@ ticket_destroy (struct TokenTicket *ticket);
  *
  * @return GNUNET_OK on success
  */
-  int
-  ticket_parse (const char* raw_data,
-                const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
-                struct TokenTicket **ticket);
+int
+ticket_parse (const char* raw_data,
+              const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key,
+              struct TokenTicket **ticket);
 
 #endif