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