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