Exemplo n.º 1
0
        public MicroRatchetContext(IServices services, MicroRatchetConfiguration config, Stream stateData)
        {
            Services      = services ?? throw new ArgumentNullException(nameof(services));
            Configuration = config ?? throw new ArgumentNullException(nameof(config));

            KeyDerivation = new AesKdf(Services.AesFactory);

            LoadState(stateData);

            VerifyServices();
            CheckMtu();
        }
Exemplo n.º 2
0
        public MicroRatchetContext(IServices services, bool isClient, int?MaximumMessageSize = null, int?MinimumMessageSize = null, Stream stateData = null, byte[] stateBytes = null)
        {
            Services = services ?? throw new ArgumentNullException(nameof(services));

            if (stateData != null && stateBytes != null)
            {
                throw new InvalidOperationException("stateData and stateBytes cannot both be specified");
            }

            Configuration = new MicroRatchetConfiguration
            {
                IsClient = isClient
            };

            if (MaximumMessageSize.HasValue)
            {
                Configuration.MaximumMessageSize = MaximumMessageSize.Value;
            }

            if (MinimumMessageSize.HasValue)
            {
                Configuration.MinimumMessageSize = MinimumMessageSize.Value;
            }

            if (stateData != null)
            {
                LoadState(stateData);
            }
            else if (stateBytes != null)
            {
                using var ms = new MemoryStream(stateBytes);
                LoadState(ms);
            }
            else
            {
                InitializeState();
            }

            KeyDerivation = new AesKdf(Services.AesFactory);

            CheckMtu();
        }