UI_UTIL_wrap_read_pem_callback(): when |cb| is NULL, use PEM_def_callback
[openssl.git] / crypto / ui / ui_util.c
index 7249a077d8caa4fb925b0dfb7ddef798a98e0d0a..f64780a6a2af7ebeabbc6557fd0f95e4a0328551 100644 (file)
@@ -1,15 +1,16 @@
 /*
  * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
  *
- * Licensed under the OpenSSL license (the "License").  You may not use
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
  * in the file LICENSE in the source distribution or at
  * https://www.openssl.org/source/license.html
  */
 
 #include <string.h>
+#include <openssl/pem.h>         /* PEM_def_callback() */
 #include "internal/thread_once.h"
-#include "ui_locl.h"
+#include "ui_local.h"
 
 #ifndef BUFSIZ
 #define BUFSIZ 256
@@ -25,7 +26,7 @@ int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt,
         UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length,
                         prompt, verify);
     OPENSSL_cleanse(buff, BUFSIZ);
-    return (ret);
+    return ret;
 }
 
 int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt,
@@ -48,7 +49,7 @@ int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt,
     }
     if (ok > 0)
         ok = 0;
-    return (ok);
+    return ok;
 }
 
 /*
@@ -156,7 +157,7 @@ UI_METHOD *UI_UTIL_wrap_read_pem_callback(pem_password_cb *cb, int rwflag)
         return NULL;
     }
     data->rwflag = rwflag;
-    data->cb = cb;
+    data->cb = cb != NULL ? cb : PEM_def_callback;
 
     return ui_method;
 }