fc5871
# HG changeset patch
fc5871
# User Rob Lemley <rob@thunderbird.net>
fc5871
# Date 1663866557 14400
fc5871
#      Thu Sep 22 13:09:17 2022 -0400
fc5871
# Node ID 121afb4ed9b0e282cf6690736ffadf1498578434
fc5871
# Parent  0798506e89ab0ad98d5826effe2087c2e2560d0b
fc5871
Bug 1790116 - mozbuild changes for RNP v0.16.2. r=kaie
fc5871
hash_sha1cd.cpp moved up to its parent directory.
fc5871
fc5871
ENABLE_IDEA needs to be set to keep support enabled.
fc5871
https://github.com/rnpgp/rnp/commit/17972d0238919d4abf88b04debce95844be4716d
fc5871
fc5871
Update rnp_symbols.py to not include deprecated functions.
fc5871
Added new symbols to rnp.symbols for export.
fc5871
fc5871
Differential Revision: https://phabricator.services.mozilla.com/D157012
fc5871
fc5871
diff --git a/comm/python/thirdroc/thirdroc/rnp_symbols.py b/python/thirdroc/thirdroc/rnp_symb/commols.py
fc5871
--- a/comm/python/thirdroc/thirdroc/rnp_symbols.py
fc5871
+++ b/comm/python/thirdroc/thirdroc/rnp_symbols.py
fc5871
@@ -14,30 +14,75 @@ the third_party/rnp/include/rnp/rnp.h fo
fc5871
 Also note that APIs that are marked deprecated are not checked for.
fc5871
 
fc5871
 Dependencies: Only Python 3
fc5871
 
fc5871
 Running:
fc5871
-  python3 rnp_symbols.py
fc5871
+  python3 rnp_symbols.py [-h] [rnp.h path] [rnp.symbols path]
fc5871
 
fc5871
-Output will be on stdout, this is to give the developer the opportunity to compare the old and
fc5871
-new versions and check for accuracy.
fc5871
+Both file path arguments are optional. By default, the header file will be
fc5871
+read from "comm/third_party/rnp/include/rnp/rnp.h" and the symbols file will
fc5871
+be written to "comm/third_party/rnp/rnp.symbols".
fc5871
+
fc5871
+Path arguments are relative to the current working directory, the defaults
fc5871
+will be determined based on the location of this script.
fc5871
+
fc5871
+Either path argument can be '-' to use stdin or stdout respectively.
fc5871
 """
fc5871
 
fc5871
-from __future__ import absolute_import, print_function
fc5871
-
fc5871
+import argparse
fc5871
 import sys
fc5871
 import os
fc5871
 import re
fc5871
 
fc5871
 HERE = os.path.dirname(__file__)
fc5871
 TOPSRCDIR = os.path.abspath(os.path.join(HERE, "../../../../"))
fc5871
-RNPSRCDIR = os.path.join(TOPSRCDIR, "comm/third_party/rnp")
fc5871
+THIRD_SRCDIR = os.path.join(TOPSRCDIR, "comm/third_party")
fc5871
+HEADER_FILE_REL = "rnp/include/rnp/rnp.h"
fc5871
+HEADER_FILE = os.path.join(THIRD_SRCDIR, HEADER_FILE_REL)
fc5871
+SYMBOLS_FILE_REL = "rnp/rnp.symbols"
fc5871
+SYMBOLS_FILE = os.path.join(THIRD_SRCDIR, SYMBOLS_FILE_REL)
fc5871
 
fc5871
 
fc5871
 FUNC_DECL_RE = re.compile(r"^RNP_API\s+.*?([a-zA-Z0-9_]+)\(.*$")
fc5871
 
fc5871
 
fc5871
+class FileArg:
fc5871
+    """Based on argparse.FileType from the Python standard library.
fc5871
+    Modified to not open the filehandles until the open() method is
fc5871
+    called.
fc5871
+    """
fc5871
+
fc5871
+    def __init__(self, mode="r"):
fc5871
+        self._mode = mode
fc5871
+        self._fp = None
fc5871
+        self._file = None
fc5871
+
fc5871
+    def __call__(self, string):
fc5871
+        # the special argument "-" means sys.std{in,out}
fc5871
+        if string == "-":
fc5871
+            if "r" in self._mode:
fc5871
+                self._fp = sys.stdin.buffer if "b" in self._mode else sys.stdin
fc5871
+            elif "w" in self._mode:
fc5871
+                self._fp = sys.stdout.buffer if "b" in self._mode else sys.stdout
fc5871
+            else:
fc5871
+                raise ValueError(f"Invalid mode {self._mode} for stdin/stdout")
fc5871
+        else:
fc5871
+            if "r" in self._mode:
fc5871
+                if not os.path.isfile(string):
fc5871
+                    raise ValueError(f"Cannot read file {string}, does not exist.")
fc5871
+            elif "w" in self._mode:
fc5871
+                if not os.access(string, os.W_OK):
fc5871
+                    raise ValueError(f"Cannot write file {string}, permission denied.")
fc5871
+            self._file = string
fc5871
+        return self
fc5871
+
fc5871
+    def open(self):
fc5871
+        if self._fp:
fc5871
+            return self._fp
fc5871
+        return open(self._file, self._mode)
fc5871
+
fc5871
+
fc5871
 def get_func_name(line):
fc5871
     """
fc5871
     Extract the function name from a RNP_API function declaration.
fc5871
     Examples:
fc5871
     RNP_API rnp_result_t rnp_enable_debug(const char *file);
fc5871
@@ -46,24 +91,41 @@ def get_func_name(line):
fc5871
     """
fc5871
     m = FUNC_DECL_RE.match(line)
fc5871
     return m.group(1)
fc5871
 
fc5871
 
fc5871
-def extract_func_defs(filename):
fc5871
+def extract_func_defs(filearg):
fc5871
     """
fc5871
     Look for RNP_API in the header file to find the names of the symbols that should be exported
fc5871
     """
fc5871
-    with open(filename) as fp:
fc5871
+    with filearg.open() as fp:
fc5871
         for line in fp:
fc5871
-            if line.startswith("RNP_API"):
fc5871
+            if line.startswith("RNP_API") and "RNP_DEPRECATED" not in line:
fc5871
                 func_name = get_func_name(line)
fc5871
                 yield func_name
fc5871
 
fc5871
 
fc5871
 if __name__ == "__main__":
fc5871
-    if len(sys.argv) > 1:
fc5871
-        FILENAME = sys.argv[1]
fc5871
-    else:
fc5871
-        FILENAME = os.path.join(RNPSRCDIR, "include/rnp/rnp.h")
fc5871
+    parser = argparse.ArgumentParser(
fc5871
+        description="Update rnp.symbols file from rnp.h",
fc5871
+        epilog="To use stdin or stdout pass '-' for the argument.",
fc5871
+    )
fc5871
+    parser.add_argument(
fc5871
+        "header_file",
fc5871
+        default=HEADER_FILE,
fc5871
+        type=FileArg("r"),
fc5871
+        nargs="?",
fc5871
+        help=f"input path to rnp.h header file (default: {HEADER_FILE_REL})",
fc5871
+    )
fc5871
+    parser.add_argument(
fc5871
+        "symbols_file",
fc5871
+        default=SYMBOLS_FILE,
fc5871
+        type=FileArg("w"),
fc5871
+        nargs="?",
fc5871
+        help=f"output path to symbols file (default: {SYMBOLS_FILE_REL})",
fc5871
+    )
fc5871
 
fc5871
-    for f in sorted(list(extract_func_defs(FILENAME))):
fc5871
-        print(f)
fc5871
+    args = parser.parse_args()
fc5871
+
fc5871
+    with args.symbols_file.open() as out_fp:
fc5871
+        for symbol in sorted(list(extract_func_defs(args.header_file))):
fc5871
+            out_fp.write(f"{symbol}\n")
fc5871
diff --git a/comm/third_party/rnp/moz.build b/third_party/rnp/moz.b/commuild
fc5871
--- a/comm/third_party/rnp/moz.build
fc5871
+++ b/comm/third_party/rnp/moz.build
fc5871
@@ -41,10 +41,11 @@ rnp_defines = {
fc5871
     "HAVE_ZLIB_H": True,
fc5871
     "CRYPTO_BACKEND_BOTAN": True,
fc5871
     "ENABLE_AEAD": True,
fc5871
     "ENABLE_TWOFISH": True,
fc5871
     "ENABLE_BRAINPOOL": True,
fc5871
+    "ENABLE_IDEA": True,
fc5871
     "PACKAGE_BUGREPORT": '"https://bugzilla.mozilla.org/enter_bug.cgi?product=Thunderbird"',
fc5871
     "PACKAGE_STRING": '"rnp {}"'.format(CONFIG["MZLA_LIBRNP_FULL_VERSION"])
fc5871
 }
fc5871
 GeneratedFile(
fc5871
     "src/lib/config.h",
fc5871
@@ -119,16 +120,16 @@ SOURCES += [
fc5871
     "src/lib/crypto/ecdsa.cpp",
fc5871
     "src/lib/crypto/eddsa.cpp",
fc5871
     "src/lib/crypto/elgamal.cpp",
fc5871
     "src/lib/crypto/hash.cpp",
fc5871
     "src/lib/crypto/hash_common.cpp",
fc5871
+    "src/lib/crypto/hash_sha1cd.cpp",
fc5871
     "src/lib/crypto/mem.cpp",
fc5871
     "src/lib/crypto/mpi.cpp",
fc5871
     "src/lib/crypto/rng.cpp",
fc5871
     "src/lib/crypto/rsa.cpp",
fc5871
     "src/lib/crypto/s2k.cpp",
fc5871
-    "src/lib/crypto/sha1cd/hash_sha1cd.cpp",
fc5871
     "src/lib/crypto/sha1cd/sha1.c",
fc5871
     "src/lib/crypto/sha1cd/ubc_check.c",
fc5871
     "src/lib/crypto/signatures.cpp",
fc5871
     "src/lib/crypto/symmetric.cpp",
fc5871
     "src/lib/fingerprint.cpp",
fc5871
diff --git a/comm/third_party/rnp/rnp.symbols b/third_party/rnp/rnp.symb/commols
fc5871
--- a/comm/third_party/rnp/rnp.symbols
fc5871
+++ b/comm/third_party/rnp/rnp.symbols
fc5871
@@ -37,10 +37,11 @@ rnp_import_keys
fc5871
 rnp_import_signatures
fc5871
 rnp_input_destroy
fc5871
 rnp_input_from_callback
fc5871
 rnp_input_from_memory
fc5871
 rnp_input_from_path
fc5871
+rnp_input_from_stdin
fc5871
 rnp_key_25519_bits_tweak
fc5871
 rnp_key_25519_bits_tweaked
fc5871
 rnp_key_add_uid
fc5871
 rnp_key_allows_usage
fc5871
 rnp_key_export
fc5871
@@ -75,10 +76,11 @@ rnp_key_get_uid_count
fc5871
 rnp_key_get_uid_handle_at
fc5871
 rnp_key_handle_destroy
fc5871
 rnp_key_have_public
fc5871
 rnp_key_have_secret
fc5871
 rnp_key_is_compromised
fc5871
+rnp_key_is_expired
fc5871
 rnp_key_is_locked
fc5871
 rnp_key_is_primary
fc5871
 rnp_key_is_protected
fc5871
 rnp_key_is_retired
fc5871
 rnp_key_is_revoked
fc5871
@@ -112,10 +114,11 @@ rnp_op_encrypt_set_cipher
fc5871
 rnp_op_encrypt_set_compression
fc5871
 rnp_op_encrypt_set_creation_time
fc5871
 rnp_op_encrypt_set_expiration_time
fc5871
 rnp_op_encrypt_set_file_mtime
fc5871
 rnp_op_encrypt_set_file_name
fc5871
+rnp_op_encrypt_set_flags
fc5871
 rnp_op_encrypt_set_hash
fc5871
 rnp_op_generate_add_pref_cipher
fc5871
 rnp_op_generate_add_pref_compression
fc5871
 rnp_op_generate_add_pref_hash
fc5871
 rnp_op_generate_add_usage
fc5871
@@ -169,10 +172,11 @@ rnp_op_verify_get_signature_at
fc5871
 rnp_op_verify_get_signature_count
fc5871
 rnp_op_verify_get_symenc_at
fc5871
 rnp_op_verify_get_symenc_count
fc5871
 rnp_op_verify_get_used_recipient
fc5871
 rnp_op_verify_get_used_symenc
fc5871
+rnp_op_verify_set_flags
fc5871
 rnp_op_verify_signature_get_handle
fc5871
 rnp_op_verify_signature_get_hash
fc5871
 rnp_op_verify_signature_get_key
fc5871
 rnp_op_verify_signature_get_status
fc5871
 rnp_op_verify_signature_get_times
fc5871
@@ -185,21 +189,24 @@ rnp_output_to_armor
fc5871
 rnp_output_to_callback
fc5871
 rnp_output_to_file
fc5871
 rnp_output_to_memory
fc5871
 rnp_output_to_null
fc5871
 rnp_output_to_path
fc5871
+rnp_output_to_stdout
fc5871
 rnp_output_write
fc5871
 rnp_recipient_get_alg
fc5871
 rnp_recipient_get_keyid
fc5871
 rnp_remove_security_rule
fc5871
 rnp_request_password
fc5871
 rnp_result_to_string
fc5871
 rnp_save_keys
fc5871
+rnp_set_timestamp
fc5871
 rnp_signature_get_alg
fc5871
 rnp_signature_get_creation
fc5871
 rnp_signature_get_expiration
fc5871
 rnp_signature_get_hash_alg
fc5871
+rnp_signature_get_key_fprint
fc5871
 rnp_signature_get_keyid
fc5871
 rnp_signature_get_signer
fc5871
 rnp_signature_get_type
fc5871
 rnp_signature_handle_destroy
fc5871
 rnp_signature_is_valid