% MJSSession - Holds all transient security data specific to this MATLAB client

% Copyright 2020-2021 The MathWorks, Inc.

classdef MJSSession < handle
    
    properties (SetAccess = immutable)
        % Unique ID for this session which is paired to the lifetime of the
        % corresponding session on the job manager
        SessionID
        
        % Factory for creating encryptors
        EncryptorFactory
               
        % Chain of digest algorithms
        DigestAlgorithmChain
                
        % Digester to hash a byte array
        Digester
        
        % String encoder to encode a char vector to a byte array
        StringEncoder
    end
    
    methods
        function obj = MJSSession(sessionID, encryptionAlgorithm, encryptorPublicKeyBytes, ...
                digestAlgorithmChain, stringEncoder)
            obj.SessionID = sessionID;
            obj.EncryptorFactory = parallel.internal.cluster.EncryptorFactory(...
                sessionID, encryptionAlgorithm, encryptorPublicKeyBytes);
            obj.DigestAlgorithmChain = digestAlgorithmChain;
            obj.Digester = digestAlgorithmChain.createDigester();
            obj.StringEncoder = stringEncoder;
        end
        
        function encryptor = createEncryptor(obj)
            encryptor = obj.EncryptorFactory.create();
        end
    end
end

