Skip to content

Commit e2cf28a

Browse files
committed
Remove Encoding from SubsystemSession and NetConfSession, and move it to SftpSession (as it is only used there).
Refactor creation of SFTP response messages to a SftpResponseFactory. Implement SaveData for a few SFTP response messages.
1 parent 9ecfa0d commit e2cf28a

File tree

61 files changed

+1616
-509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1616
-509
lines changed

src/Renci.SshNet.NETCore/Renci.SshNet.NETCore.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@
9797
<Version>4.0.1</Version>
9898
</PackageReference>
9999
</ItemGroup>
100+
<ItemGroup>
101+
<Compile Update="..\Renci.SshNet\Sftp\ISftpMessageFactory.cs" Link="Sftp\ISftpResponseFactory.cs" />
102+
<Compile Update="..\Renci.SshNet\Sftp\SftpMessageFactory.cs" Link="Sftp\SftpResponseFactory.cs" />
103+
</ItemGroup>
100104
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
101105
<DefineConstants>TRACE;DEBUG;FEATURE_ENCODING_ASCII;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_MEMORYSTREAM_TRYGETBUFFER;FEATURE_REFLECTION_TYPEINFO;FEATURE_RNG_CREATE;FEATURE_SOCKET_TAP;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SETSOCKETOPTION;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_DNS_TAP;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512</DefineConstants>
102106
</PropertyGroup>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Renci.SshNet.Sftp.Responses;
2+
3+
namespace Renci.SshNet.Tests.Classes.Sftp
4+
{
5+
internal class SftpDataResponseBuilder
6+
{
7+
private uint _protocolVersion;
8+
private uint _responseId;
9+
private byte[] _data;
10+
11+
public SftpDataResponseBuilder WithProtocolVersion(uint protocolVersion)
12+
{
13+
_protocolVersion = protocolVersion;
14+
return this;
15+
}
16+
17+
public SftpDataResponseBuilder WithResponseId(uint responseId)
18+
{
19+
_responseId = responseId;
20+
return this;
21+
}
22+
23+
public SftpDataResponseBuilder WithData(byte[] data)
24+
{
25+
_data = data;
26+
return this;
27+
}
28+
29+
public SftpDataResponse Build()
30+
{
31+
return new SftpDataResponse(_protocolVersion)
32+
{
33+
ResponseId = _responseId,
34+
Data = _data
35+
};
36+
}
37+
}
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Renci.SshNet.Sftp;
2+
using Renci.SshNet.Sftp.Responses;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace Renci.SshNet.Tests.Classes.Sftp
7+
{
8+
internal class SftpHandleResponseBuilder
9+
{
10+
private uint _protocolVersion;
11+
private uint _responseId;
12+
private byte[] _handle;
13+
14+
public SftpHandleResponseBuilder WithProtocolVersion(uint protocolVersion)
15+
{
16+
_protocolVersion = protocolVersion;
17+
return this;
18+
}
19+
20+
public SftpHandleResponseBuilder WithResponseId(uint responseId)
21+
{
22+
_responseId = responseId;
23+
return this;
24+
}
25+
26+
public SftpHandleResponseBuilder WithHandle(byte[] handle)
27+
{
28+
_handle = handle;
29+
return this;
30+
}
31+
32+
public SftpHandleResponse Build()
33+
{
34+
var sftpHandleResponse = new SftpHandleResponse(_protocolVersion)
35+
{
36+
ResponseId = _responseId,
37+
Handle = _handle
38+
};
39+
return sftpHandleResponse;
40+
}
41+
}
42+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Renci.SshNet.Sftp.Requests;
2+
3+
namespace Renci.SshNet.Tests.Classes.Sftp
4+
{
5+
internal class SftpInitRequestBuilder
6+
{
7+
private uint _version;
8+
9+
public SftpInitRequestBuilder WithVersion(uint version)
10+
{
11+
_version = version;
12+
return this;
13+
}
14+
15+
public SftpInitRequest Build()
16+
{
17+
return new SftpInitRequest(_version);
18+
}
19+
}
20+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using Renci.SshNet.Sftp;
2+
using Renci.SshNet.Sftp.Responses;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace Renci.SshNet.Tests.Classes.Sftp
7+
{
8+
internal class SftpNameResponseBuilder
9+
{
10+
private uint _responseId;
11+
private uint _protocolVersion;
12+
private Encoding _encoding;
13+
private List<KeyValuePair<string, SftpFileAttributes>> _files;
14+
15+
public SftpNameResponseBuilder()
16+
{
17+
_files = new List<KeyValuePair<string, SftpFileAttributes>>();
18+
}
19+
20+
public SftpNameResponseBuilder WithProtocolVersion(uint protocolVersion)
21+
{
22+
_protocolVersion = protocolVersion;
23+
return this;
24+
}
25+
26+
public SftpNameResponseBuilder WithResponseId(uint responseId)
27+
{
28+
_responseId = responseId;
29+
return this;
30+
}
31+
32+
public SftpNameResponseBuilder WithFiles(params KeyValuePair<string, SftpFileAttributes>[] files)
33+
{
34+
for (var i = 0; i < files.Length; i++)
35+
_files.Add(files[i]);
36+
return this;
37+
}
38+
39+
public SftpNameResponseBuilder WithFile(string filename, SftpFileAttributes attributes)
40+
{
41+
_files.Add(new KeyValuePair<string, SftpFileAttributes>(filename, attributes));
42+
return this;
43+
}
44+
45+
public SftpNameResponseBuilder WithEncoding(Encoding encoding)
46+
{
47+
_encoding = encoding;
48+
return this;
49+
}
50+
51+
public SftpNameResponse Build()
52+
{
53+
var sftpNameResponse = new SftpNameResponse(_protocolVersion, _encoding)
54+
{
55+
ResponseId = _responseId,
56+
Files = _files.ToArray()
57+
};
58+
return sftpNameResponse;
59+
}
60+
}
61+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using Renci.SshNet.Sftp;
2+
using Renci.SshNet.Sftp.Requests;
3+
using Renci.SshNet.Sftp.Responses;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
9+
namespace Renci.SshNet.Tests.Classes.Sftp
10+
{
11+
internal class SftpOpenRequestBuilder
12+
{
13+
private uint _protocolVersion;
14+
private uint _requestId;
15+
private string _fileName;
16+
private Encoding _encoding;
17+
private Flags _flags;
18+
private Action<SftpHandleResponse> _handleAction;
19+
private Action<SftpStatusResponse> _statusAction;
20+
21+
public SftpOpenRequestBuilder WithProtocolVersion(uint protocolVersion)
22+
{
23+
_protocolVersion = protocolVersion;
24+
return this;
25+
}
26+
27+
public SftpOpenRequestBuilder WithRequestId(uint requestId)
28+
{
29+
_requestId = requestId;
30+
return this;
31+
}
32+
33+
public SftpOpenRequestBuilder WithFileName(string fileName)
34+
{
35+
_fileName = fileName;
36+
return this;
37+
}
38+
39+
public SftpOpenRequestBuilder WithEncoding(Encoding encoding)
40+
{
41+
_encoding = encoding;
42+
return this;
43+
}
44+
45+
public SftpOpenRequestBuilder WithFlags(Flags flags)
46+
{
47+
_flags = flags;
48+
return this;
49+
}
50+
51+
public SftpOpenRequestBuilder WithDataAction(Action<SftpHandleResponse> handleAction)
52+
{
53+
_handleAction = handleAction;
54+
return this;
55+
}
56+
57+
public SftpOpenRequestBuilder WithStatusAction(Action<SftpStatusResponse> statusAction)
58+
{
59+
_statusAction = statusAction;
60+
return this;
61+
}
62+
63+
public SftpOpenRequest Build()
64+
{
65+
var handleAction = _handleAction ?? ((handleResponse) => { });
66+
var statusAction = _statusAction ?? ((statusResponse) => { });
67+
68+
return new SftpOpenRequest(_protocolVersion, _requestId, _fileName, _encoding, _flags, handleAction, statusAction);
69+
}
70+
}
71+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using Renci.SshNet.Sftp.Requests;
2+
using Renci.SshNet.Sftp.Responses;
3+
using System;
4+
5+
namespace Renci.SshNet.Tests.Classes.Sftp
6+
{
7+
internal class SftpReadRequestBuilder
8+
{
9+
private uint _protocolVersion;
10+
private uint _requestId;
11+
private byte[] _handle;
12+
private uint _offset;
13+
private uint _length;
14+
private Action<SftpDataResponse> _dataAction;
15+
private Action<SftpStatusResponse> _statusAction;
16+
17+
public SftpReadRequestBuilder WithProtocolVersion(uint protocolVersion)
18+
{
19+
_protocolVersion = protocolVersion;
20+
return this;
21+
}
22+
23+
public SftpReadRequestBuilder WithRequestId(uint requestId)
24+
{
25+
_requestId = requestId;
26+
return this;
27+
}
28+
29+
public SftpReadRequestBuilder WithHandle(byte[] handle)
30+
{
31+
_handle = handle;
32+
return this;
33+
}
34+
35+
public SftpReadRequestBuilder WithOffset(uint offset)
36+
{
37+
_offset = offset;
38+
return this;
39+
}
40+
41+
public SftpReadRequestBuilder WithLength(uint length)
42+
{
43+
_length = length;
44+
return this;
45+
}
46+
47+
public SftpReadRequestBuilder WithDataAction(Action<SftpDataResponse> dataAction)
48+
{
49+
_dataAction = dataAction;
50+
return this;
51+
}
52+
53+
public SftpReadRequestBuilder WithStatusAction(Action<SftpStatusResponse> statusAction)
54+
{
55+
_statusAction = statusAction;
56+
return this;
57+
}
58+
59+
public SftpReadRequest Build()
60+
{
61+
var dataAction = _dataAction ?? ((dataResponse) => { });
62+
var statusAction = _statusAction ?? ((statusResponse) => { });
63+
64+
return new SftpReadRequest(_protocolVersion, _requestId, _handle, _offset, _length, dataAction, statusAction);
65+
}
66+
}
67+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using Renci.SshNet.Sftp.Requests;
2+
using Renci.SshNet.Sftp.Responses;
3+
using System;
4+
using System.Text;
5+
6+
namespace Renci.SshNet.Tests.Classes.Sftp
7+
{
8+
internal class SftpRealPathRequestBuilder
9+
{
10+
private uint _protocolVersion;
11+
private uint _requestId;
12+
private string _path;
13+
private Encoding _encoding;
14+
private Action<SftpNameResponse> _nameAction;
15+
private Action<SftpStatusResponse> _statusAction;
16+
17+
public SftpRealPathRequestBuilder WithProtocolVersion(uint protocolVersion)
18+
{
19+
_protocolVersion = protocolVersion;
20+
return this;
21+
}
22+
23+
public SftpRealPathRequestBuilder WithRequestId(uint requestId)
24+
{
25+
_requestId = requestId;
26+
return this;
27+
}
28+
29+
public SftpRealPathRequestBuilder WithPath(string path)
30+
{
31+
_path = path;
32+
return this;
33+
}
34+
35+
public SftpRealPathRequestBuilder WithEncoding(Encoding encoding)
36+
{
37+
_encoding = encoding;
38+
return this;
39+
}
40+
41+
public SftpRealPathRequestBuilder WithNameAction(Action<SftpNameResponse> nameAction)
42+
{
43+
_nameAction = nameAction;
44+
return this;
45+
}
46+
47+
public SftpRealPathRequestBuilder WithStatusAction(Action<SftpStatusResponse> statusAction)
48+
{
49+
_statusAction = statusAction;
50+
return this;
51+
}
52+
53+
public SftpRealPathRequest Build()
54+
{
55+
var nameAction = _nameAction ?? ((nameResponse) => { });
56+
var statusAction = _statusAction ?? ((statusResponse) => { });
57+
58+
return new SftpRealPathRequest(_protocolVersion, _requestId, _path, _encoding, nameAction, statusAction);
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)