updates
[crypto.git] / lib / silccrypt / silcpkcs.c
index d61ed0c826db0ca0e7933954661cc7bd36acd35b..8d409e35ec8792198c54171d0a362ca500b6b79f 100644 (file)
@@ -58,7 +58,7 @@ const SilcPKCSObject silc_default_pkcs[] =
 /* Register a new PKCS into SILC. This is used at the initialization of
    the SILC. */
 
-bool silc_pkcs_register(SilcPKCSObject *pkcs)
+bool silc_pkcs_register(const SilcPKCSObject *pkcs)
 {
 #ifndef SILC_EPOC
   SilcPKCSObject *new;
@@ -128,7 +128,7 @@ bool silc_pkcs_register_default(void)
   int i;
 
   for (i = 0; silc_default_pkcs[i].name; i++)
-    silc_pkcs_register((SilcPKCSObject *)&(silc_default_pkcs[i]));
+    silc_pkcs_register(&(silc_default_pkcs[i]));
 
 #endif /* SILC_EPOC */
   return TRUE;
@@ -406,16 +406,17 @@ char *silc_pkcs_encode_identifier(char *username, char *host, char *realname,
   SilcBuffer buf;
   char *identifier;
   SilcUInt32 len, tlen = 0;
+  char utf8[256 + 1];
 
   if (!username || !host)
     return NULL;
 
-  len = (username ? strlen(username) : 0) +
-       (host     ? strlen(host)     : 0) +
-       (realname ? strlen(realname) : 0) +
-       (email    ? strlen(email)    : 0) +
-       (org      ? strlen(org)      : 0) +
-       (country  ? strlen(country)  : 0);
+  len = (username ? silc_utf8_encoded_len(username, strlen(username), 0) : 0) +
+       (host     ? silc_utf8_encoded_len(host, strlen(host), 0) : 0) +
+       (realname ? silc_utf8_encoded_len(realname, strlen(realname), 0) : 0) +
+       (email    ? silc_utf8_encoded_len(email, strlen(email), 0) : 0) +
+       (org      ? silc_utf8_encoded_len(org, strlen(org), 0) : 0) +
+       (country  ? silc_utf8_encoded_len(country, strlen(country), 0) : 0);
   
   if (len < 3)
     return NULL;
@@ -425,62 +426,77 @@ char *silc_pkcs_encode_identifier(char *username, char *host, char *realname,
   silc_buffer_pull_tail(buf, len);
 
   if (username) {
+    memset(utf8, 0, sizeof(utf8));
+    len = silc_utf8_encode(username, strlen(username), 0, utf8,
+                          sizeof(utf8) - 1);
     silc_buffer_format(buf,
                       SILC_STR_UI32_STRING("UN="),
-                      SILC_STR_UI32_STRING(username),
+                      SILC_STR_UI32_STRING(utf8),
                       SILC_STR_END);
-    silc_buffer_pull(buf, 3 + strlen(username));
-    tlen = 3 + strlen(username)
+    silc_buffer_pull(buf, 3 + len);
+    tlen = 3 + len
   }
     
   if (host) {
+    memset(utf8, 0, sizeof(utf8));
+    len = silc_utf8_encode(host, strlen(host), 0, utf8, sizeof(utf8) - 1);
     silc_buffer_format(buf,
                       SILC_STR_UI32_STRING(", "),
                       SILC_STR_UI32_STRING("HN="),
-                      SILC_STR_UI32_STRING(host),
+                      SILC_STR_UI32_STRING(utf8),
                       SILC_STR_END);
-    silc_buffer_pull(buf, 5 + strlen(host));
-    tlen += 5 + strlen(host)
+    silc_buffer_pull(buf, 5 + len);
+    tlen += 5 + len
   }
 
   if (realname) {
+    memset(utf8, 0, sizeof(utf8));
+    len = silc_utf8_encode(realname, strlen(realname), 0, utf8,
+                          sizeof(utf8) - 1);
     silc_buffer_format(buf,
                       SILC_STR_UI32_STRING(", "),
                       SILC_STR_UI32_STRING("RN="),
-                      SILC_STR_UI32_STRING(realname),
+                      SILC_STR_UI32_STRING(utf8),
                       SILC_STR_END);
-    silc_buffer_pull(buf, 5 + strlen(realname));
-    tlen += 5 + strlen(realname)
+    silc_buffer_pull(buf, 5 + len);
+    tlen += 5 + len
   }
 
   if (email) {
+    memset(utf8, 0, sizeof(utf8));
+    len = silc_utf8_encode(email, strlen(email), 0, utf8, sizeof(utf8) - 1);
     silc_buffer_format(buf,
                       SILC_STR_UI32_STRING(", "),
                       SILC_STR_UI32_STRING("E="),
-                      SILC_STR_UI32_STRING(email),
+                      SILC_STR_UI32_STRING(utf8),
                       SILC_STR_END);
-    silc_buffer_pull(buf, 4 + strlen(email));
-    tlen += 4 + strlen(email)
+    silc_buffer_pull(buf, 4 + len);
+    tlen += 4 + len
   }
 
   if (org) {
+    memset(utf8, 0, sizeof(utf8));
+    len = silc_utf8_encode(org, strlen(org), 0, utf8, sizeof(utf8) - 1);
     silc_buffer_format(buf,
                       SILC_STR_UI32_STRING(", "),
                       SILC_STR_UI32_STRING("O="),
-                      SILC_STR_UI32_STRING(org),
+                      SILC_STR_UI32_STRING(utf8),
                       SILC_STR_END);
-    silc_buffer_pull(buf, 4 + strlen(org));
-    tlen += 4 + strlen(org)
+    silc_buffer_pull(buf, 4 + len);
+    tlen += 4 + len
   }
 
   if (country) {
+    memset(utf8, 0, sizeof(utf8));
+    len = silc_utf8_encode(country, strlen(country), 0, utf8,
+                          sizeof(utf8) - 1);
     silc_buffer_format(buf,
                       SILC_STR_UI32_STRING(", "),
                       SILC_STR_UI32_STRING("C="),
-                      SILC_STR_UI32_STRING(country),
+                      SILC_STR_UI32_STRING(utf8),
                       SILC_STR_END);
-    silc_buffer_pull(buf, 4 + strlen(country));
-    tlen += 4 + strlen(country)
+    silc_buffer_pull(buf, 4 + len);
+    tlen += 4 + len
   }
 
   silc_buffer_push(buf, buf->data - buf->head);
@@ -945,7 +961,7 @@ static int silc_pkcs_save_public_key_internal(char *filename,
   case SILC_PKCS_FILE_BIN:
     break;
   case SILC_PKCS_FILE_PEM:
-    data = silc_encode_pem_file(data, data_len);
+    data = silc_pem_encode_file(data, data_len);
     data_len = strlen(data);
     break;
   }
@@ -1008,7 +1024,7 @@ static int silc_pkcs_save_private_key_internal(char *filename,
   case SILC_PKCS_FILE_BIN:
     break;
   case SILC_PKCS_FILE_PEM:
-    data = silc_encode_pem_file(data, data_len);
+    data = silc_pem_encode_file(data, data_len);
     data_len = strlen(data);
     break;
   }
@@ -1097,7 +1113,7 @@ int silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key,
     case SILC_PKCS_FILE_BIN:
       break;
     case SILC_PKCS_FILE_PEM:
-      data = silc_decode_pem(data, len, &len);
+      data = silc_pem_decode(data, len, &len);
       memset(old, 0, data_len);
       silc_free(old);
       old = data; 
@@ -1154,7 +1170,7 @@ int silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key,
     case SILC_PKCS_FILE_BIN:
       break;
     case SILC_PKCS_FILE_PEM:
-      data = silc_decode_pem(data, len, &len);
+      data = silc_pem_decode(data, len, &len);
       break;
     }