RSA, DSA, DH: Allow some given input to be NULL on already initialised keys
[openssl.git] / crypto / ui / ui_util.c
index ee9730d5e2f87a972cbc532eb0f9cccefd130819..f04ee7c1f4f8e61e8c3fb665c8d2a58cebee6142 100644 (file)
@@ -1,4 +1,3 @@
-/* crypto/ui/ui_util.c -*- mode:C; c-file-style: "eay" -*- */
 /* ====================================================================
  * Copyright (c) 2001-2002 The OpenSSL Project.  All rights reserved.
  *
@@ -7,7 +6,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  */
 
 #include <string.h>
-#include <openssl/ui.h>
+#include "ui_locl.h"
 
-int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify)
-       {
-       char buff[BUFSIZ];
-       int ret;
+#ifndef BUFSIZ
+#define BUFSIZ 256
+#endif
 
-       ret=UI_UTIL_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
-       OPENSSL_cleanse(buff,BUFSIZ);
-       return(ret);
-       }
+int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt,
+                           int verify)
+{
+    char buff[BUFSIZ];
+    int ret;
 
-int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify)
-       {
-       int ok = 0;
-       UI *ui;
+    ret =
+        UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length,
+                        prompt, verify);
+    OPENSSL_cleanse(buff, BUFSIZ);
+    return (ret);
+}
 
-       if (size < 1)
-               return -1;
+int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt,
+                    int verify)
+{
+    int ok = 0;
+    UI *ui;
 
-       ui = UI_new();
-       if (ui)
-               {
-               ok = UI_add_input_string(ui,prompt,0,buf,0,size-1);
-               if (ok == 0 && verify)
-                       ok = UI_add_verify_string(ui,prompt,0,buff,0,size-1,
-                               buf);
-               if (ok == 0)
-                       ok=UI_process(ui);
-               UI_free(ui);
-               }
-       return(ok);
-       }
+    if (size < 1)
+        return -1;
+
+    ui = UI_new();
+    if (ui != NULL) {
+        ok = UI_add_input_string(ui, prompt, 0, buf, 0, size - 1);
+        if (ok >= 0 && verify)
+            ok = UI_add_verify_string(ui, prompt, 0, buff, 0, size - 1, buf);
+        if (ok >= 0)
+            ok = UI_process(ui);
+        UI_free(ui);
+    }
+    if (ok > 0)
+        ok = 0;
+    return (ok);
+}