Change OSSL_DEPRECATED to take a version argument
authorRichard Levitte <levitte@openssl.org>
Sat, 3 Oct 2020 07:33:32 +0000 (09:33 +0200)
committerRichard Levitte <levitte@openssl.org>
Mon, 12 Oct 2020 06:29:30 +0000 (08:29 +0200)
The macro value is changed to use deprecation messages where whose are
supported.

We also add the macro OSSL_DEPRECATED_FOR(), to be used whenever an
additional message text is desirable, for example to tell the user
what the deprecated is replaced with.  Example:

    OSSL_DEPRECATED_FOR(3.0,"use EVP_PKEY and EVP_PKEY_size() instead")
    int RSA_size(const RSA *rsa);

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13074)

include/openssl/macros.h

index 8f9f31d3f84e6a6ff7f1f90afda8e1683720db0c..bdeb2793bbc00c5846fb081baed42611ab077564 100644 (file)
 /*
  * Generic deprecation macro
  *
- * If OPENSSL_SUPPRESS_DEPRECATED is defined, then OSSL_DEPRECATED
- * becomes a no-op
+ * If OPENSSL_SUPPRESS_DEPRECATED is defined, then OSSL_DEPRECATED and
+ * OSSL_DEPRECATED_FOR become no-ops
  */
 # ifndef OSSL_DEPRECATED
+#  undef OSSL_DEPRECATED_FOR
 #  ifndef OPENSSL_SUPPRESS_DEPRECATED
 #   if defined(__GNUC__)
-#    if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
-#     define OSSL_DEPRECATED __attribute__((deprecated))
+     /*
+      * According to GCC documentation, deprecations with message appeared in
+      * GCC 4.5.0
+      */
+#    if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+#     define OSSL_DEPRECATED(since) \
+          __attribute__((deprecated("Since OpenSSL " # since)))
+#     define OSSL_DEPRECATED_FOR(since, message) \
+          __attribute__((deprecated("Since OpenSSL " # since ";" message)))
+#    elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
+#     define OSSL_DEPRECATED(since) __attribute__((deprecated))
+#     define OSSL_DEPRECATED_FOR(since, message) __attribute__((deprecated))
 #    endif
 #   elif defined(__SUNPRO_C)
 #    if (__SUNPRO_C >= 0x5130)
-#     define OSSL_DEPRECATED __attribute__ ((deprecated))
+#     define OSSL_DEPRECATED(since) __attribute__ ((deprecated))
+#     define OSSL_DEPRECATED_FOR(since, message) __attribute__ ((deprecated))
 #    endif
 #   endif
 #  endif
@@ -46,7 +58,8 @@
 
 /* Still not defined?  Then define empty macros */
 # ifndef OSSL_DEPRECATED
-#  define OSSL_DEPRECATED
+#  define OSSL_DEPRECATED(since)
+#  define OSSL_DEPRECATED_FOR(since, message)
 # endif
 
 /*
 
 # if OPENSSL_API_LEVEL >= 30000
 #  ifndef OPENSSL_NO_DEPRECATED
-#   define DEPRECATEDIN_3_0(f)       OSSL_DEPRECATED f;
+#   define DEPRECATEDIN_3_0(f)       OSSL_DEPRECATED(3.0) f;
 #  else
 #   define DEPRECATEDIN_3_0(f)
 #   define OPENSSL_NO_DEPRECATED_3_0
 # endif
 # if OPENSSL_API_LEVEL >= 10101
 #  ifndef OPENSSL_NO_DEPRECATED
-#   define DEPRECATEDIN_1_1_1(f)     OSSL_DEPRECATED f;
+#   define DEPRECATEDIN_1_1_1(f)     OSSL_DEPRECATED(1.1.1) f;
 #  else
 #   define DEPRECATEDIN_1_1_1(f)
 #   define OPENSSL_NO_DEPRECATED_1_1_1
 # endif
 # if OPENSSL_API_LEVEL >= 10100
 #  ifndef OPENSSL_NO_DEPRECATED
-#   define DEPRECATEDIN_1_1_0(f)     OSSL_DEPRECATED f;
+#   define DEPRECATEDIN_1_1_0(f)     OSSL_DEPRECATED(1.1.0) f;
 #  else
 #   define DEPRECATEDIN_1_1_0(f)
 #   define OPENSSL_NO_DEPRECATED_1_1_0
 # endif
 # if OPENSSL_API_LEVEL >= 10002
 #  ifndef OPENSSL_NO_DEPRECATED
-#   define DEPRECATEDIN_1_0_2(f)     OSSL_DEPRECATED f;
+#   define DEPRECATEDIN_1_0_2(f)     OSSL_DEPRECATED(1.0.2) f;
 #  else
 #   define DEPRECATEDIN_1_0_2(f)
 #   define OPENSSL_NO_DEPRECATED_1_0_2
 # endif
 # if OPENSSL_API_LEVEL >= 10001
 #  ifndef OPENSSL_NO_DEPRECATED
-#   define DEPRECATEDIN_1_0_1(f)     OSSL_DEPRECATED f;
+#   define DEPRECATEDIN_1_0_1(f)     OSSL_DEPRECATED(1.0.1) f;
 #  else
 #   define DEPRECATEDIN_1_0_1(f)
 #   define OPENSSL_NO_DEPRECATED_1_0_1
 # endif
 # if OPENSSL_API_LEVEL >= 10000
 #  ifndef OPENSSL_NO_DEPRECATED
-#   define DEPRECATEDIN_1_0_0(f)     OSSL_DEPRECATED f;
+#   define DEPRECATEDIN_1_0_0(f)     OSSL_DEPRECATED(1.0.0) f;
 #  else
 #   define DEPRECATEDIN_1_0_0(f)
 #   define OPENSSL_NO_DEPRECATED_1_0_0
 # endif
 # if OPENSSL_API_LEVEL >= 908
 #  ifndef OPENSSL_NO_DEPRECATED
-#   define DEPRECATEDIN_0_9_8(f)     OSSL_DEPRECATED f;
+#   define DEPRECATEDIN_0_9_8(f)     OSSL_DEPRECATED(0.9.8) f;
 #  else
 #   define DEPRECATEDIN_0_9_8(f)
 #   define OPENSSL_NO_DEPRECATED_0_9_8