global reindent, now with uncrustify hook enabled
[oweals/gnunet.git] / src / credential / credential_misc.c
index 2b134bc93d7089bf8416a8a7af6e7db7b77f0bb4..13435273e6f5b13c3806172f78f359c936d7d208 100644 (file)
@@ -3,7 +3,7 @@
      Copyright (C) 2009-2013, 2016 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
+     under the terms of the GNU Affero General Public License as published
      by the Free Software Foundation, either version 3 of the License,
      or (at your option) any later version.
 
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-*/
+
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
+ */
 
 
 /**
@@ -29,7 +34,8 @@
 #include <inttypes.h>
 
 char*
-GNUNET_CREDENTIAL_credential_to_string (const struct GNUNET_CREDENTIAL_Credential *cred)
+GNUNET_CREDENTIAL_credential_to_string (const struct
+                                        GNUNET_CREDENTIAL_Credential *cred)
 {
   char *cred_str;
   char *subject_pkey;
@@ -39,11 +45,11 @@ GNUNET_CREDENTIAL_credential_to_string (const struct GNUNET_CREDENTIAL_Credentia
 
   subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key);
   issuer_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key);
-  GNUNET_STRINGS_base64_encode ((char*)&cred->signature,
-                                sizeof (struct GNUNET_CRYPTO_EcdsaSignature),
+  GNUNET_STRINGS_base64_encode ((char*) &cred->signature,
+                                sizeof(struct GNUNET_CRYPTO_EcdsaSignature),
                                 &signature);
   GNUNET_asprintf (&cred_str,
-                   "%s.%s -> %s | %s | %"SCNu64,
+                   "%s.%s -> %s | %s | %" SCNu64,
                    issuer_pkey,
                    cred->issuer_attribute,
                    subject_pkey,
@@ -56,23 +62,24 @@ GNUNET_CREDENTIAL_credential_to_string (const struct GNUNET_CREDENTIAL_Credentia
 }
 
 struct GNUNET_CREDENTIAL_Credential*
-GNUNET_CREDENTIAL_credential_from_string (const char* s)
+GNUNET_CREDENTIAL_credential_from_string (const char*s)
 {
   struct GNUNET_CREDENTIAL_Credential *cred;
-  size_t enclen = (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
+  size_t enclen = (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) * 8;
+
   if (enclen % 5 > 0)
     enclen += 5 - enclen % 5;
   enclen /= 5; /* 260/5 = 52 */
   char subject_pkey[enclen + 1];
   char issuer_pkey[enclen + 1];
   char name[253 + 1];
-  char signature[256]; //TODO max payload size
+  char signature[256]; // TODO max payload size
 
   struct GNUNET_CRYPTO_EcdsaSignature *sig;
   struct GNUNET_TIME_Absolute etime_abs;
 
-  if (5 != SSCANF (s,
-                   "%52s.%253s -> %52s | %s | %"SCNu64,
+  if (5 != sscanf (s,
+                   "%52s.%253s -> %52s | %s | %" SCNu64,
                    issuer_pkey,
                    name,
                    subject_pkey,
@@ -80,28 +87,32 @@ GNUNET_CREDENTIAL_credential_from_string (const char* s)
                    &etime_abs.abs_value_us))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Unable to parse CRED record string `%s'\n"),
+                _ ("Unable to parse CRED record string `%s'\n"),
                 s);
     return NULL;
   }
-  cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + strlen (name) + 1);
+  cred = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential) + strlen (
+                          name) + 1);
   GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey,
                                               strlen (subject_pkey),
                                               &cred->subject_key);
   GNUNET_CRYPTO_ecdsa_public_key_from_string (issuer_pkey,
                                               strlen (issuer_pkey),
                                               &cred->issuer_key);
-  GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdsaSignature) == GNUNET_STRINGS_base64_decode (signature,
-                                strlen (signature),
-                                (char**)&sig));
+  GNUNET_assert (sizeof(struct GNUNET_CRYPTO_EcdsaSignature) ==
+                 GNUNET_STRINGS_base64_decode (signature,
+                                               strlen (
+                                                 signature),
+                                               (
+                                                 char**) &sig));
   cred->signature = *sig;
   cred->expiration = etime_abs;
   GNUNET_free (sig);
   GNUNET_memcpy (&cred[1],
                  name,
-                 strlen (name)+1);
-  cred->issuer_attribute_len = strlen ((char*)&cred[1]);
-  cred->issuer_attribute = (char*)&cred[1];
+                 strlen (name) + 1);
+  cred->issuer_attribute_len = strlen ((char*) &cred[1]);
+  cred->issuer_attribute = (char*) &cred[1];
   return cred;
 }
 
@@ -114,7 +125,8 @@ GNUNET_CREDENTIAL_credential_from_string (const char* s)
  * @return handle to the queued request
  */
 struct GNUNET_CREDENTIAL_Credential *
-GNUNET_CREDENTIAL_credential_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
+GNUNET_CREDENTIAL_credential_issue (const struct
+                                    GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
                                     struct GNUNET_CRYPTO_EcdsaPublicKey *subject,
                                     const char *attribute,
                                     struct GNUNET_TIME_Absolute *expiration)
@@ -123,20 +135,22 @@ GNUNET_CREDENTIAL_credential_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *
   struct GNUNET_CREDENTIAL_Credential *cred;
   size_t size;
 
-  size = sizeof (struct CredentialEntry) + strlen (attribute) + 1;
+  size = sizeof(struct CredentialEntry) + strlen (attribute) + 1;
   crd = GNUNET_malloc (size);
-  cred = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + strlen (attribute) + 1);
-  crd->purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature));
+  cred = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential) + strlen (
+                          attribute) + 1);
+  crd->purpose.size = htonl (size - sizeof(struct
+                                           GNUNET_CRYPTO_EcdsaSignature));
 
   crd->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CREDENTIAL);
   GNUNET_CRYPTO_ecdsa_key_get_public (issuer,
                                       &crd->issuer_key);
   crd->subject_key = *subject;
   crd->expiration = GNUNET_htonll (expiration->abs_value_us);
-  crd->issuer_attribute_len = htonl (strlen (attribute)+1);
-  GNUNET_memcpy ((char*)&crd[1],
+  crd->issuer_attribute_len = htonl (strlen (attribute) + 1);
+  GNUNET_memcpy ((char*) &crd[1],
                  attribute,
-                 strlen (attribute)+1);
+                 strlen (attribute) + 1);
   if (GNUNET_OK !=
       GNUNET_CRYPTO_ecdsa_sign (issuer,
                                 &crd->purpose,
@@ -155,10 +169,8 @@ GNUNET_CREDENTIAL_credential_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *
   cred->subject_key = *subject;
   GNUNET_memcpy (&cred[1],
                  attribute,
-                 strlen (attribute)+1);
-  cred->issuer_attribute = (char*)&cred[1];
+                 strlen (attribute) + 1);
+  cred->issuer_attribute = (char*) &cred[1];
   GNUNET_free (crd);
   return cred;
 }
-
-