from pqc_binary_format import (
Algorithm,
EncParameters,
KemParameters,
PqcMetadata,
PqcBinaryFormat,
FormatFlags,
)
def main():
print("PQC Binary Format Python Example")
print("=" * 50)
print("\n1. Basic Encryption Format")
print("-" * 50)
algorithm = Algorithm("hybrid")
print(f"Algorithm: {algorithm.name()} (ID: {algorithm.id()})")
enc_params = EncParameters(
iv=bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), tag=bytes([0] * 16), )
metadata = PqcMetadata(
enc_params=enc_params,
kem_params=None,
sig_params=None,
compression_params=None,
)
encrypted_data = bytes([1, 2, 3, 4, 5])
pqc_format = PqcBinaryFormat(algorithm, metadata, encrypted_data)
serialized = pqc_format.to_bytes()
print(f"Serialized size: {len(serialized)} bytes")
print(f"Total format size: {pqc_format.total_size()} bytes")
deserialized = PqcBinaryFormat.from_bytes(serialized)
print(f"Deserialized algorithm: {deserialized.algorithm().name()}")
print(f"Data length: {len(deserialized.data())} bytes")
deserialized.validate()
print("✓ Validation passed")
print("\n2. Format with KEM Parameters")
print("-" * 50)
kem_params = KemParameters(
public_key=bytes([0] * 1568), ciphertext=bytes([0] * 1568), )
metadata_with_kem = PqcMetadata(
enc_params=enc_params,
kem_params=kem_params,
sig_params=None,
compression_params=None,
)
pqc_with_kem = PqcBinaryFormat(algorithm, metadata_with_kem, encrypted_data)
serialized_with_kem = pqc_with_kem.to_bytes()
print(f"Serialized size with KEM: {len(serialized_with_kem)} bytes")
print("\n3. Format with Feature Flags")
print("-" * 50)
flags = FormatFlags().with_compression().with_streaming()
print(f"Compression enabled: {flags.has_compression()}")
print(f"Streaming enabled: {flags.has_streaming()}")
print(f"Additional auth: {flags.has_additional_auth()}")
pqc_with_flags = PqcBinaryFormat.with_flags(
algorithm, flags, metadata, encrypted_data
)
print(f"Format with flags size: {pqc_with_flags.total_size()} bytes")
print("\n4. Algorithm Comparison")
print("-" * 50)
algorithms = ["classical", "hybrid", "post-quantum", "ml-kem-1024"]
for alg_name in algorithms:
alg = Algorithm(alg_name)
fmt = PqcBinaryFormat(alg, metadata, encrypted_data)
size = fmt.total_size()
print(f"{alg.name():<20} - {size} bytes")
print("\n✓ All examples completed successfully!")
if __name__ == "__main__":
main()