import argparse
from rpm_rs import Package, Signer
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("rpm", help="Path to the RPM file")
parser.add_argument("key", help="Path to the private key file (ASCII-armored)")
parser.add_argument("output", help="Output path for the signed RPM")
args = parser.parse_args()
rpm_path, key_path, output_path = args.rpm, args.key, args.output
pkg = Package.open(rpm_path)
header_bytes = pkg.header_bytes()
print(f"Extracted {len(header_bytes)} header bytes for signing")
signer = Signer.from_file(key_path)
signature_bytes = signer.sign(header_bytes)
print(f"Received {len(signature_bytes)} signature bytes")
pkg.apply_signature(signature_bytes)
pkg.write_file(output_path)
print(f"Wrote signed package to {output_path}")