# ------------------------------------------------------------
# PSUT IoT Engineering Studio | CR81
# Experiment: ssh transport user authentication and channels
# Purpose: expose algorithm states and verify the experiment invariant.
# ------------------------------------------------------------
# CR81 | SSH transport, user authentication and channels
# Execute the named operation; expose states and assert the laboratory invariant.
import json



DEFAULT={'host_trusted': True, 'user_authorized': True}
ALTERNATE={'host_trusted': False}

def run(overrides=None):
    # Merge only explicitly supplied inputs with the lecture baseline.
    params={**DEFAULT, **(overrides or {})}
    host_trusted=params['host_trusted']
    user_authorized=params['user_authorized']
    if type(host_trusted) is not bool or type(user_authorized) is not bool:
        raise ValueError('Invalid classroom input')
    steps=[{'state':'version exchange and key exchange'},{'state':'verify host key','trusted':host_trusted}]
    if host_trusted:steps.append({'state':'verify user public-key proof','authorized':user_authorized})
    accepted=host_trusted and user_authorized;steps.append({'state':'open session channel' if accepted else 'abort'});result={'channel_open':accepted}
    # Independently check the stated mathematical or protocol invariant.
    assert result["channel_open"]==(host_trusted and user_authorized), "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))
