feat: Add SSH 2.0 data type codec with encoder and decoder #58
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements encoder and decoder for SSH 2.0 protocol data types according to RFC 4251 specification.
Overview
This PR adds a complete SSH 2.0 codec implementation in
src/ssh/following the same patterns as existing codecs (XDR, Avro, etc.). The implementation providesSshEncoderandSshDecoderclasses for encoding and decoding SSH protocol data types.Data Types Supported
All SSH 2.0 data types from RFC 4251 Section 5 are implemented:
writeBinStr()/readBinStr()- Binary data as Uint8ArraywriteStr()/readStr()- UTF-8 encoded stringswriteAsciiStr()/readAsciiStr()- ASCII encoded stringsJsonPackMpintclass)Usage Example
Implementation Details
Testing
Comprehensive test coverage with 83 tests:
All existing tests continue to pass (3,201 total tests).
Files Added
src/JsonPackMpint.ts- Multiple precision integer classsrc/ssh/SshEncoder.ts- SSH protocol encodersrc/ssh/SshDecoder.ts- SSH protocol decodersrc/ssh/index.ts- Module exportssrc/__tests__/JsonPackMpint.spec.ts- Mpint testssrc/ssh/__tests__/SshEncoder.spec.ts- Encoder testssrc/ssh/__tests__/SshDecoder.spec.ts- Decoder testssrc/ssh/__tests__/codec.spec.ts- Round-trip testsResolves #[issue-number]
Original prompt
This section details on the original issue you should resolve
<issue_title>Add SSH data type codec</issue_title>
<issue_description>Implement encoder and decoder for SSH 2.0 data types in
src/ssh/folder. ImplementSshEncoderandSshDecoder(see XDR codec atsrc/xdr/for reference).Data type representation in JavaScript:
uint32withnumber,uint64withbigint.mpintcreate a class insrc/JsonPackMpint.ts.name-listin POJO string arraystring[].bytemaps toUint8Array(.writeBin()and.readBin()).stringwill map to either JavaScriptstringorUint8Array..readBinStr(),.readStr()(UTF-8),.readAsciiStr()..writeBinStr(value: Uint8Array),.writeStr(value: string)(UTF-8),.writeAsciiStr(value: string).Specification: https://datatracker.ietf.org/doc/html/rfc4251
Excerpt: