feat: make lint happy
This commit is contained in:
@@ -58,7 +58,7 @@ class BinaryWriter {
|
||||
for (let i = 0; i < this.buffers.length; i++) {
|
||||
totalLen += this.buffers[i].byteLength;
|
||||
}
|
||||
let merged = new Uint8Array(totalLen);
|
||||
const merged = new Uint8Array(totalLen);
|
||||
let offset = 0;
|
||||
for (let i = 0; i < this.buffers.length; i++) {
|
||||
merged.set(this.buffers[i], offset);
|
||||
@@ -83,13 +83,13 @@ class BinaryWriter {
|
||||
}
|
||||
|
||||
writeUint32(num: number) {
|
||||
let dataView = new DataView(new ArrayBuffer(4), 0);
|
||||
const dataView = new DataView(new ArrayBuffer(4), 0);
|
||||
dataView.setUint32(0, num);
|
||||
this.writeBytes(new Uint8Array(dataView.buffer));
|
||||
}
|
||||
|
||||
writeNumber(num: number) {
|
||||
let n = new Uint8Array(1)
|
||||
const n = new Uint8Array(1)
|
||||
n[0] = num;
|
||||
this.writeBytes(n);
|
||||
}
|
||||
@@ -163,12 +163,12 @@ class SshSignature {
|
||||
}
|
||||
|
||||
static parse(buffer: Uint8Array): SshSignature {
|
||||
let reader = new BinaryReader(buffer);
|
||||
const reader = new BinaryReader(buffer);
|
||||
const sshSig = reader.readLengthToString(6);
|
||||
if (sshSig !== "SSHSIG") {
|
||||
throw `Bad SSH signature magic, expect: SSHSIG, actual: ${sshSig}`;
|
||||
}
|
||||
let sshVer = reader.readUint32();
|
||||
const sshVer = reader.readUint32();
|
||||
if (sshVer !== 1) {
|
||||
throw `Bad SSH signature version, expect: 1, actual: ${sshVer}`;
|
||||
}
|
||||
@@ -214,7 +214,7 @@ class SshSignature {
|
||||
if (this.getHashAlgorithmLength() !== digest.byteLength) {
|
||||
throw `Bad digest length, expect: ${this.getHashAlgorithmLength()}, acutal: ${digest.byteLength}`;
|
||||
}
|
||||
let writer = new BinaryWriter();
|
||||
const writer = new BinaryWriter();
|
||||
writer.writeLengthFromString("SSHSIG");
|
||||
writer.writeStringFromString(this.namespace);
|
||||
writer.writeStringFromString("");
|
||||
@@ -260,10 +260,10 @@ class SshSignatureValue {
|
||||
}
|
||||
|
||||
static parse(buffer: Uint8Array): SshSignatureValue {
|
||||
let reader = new BinaryReader(buffer);
|
||||
const reader = new BinaryReader(buffer);
|
||||
const signatureAlgorithm = reader.readStringToString();
|
||||
const signatureEc = reader.readString();
|
||||
let signatureEcReader = new BinaryReader(signatureEc);
|
||||
const signatureEcReader = new BinaryReader(signatureEc);
|
||||
const r = signatureEcReader.readString();
|
||||
const s = signatureEcReader.readString();
|
||||
return new SshSignatureValue(signatureAlgorithm, r, s);
|
||||
@@ -271,7 +271,7 @@ class SshSignatureValue {
|
||||
|
||||
// crypto.subtle.sign's signature is R and S
|
||||
toRs(): Uint8Array {
|
||||
let writer = new BinaryWriter();
|
||||
const writer = new BinaryWriter();
|
||||
if (this.ecSignatureR.byteLength === 0x21) {
|
||||
writer.writeBytes(this.ecSignatureR.slice(1));
|
||||
} else {
|
||||
@@ -290,7 +290,7 @@ class SshSignatureValue {
|
||||
// INTEGER: 69658b75c9c7523c15e6de16907350f0d0fd51114237c3e32bdd9fe92465e768
|
||||
// }
|
||||
toDer(): Uint8Array {
|
||||
let writer = new BinaryWriter();
|
||||
const writer = new BinaryWriter();
|
||||
writer.writeNumber(0x30);
|
||||
writer.writeNumber(0x45);
|
||||
|
||||
@@ -325,7 +325,7 @@ class SshPublicKey {
|
||||
}
|
||||
|
||||
static parse(buffer: Uint8Array): SshPublicKey {
|
||||
let reader = new BinaryReader(buffer);
|
||||
const reader = new BinaryReader(buffer);
|
||||
const signatureAlgorithm = reader.readStringToString();
|
||||
const curveAlgorithm = reader.readStringToString();
|
||||
const publicKeyPoint = reader.readString();
|
||||
@@ -336,7 +336,7 @@ class SshPublicKey {
|
||||
}
|
||||
|
||||
toDer(): Uint8Array {
|
||||
let writer = new BinaryWriter();
|
||||
const writer = new BinaryWriter();
|
||||
if (this.algorithm === "nistp256") {
|
||||
writer.writeBytes(decodeHex("3059301306072a8648ce3d020106082a8648ce3d030107034200"));
|
||||
} else {
|
||||
@@ -351,7 +351,7 @@ class SshPublicKey {
|
||||
}
|
||||
|
||||
async importJwk(): Promise<CryptoKey> {
|
||||
let jwk = this.toJwk();
|
||||
const jwk = this.toJwk();
|
||||
return await crypto.subtle.importKey(
|
||||
"jwk",
|
||||
jwk,
|
||||
@@ -392,7 +392,7 @@ class SshPublicKey {
|
||||
function parsePemToArray(pem: string): Uint8Array {
|
||||
const lines = pem.split("\n");
|
||||
let isInPem = false;
|
||||
let innerPem = [];
|
||||
const innerPem = [];
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
if (isInPem) {
|
||||
@@ -413,14 +413,14 @@ function parsePemToArray(pem: string): Uint8Array {
|
||||
}
|
||||
|
||||
async function digestString(data: string, algorithm: string): Promise<Uint8Array> {
|
||||
let hashAlgorithm = normalizeHashAlgorithm(algorithm);
|
||||
const hashAlgorithm = normalizeHashAlgorithm(algorithm);
|
||||
const messageBuffer = new TextEncoder().encode(data);
|
||||
const hashBuffer = await crypto.subtle.digest(hashAlgorithm, messageBuffer);
|
||||
return new Uint8Array(hashBuffer);
|
||||
}
|
||||
|
||||
async function digestFile(filename: string, algorithm: string): Promise<Uint8Array> {
|
||||
let hashAlgorithm = normalizeHashAlgorithm(algorithm);
|
||||
const hashAlgorithm = normalizeHashAlgorithm(algorithm);
|
||||
const file = await Deno.open(filename, {read: true});
|
||||
const readableStream = file.readable;
|
||||
const hashBuffer = await crypto.subtle.digest(hashAlgorithm, readableStream);
|
||||
|
||||
Reference in New Issue
Block a user