import sys
from rpm_rs import Package, Signer
if len(sys.argv) < 4:
print("Usage: remote_signing.py <rpm-file> <private-key> <output>", file=sys.stderr)
sys.exit(1)
rpm_path, key_path, output_path = sys.argv[1], sys.argv[2], sys.argv[3]
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}")