private void ApplyEncryption <T>(LXResponseCommandHandler <T> handler, CommandEncryption encryption) { Encryptor encryptor = _encryptorProvider.GetEncryptor(encryption); if (encryption != CommandEncryption.Request) { handler.Encoder = encryptor; if (encryption == CommandEncryption.RequestAndResponse) { handler.Decoder = encryptor; } } }
public async Task <LXResponse <T> > RequestCommandAsync <T>(string command, CommandEncryption encryption, RequestCommandValidation validation, CancellationToken cancellationToken) { try { var response = await RequestCommandInternalAsync <T>(command, encryption, cancellationToken).ConfigureAwait(false); string control = Uri.EscapeUriString(response.Control); if ((validation & RequestCommandValidation.Command) != 0 && !AreCommandsEqual(command, control)) { throw new MiniserverTransportException(); } if ((validation & RequestCommandValidation.Status) != 0 && !LXStatusCode.IsSuccess(response.Code)) { throw new MiniserverCommandException(response.Code); } return(response); } catch (ObjectDisposedException) { throw new MiniserverTransportException("No connection " + this.ClosedException?.Message, this.ClosedException); } }
public Encryptor(Session session, CommandEncryption mode) { Contract.Requires(session != null); this._session = session; this._mode = mode; }
protected override async Task <LXResponse <T> > RequestCommandInternalAsync <T>(string command, CommandEncryption encryption, CancellationToken cancellationToken) { var handler = new LXResponseCommandHandler <T>(); ApplyEncryption(handler, encryption); await EnqueueCommandAsync(command, handler, cancellationToken).ConfigureAwait(false); return(await handler.Task.ConfigureAwait(false)); }
protected override async Task <LXResponse <T> > RequestCommandInternalAsync <T>(string command, CommandEncryption encryption, CancellationToken cancellationToken) { EnsureHttpClient(); using var response = await _httpClient.GetAsync(command, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); if (response.IsSuccessStatusCode && HttpUtils.IsJsonMediaType(response.Content.Headers.ContentType)) { string contentStr = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var lxResponse = LXResponse <T> .Deserialize(contentStr); return(lxResponse); } else { throw new MiniserverTransportException(); } }
protected abstract Task <LXResponse <T> > RequestCommandInternalAsync <T>(string command, CommandEncryption encryption, CancellationToken cancellationToken);
public Task <LXResponse <T> > RequestCommandAsync <T>(string command, CommandEncryption encryption, CancellationToken cancellationToken) => RequestCommandAsync <T>(command, encryption, RequestCommandValidation.All, cancellationToken);