/* Agent Tcl
   Bob Gray
   17 April 1996

   tclSecure.cc

   This file implements the library routines that handle security.

   Copyright (c) 1995-1996, Bob Gray, Dartmouth College

   See the file "agent.terms" for information on usage and redistribution
   of this file and for a DISCLAIMER OF ALL WARRANTIES.
*/

#include "tcl.h"
#include "agentTcl.h"
#include "agentTclInt.h"
#include "tclSecurity.h"

/* Agent_SetEncryption

   Purpose: Turn on or off encryption

     Input: interp = the Tcl interpreter
		     (struct Tcl_Interp *)

	    state  = e_TRUE to turn encryption on and e_FALSE to turn    
		     encryption off
		     (enum BOOLEAN)

    Output: The procedure returns TCL_ERROR and sets the interpreter result
	    to an appropriate error message on error.  Otherwise the procedure
            returns TCL_OK and sets encryption to the given state.
*/

int Agent_SetEncryption (Tcl_Interp *interp, BOOLEAN state)
{
    int code;
    AGENT_TCL *agent;
    SECURITY_TCL *security;

	/* assertions on the parameters */

    assert (interp != NULL);

	/* AGENT structure */

    agent = AGENT_TCL::get_agent (interp);
    assert (agent != NULL);

	/* SECURITY structure */

    security = (SECURITY_TCL *) agent -> get_security ();
    assert (security != NULL);

	/* turn on or off encryption */

    if ((code = security -> setEncryption (state)) == SECURITY_OK) {
	return TCL_OK;
    }

	/* error so construct the error code and message */

    Tcl_SetErrorCode (interp, security -> securityCodeToShortString(code).value(), (char *) NULL);
    Tcl_SetResult (interp, security -> securityCodeToLongString(code).value(), TCL_VOLATILE);
    return TCL_ERROR;
}

/* Agent_SetSignatures

   Purpose: Turn on or off signatures

     Input: interp = the Tcl interpreter
		     (struct Tcl_Interp *)

	    state  = e_TRUE to turn signatures on and e_FALSE to turn    
		     signatures off
		     (enum BOOLEAN)

    Output: The procedure returns TCL_ERROR and sets the interpreter result
	    to an appropriate error message on error.  Otherwise the procedure
            returns TCL_OK and sets signatures to the given state.
*/

int Agent_SetSignatures (Tcl_Interp *interp, BOOLEAN state)
{
    int code;
    AGENT_TCL *agent;
    SECURITY_TCL *security;

	/* assertions on the parameters */

    assert (interp != NULL);

	/* AGENT structure */

    agent = AGENT_TCL::get_agent (interp);
    assert (agent != NULL);

	/* SECURITY structure */

    security = (SECURITY_TCL *) agent -> get_security ();
    assert (security != NULL);

	/* turn on or off signatures */

    if ((code = security -> setSignatures (state)) == SECURITY_OK) {
	return TCL_OK;
    }

	/* error so construct an appropriate error code and message */

    Tcl_SetErrorCode (interp, security -> securityCodeToShortString(code).value(), (char *) NULL);
    Tcl_SetResult (interp, security -> securityCodeToLongString(code).value(), TCL_VOLATILE);
    return TCL_ERROR;
}
