# ------------------------------------------------------------
# PSUT IoT Engineering Studio | CR75
# Experiment: certificate trust chain and revocation decisions
# Purpose: expose algorithm states and verify the experiment invariant.
# ------------------------------------------------------------
# CR75 | Certificate trust chain and revocation decisions
# Execute the named operation; expose states and assert the laboratory invariant.
import json



DEFAULT={'trusted': True, 'intermediate': True, 'time_valid': True, 'hostname_valid': True, 'revoked': False}
ALTERNATE={'hostname_valid': False}

def run(overrides=None):
    # Merge only explicitly supplied inputs with the lecture baseline.
    params={**DEFAULT, **(overrides or {})}
    trusted=params['trusted']
    intermediate=params['intermediate']
    time_valid=params['time_valid']
    hostname_valid=params['hostname_valid']
    revoked=params['revoked']
    checks={'trusted root':trusted,'intermediate supplied':intermediate,'validity period':time_valid,'hostname matches':hostname_valid,'not revoked under configured policy':not revoked};steps=[{'check':k,'pass':v} for k,v in checks.items()];result={'accepted':all(checks.values()),'failed':[k for k,v in checks.items() if not v]}
    # Independently check the stated mathematical or protocol invariant.
    assert result["accepted"]== (trusted and intermediate and time_valid and hostname_valid and not revoked), "verification failed"
    return {"steps":steps,"result":result}

if __name__ == "__main__":
    import argparse
    parser=argparse.ArgumentParser();parser.add_argument("--inputs",default="{}");parser.add_argument("--test",action="store_true");args=parser.parse_args()
    if args.test:
        for case in [{},ALTERNATE]:run(case)
        print("PASS")
    else:print(json.dumps(run(json.loads(args.inputs)),indent=2))
