-- RPC: Veneer over MesaMesaRPC.mesa for Cedar's benefit

-- File [Ivy]<Birrell>RPC>CedarRPCImpl.mesa

-- Andrew Birrell  July 6, 1982 3:42 pm
-- BZM		29-Oct-81 11:46:31
-- Taft		6-Oct-81 18:35:28


DIRECTORY
BodyDefs	USING [Password],
RPC		USING [EncryptionKey, Principal],
ConvertUnsafe	USING [AppendRope, ToRope],
Rope		USING [Length, ROPE],
MesaRPC		USING [AuthenticateFailed, Conversation, ConversationLevel,
		       GetCaller, MakeKey, maxPrincipalLength, StartConversation];


CedarRPCImpl: PROGRAM
  IMPORTS ConvertUnsafe, Rope, MesaRPC
  EXPORTS RPC =
  BEGIN

  MakeKey: PUBLIC PROC [text: Rope.ROPE] RETURNS[RPC.EncryptionKey] =
    BEGIN
    p: STRING = [64];
    ConvertUnsafe.AppendRope[p,text];
    RETURN[MesaRPC.MakeKey[p]]
    END;

  StartConversation: PUBLIC PROC[caller: RPC.Principal,
				 key: RPC.EncryptionKey,
			         callee: RPC.Principal,
			         level: MesaRPC.ConversationLevel ]
                         RETURNS[conversation: MesaRPC.Conversation] =
    BEGIN
    callerString: STRING = [MesaRPC.maxPrincipalLength];
    calleeString: STRING = [MesaRPC.maxPrincipalLength];
    IF Rope.Length[caller] > MesaRPC.maxPrincipalLength
    THEN ERROR MesaRPC.AuthenticateFailed[badCaller];
    IF Rope.Length[callee] > MesaRPC.maxPrincipalLength
    THEN ERROR MesaRPC.AuthenticateFailed[badCallee];
    ConvertUnsafe.AppendRope[to: callerString, from: caller];
    ConvertUnsafe.AppendRope[to: calleeString, from: callee];
    RETURN[ MesaRPC.StartConversation[callerString, key, calleeString, level] ];
    END;

  GetCaller: PUBLIC PROC[conversation: MesaRPC.Conversation]
                 RETURNS[caller: RPC.Principal] =
    { RETURN[ ConvertUnsafe.ToRope[from: MesaRPC.GetCaller[conversation]] ] };

END.