generated from JeanOUINA/typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: publickey & password authentication
Publickey authentication still has some issue when connecting to openssh servers
- Loading branch information
Showing
33 changed files
with
1,545 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
decodeBigIntBE, | ||
decodeBigIntLE, | ||
encodeBigIntBE, | ||
encodeBigIntLE, | ||
} from "../../src/utils/BigInt" | ||
|
||
describe("BigInt Utils", () => { | ||
test("encode BigInt Big-Endian", () => { | ||
const result = encodeBigIntBE(0x1234567890abcdefn) | ||
expect(result.toString("hex")).toBe("1234567890abcdef") | ||
}) | ||
|
||
test("encode BigInt Little-Endian", () => { | ||
const result = encodeBigIntLE(0x1234567890abcdefn) | ||
expect(result.toString("hex")).toBe("efcdab9078563412") | ||
}) | ||
|
||
test("decode BigInt Big-Endian", () => { | ||
const result = encodeBigIntBE(0x1234567890abcdefn) | ||
expect(decodeBigIntBE(result)).toBe(0x1234567890abcdefn) | ||
}) | ||
|
||
test("decode BigInt Little-Endian", () => { | ||
const result = encodeBigIntLE(0x1234567890abcdefn) | ||
expect(decodeBigIntLE(result)).toBe(0x1234567890abcdefn) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { parseBinaryBoolean, serializeBinaryBoolean } from "../../src/utils/BinaryBoolean" | ||
|
||
describe("BinaryBoolean Utils", () => { | ||
test("Should be parseable", () => { | ||
expect(parseBinaryBoolean(Buffer.from([0]))).toBe(false) | ||
expect(parseBinaryBoolean(Buffer.from([1]))).toBe(true) | ||
}) | ||
|
||
test("Should not be parseable", () => { | ||
expect(() => parseBinaryBoolean(Buffer.from([2]))).toThrow() | ||
expect(() => parseBinaryBoolean(Buffer.from([0, 1]))).toThrow() | ||
}) | ||
|
||
test("Should serialize", () => { | ||
expect(serializeBinaryBoolean(false)).toEqual(Buffer.from([0])) | ||
expect(serializeBinaryBoolean(true)).toEqual(Buffer.from([1])) | ||
}) | ||
|
||
test("Should not serialize", () => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
expect(() => serializeBinaryBoolean(null)).toThrow() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { | ||
readNextBuffer, | ||
readNextUint8, | ||
readNextUint32, | ||
readNextBinaryBoolean, | ||
serializeBuffer, | ||
serializeUint8, | ||
serializeUint32, | ||
} from "../../src/utils/Buffer" | ||
|
||
describe("Buffer Utils", () => { | ||
describe("readNextBuffer", () => { | ||
it("should read the next buffer correctly", () => { | ||
const buffer = Buffer.from([0x00, 0x00, 0x00, 0x04, 0x61, 0x62, 0x63, 0x64]) | ||
const [data, remaining] = readNextBuffer(buffer) | ||
expect(data).toStrictEqual(Buffer.from([0x61, 0x62, 0x63, 0x64])) | ||
expect(remaining).toStrictEqual(Buffer.from([])) | ||
}) | ||
|
||
it("should throw an error if buffer length is less than 4", () => { | ||
const buffer = Buffer.from([0x00, 0x00, 0x00]) | ||
expect(() => { | ||
readNextBuffer(buffer) | ||
}).toThrow() | ||
}) | ||
}) | ||
describe("readNextUint8", () => { | ||
it("should read the next Uint8 correctly", () => { | ||
const buffer = Buffer.from([0x01, 0x02, 0x03]) | ||
const [data, remaining] = readNextUint8(buffer) | ||
expect(data).toBe(0x01) | ||
expect(remaining).toStrictEqual(Buffer.from([0x02, 0x03])) | ||
}) | ||
it("should throw an error if buffer length is less than 1", () => { | ||
const buffer = Buffer.from([]) | ||
expect(() => { | ||
readNextUint8(buffer) | ||
}).toThrow() | ||
}) | ||
}) | ||
describe("readNextUint32", () => { | ||
it("should read the next Uint32 correctly", () => { | ||
const buffer = Buffer.from([0x00, 0x00, 0x00, 0x01, 0x02, 0x03]) | ||
const [data, remaining] = readNextUint32(buffer) | ||
expect(data).toBe(0x00000001) | ||
expect(remaining).toStrictEqual(Buffer.from([0x02, 0x03])) | ||
}) | ||
it("should throw an error if buffer length is less than 4", () => { | ||
const buffer = Buffer.from([0x00, 0x00, 0x00]) | ||
expect(() => { | ||
readNextUint32(buffer) | ||
}).toThrow() | ||
}) | ||
}) | ||
describe("readNextBinaryBoolean", () => { | ||
it("should read the next BinaryBoolean correctly", () => { | ||
const buffer = Buffer.from([0x01, 0x02]) | ||
const [data, remaining] = readNextBinaryBoolean(buffer) | ||
expect(data).toBe(true) | ||
expect(remaining).toStrictEqual(Buffer.from([0x02])) | ||
}) | ||
it("should throw an error if buffer length is less than 1", () => { | ||
const buffer = Buffer.from([]) | ||
expect(() => { | ||
readNextBinaryBoolean(buffer) | ||
}).toThrow() | ||
}) | ||
}) | ||
describe("serializeBuffer", () => { | ||
it("should serialize the buffer correctly", () => { | ||
const buffer = Buffer.from([0x61, 0x62, 0x63, 0x64]) | ||
const serialized = serializeBuffer(buffer) | ||
expect(serialized).toStrictEqual( | ||
Buffer.from([0x00, 0x00, 0x00, 0x04, 0x61, 0x62, 0x63, 0x64]), | ||
) | ||
}) | ||
}) | ||
describe("serializeUint8", () => { | ||
it("should serialize the Uint8 correctly", () => { | ||
const serialized = serializeUint8(0x01) | ||
expect(serialized).toStrictEqual(Buffer.from([0x01])) | ||
}) | ||
}) | ||
describe("serializeUint32", () => { | ||
it("should serialize the Uint32 correctly", () => { | ||
const serialized = serializeUint32(0x00000001) | ||
expect(serialized).toStrictEqual(Buffer.from([0x00, 0x00, 0x00, 0x01])) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { readNextNameList, serializeNameList } from "../../src/utils/NameList" | ||
|
||
describe("NameList Utils", () => { | ||
test("Should be parseable", () => { | ||
expect(readNextNameList(Buffer.from("00000005612c622c63deadbeef", "hex"))).toEqual([ | ||
["a", "b", "c"], | ||
Buffer.from("deadbeef", "hex"), | ||
]) | ||
}) | ||
|
||
test("Should serialize", () => { | ||
expect(serializeNameList(["a", "b", "c"]).toString("hex")).toEqual("00000005612c622c63") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
}, | ||
"type": "module", | ||
"dependencies": { | ||
"asn1js": "^3.0.5" | ||
"asn1js": "^3.0.5", | ||
"tweetnacl": "^1.0.3" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.