feat: make lint happy
This commit is contained in:
@@ -1,24 +1,24 @@
|
|||||||
export function compareVersion(ver1: string, ver2: string) {
|
export function compareVersion(ver1: string, ver2: string) {
|
||||||
if (ver1 === ver2) { return 0; }
|
if (ver1 === ver2) { return 0; }
|
||||||
let ver1Parts = ver1.split(".");
|
const ver1Parts = ver1.split(".");
|
||||||
let ver2Parts = ver2.split(".");
|
const ver2Parts = ver2.split(".");
|
||||||
let ver1Main = parseInt(ver1Parts[0]);
|
const ver1Main = parseInt(ver1Parts[0]);
|
||||||
let ver2Main = parseInt(ver2Parts[0]);
|
const ver2Main = parseInt(ver2Parts[0]);
|
||||||
if (ver1Main > ver2Main) { return 1; }
|
if (ver1Main > ver2Main) { return 1; }
|
||||||
if (ver1Main < ver2Main) { return -1; }
|
if (ver1Main < ver2Main) { return -1; }
|
||||||
let ver1Second = parseInt(ver1Parts[1]);
|
const ver1Second = parseInt(ver1Parts[1]);
|
||||||
let ver2Second = parseInt(ver2Parts[1]);
|
const ver2Second = parseInt(ver2Parts[1]);
|
||||||
if (ver1Second > ver2Second) { return 1; }
|
if (ver1Second > ver2Second) { return 1; }
|
||||||
if (ver1Second < ver2Second) { return -1; }
|
if (ver1Second < ver2Second) { return -1; }
|
||||||
let ver1Third = parseInt(ver1Parts[2]);
|
const ver1Third = parseInt(ver1Parts[2]);
|
||||||
let ver2Third = parseInt(ver2Parts[2]);
|
const ver2Third = parseInt(ver2Parts[2]);
|
||||||
if (ver1Third > ver2Third) { return 1; }
|
if (ver1Third > ver2Third) { return 1; }
|
||||||
if (ver1Third < ver2Third) { return -1; }
|
if (ver1Third < ver2Third) { return -1; }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isOn(val: string) {
|
export function isOn(val: string) {
|
||||||
let lowerVal = (val == null)? val: val.toLowerCase();
|
const lowerVal = (val == null)? val: val.toLowerCase();
|
||||||
return lowerVal === "on" || lowerVal === "yes" || lowerVal === "1" || lowerVal === "true";
|
return lowerVal === "on" || lowerVal === "yes" || lowerVal === "1" || lowerVal === "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { hmac } from "https://deno.land/x/hmac@v2.0.1/mod.ts";
|
import { hmac } from "https://deno.land/x/hmac@v2.0.1/mod.ts";
|
||||||
|
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
async function postHttpJson(url: string, body: any) {
|
async function postHttpJson(url: string, body: any) {
|
||||||
const resp = await fetch(url, {
|
const resp = await fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -59,13 +60,14 @@ export async function sendDingTalkMarkdownMessage(message: DingTalkMarkdownMessa
|
|||||||
}, options);
|
}, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
export async function sendDingTalkMessage(message: any, options: SendDingTalkMessageOptions) {
|
export async function sendDingTalkMessage(message: any, options: SendDingTalkMessageOptions) {
|
||||||
let send_url = options.base_url || BASE_DING_TALK_URL;
|
let send_url = options.base_url || BASE_DING_TALK_URL;
|
||||||
send_url += "?access_token=" + encodeURIComponent(options.access_token);
|
send_url += "?access_token=" + encodeURIComponent(options.access_token);
|
||||||
if (options.sec_token) {
|
if (options.sec_token) {
|
||||||
const timestamp = new Date().getTime();
|
const timestamp = new Date().getTime();
|
||||||
const timestamp_and_secret = `${timestamp}\n${options.sec_token}`;
|
const timestamp_and_secret = `${timestamp}\n${options.sec_token}`;
|
||||||
const sec_token_sign = hmac("sha256", options.sec_token, timestamp_and_secret, "utf8", "base64");
|
const sec_token_sign = hmac("sha256", options.sec_token, timestamp_and_secret, "utf8", "base64") as string;
|
||||||
send_url += "×tamp=" + timestamp;
|
send_url += "×tamp=" + timestamp;
|
||||||
send_url += "&sign=" + encodeURIComponent(sec_token_sign);
|
send_url += "&sign=" + encodeURIComponent(sec_token_sign);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class BinaryWriter {
|
|||||||
for (let i = 0; i < this.buffers.length; i++) {
|
for (let i = 0; i < this.buffers.length; i++) {
|
||||||
totalLen += this.buffers[i].byteLength;
|
totalLen += this.buffers[i].byteLength;
|
||||||
}
|
}
|
||||||
let merged = new Uint8Array(totalLen);
|
const merged = new Uint8Array(totalLen);
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
for (let i = 0; i < this.buffers.length; i++) {
|
for (let i = 0; i < this.buffers.length; i++) {
|
||||||
merged.set(this.buffers[i], offset);
|
merged.set(this.buffers[i], offset);
|
||||||
@@ -83,13 +83,13 @@ class BinaryWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
writeUint32(num: number) {
|
writeUint32(num: number) {
|
||||||
let dataView = new DataView(new ArrayBuffer(4), 0);
|
const dataView = new DataView(new ArrayBuffer(4), 0);
|
||||||
dataView.setUint32(0, num);
|
dataView.setUint32(0, num);
|
||||||
this.writeBytes(new Uint8Array(dataView.buffer));
|
this.writeBytes(new Uint8Array(dataView.buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
writeNumber(num: number) {
|
writeNumber(num: number) {
|
||||||
let n = new Uint8Array(1)
|
const n = new Uint8Array(1)
|
||||||
n[0] = num;
|
n[0] = num;
|
||||||
this.writeBytes(n);
|
this.writeBytes(n);
|
||||||
}
|
}
|
||||||
@@ -163,12 +163,12 @@ class SshSignature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static parse(buffer: Uint8Array): SshSignature {
|
static parse(buffer: Uint8Array): SshSignature {
|
||||||
let reader = new BinaryReader(buffer);
|
const reader = new BinaryReader(buffer);
|
||||||
const sshSig = reader.readLengthToString(6);
|
const sshSig = reader.readLengthToString(6);
|
||||||
if (sshSig !== "SSHSIG") {
|
if (sshSig !== "SSHSIG") {
|
||||||
throw `Bad SSH signature magic, expect: SSHSIG, actual: ${sshSig}`;
|
throw `Bad SSH signature magic, expect: SSHSIG, actual: ${sshSig}`;
|
||||||
}
|
}
|
||||||
let sshVer = reader.readUint32();
|
const sshVer = reader.readUint32();
|
||||||
if (sshVer !== 1) {
|
if (sshVer !== 1) {
|
||||||
throw `Bad SSH signature version, expect: 1, actual: ${sshVer}`;
|
throw `Bad SSH signature version, expect: 1, actual: ${sshVer}`;
|
||||||
}
|
}
|
||||||
@@ -214,7 +214,7 @@ class SshSignature {
|
|||||||
if (this.getHashAlgorithmLength() !== digest.byteLength) {
|
if (this.getHashAlgorithmLength() !== digest.byteLength) {
|
||||||
throw `Bad digest length, expect: ${this.getHashAlgorithmLength()}, acutal: ${digest.byteLength}`;
|
throw `Bad digest length, expect: ${this.getHashAlgorithmLength()}, acutal: ${digest.byteLength}`;
|
||||||
}
|
}
|
||||||
let writer = new BinaryWriter();
|
const writer = new BinaryWriter();
|
||||||
writer.writeLengthFromString("SSHSIG");
|
writer.writeLengthFromString("SSHSIG");
|
||||||
writer.writeStringFromString(this.namespace);
|
writer.writeStringFromString(this.namespace);
|
||||||
writer.writeStringFromString("");
|
writer.writeStringFromString("");
|
||||||
@@ -260,10 +260,10 @@ class SshSignatureValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static parse(buffer: Uint8Array): SshSignatureValue {
|
static parse(buffer: Uint8Array): SshSignatureValue {
|
||||||
let reader = new BinaryReader(buffer);
|
const reader = new BinaryReader(buffer);
|
||||||
const signatureAlgorithm = reader.readStringToString();
|
const signatureAlgorithm = reader.readStringToString();
|
||||||
const signatureEc = reader.readString();
|
const signatureEc = reader.readString();
|
||||||
let signatureEcReader = new BinaryReader(signatureEc);
|
const signatureEcReader = new BinaryReader(signatureEc);
|
||||||
const r = signatureEcReader.readString();
|
const r = signatureEcReader.readString();
|
||||||
const s = signatureEcReader.readString();
|
const s = signatureEcReader.readString();
|
||||||
return new SshSignatureValue(signatureAlgorithm, r, s);
|
return new SshSignatureValue(signatureAlgorithm, r, s);
|
||||||
@@ -271,7 +271,7 @@ class SshSignatureValue {
|
|||||||
|
|
||||||
// crypto.subtle.sign's signature is R and S
|
// crypto.subtle.sign's signature is R and S
|
||||||
toRs(): Uint8Array {
|
toRs(): Uint8Array {
|
||||||
let writer = new BinaryWriter();
|
const writer = new BinaryWriter();
|
||||||
if (this.ecSignatureR.byteLength === 0x21) {
|
if (this.ecSignatureR.byteLength === 0x21) {
|
||||||
writer.writeBytes(this.ecSignatureR.slice(1));
|
writer.writeBytes(this.ecSignatureR.slice(1));
|
||||||
} else {
|
} else {
|
||||||
@@ -290,7 +290,7 @@ class SshSignatureValue {
|
|||||||
// INTEGER: 69658b75c9c7523c15e6de16907350f0d0fd51114237c3e32bdd9fe92465e768
|
// INTEGER: 69658b75c9c7523c15e6de16907350f0d0fd51114237c3e32bdd9fe92465e768
|
||||||
// }
|
// }
|
||||||
toDer(): Uint8Array {
|
toDer(): Uint8Array {
|
||||||
let writer = new BinaryWriter();
|
const writer = new BinaryWriter();
|
||||||
writer.writeNumber(0x30);
|
writer.writeNumber(0x30);
|
||||||
writer.writeNumber(0x45);
|
writer.writeNumber(0x45);
|
||||||
|
|
||||||
@@ -325,7 +325,7 @@ class SshPublicKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static parse(buffer: Uint8Array): SshPublicKey {
|
static parse(buffer: Uint8Array): SshPublicKey {
|
||||||
let reader = new BinaryReader(buffer);
|
const reader = new BinaryReader(buffer);
|
||||||
const signatureAlgorithm = reader.readStringToString();
|
const signatureAlgorithm = reader.readStringToString();
|
||||||
const curveAlgorithm = reader.readStringToString();
|
const curveAlgorithm = reader.readStringToString();
|
||||||
const publicKeyPoint = reader.readString();
|
const publicKeyPoint = reader.readString();
|
||||||
@@ -336,7 +336,7 @@ class SshPublicKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toDer(): Uint8Array {
|
toDer(): Uint8Array {
|
||||||
let writer = new BinaryWriter();
|
const writer = new BinaryWriter();
|
||||||
if (this.algorithm === "nistp256") {
|
if (this.algorithm === "nistp256") {
|
||||||
writer.writeBytes(decodeHex("3059301306072a8648ce3d020106082a8648ce3d030107034200"));
|
writer.writeBytes(decodeHex("3059301306072a8648ce3d020106082a8648ce3d030107034200"));
|
||||||
} else {
|
} else {
|
||||||
@@ -351,7 +351,7 @@ class SshPublicKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async importJwk(): Promise<CryptoKey> {
|
async importJwk(): Promise<CryptoKey> {
|
||||||
let jwk = this.toJwk();
|
const jwk = this.toJwk();
|
||||||
return await crypto.subtle.importKey(
|
return await crypto.subtle.importKey(
|
||||||
"jwk",
|
"jwk",
|
||||||
jwk,
|
jwk,
|
||||||
@@ -392,7 +392,7 @@ class SshPublicKey {
|
|||||||
function parsePemToArray(pem: string): Uint8Array {
|
function parsePemToArray(pem: string): Uint8Array {
|
||||||
const lines = pem.split("\n");
|
const lines = pem.split("\n");
|
||||||
let isInPem = false;
|
let isInPem = false;
|
||||||
let innerPem = [];
|
const innerPem = [];
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
const line = lines[i];
|
const line = lines[i];
|
||||||
if (isInPem) {
|
if (isInPem) {
|
||||||
@@ -413,14 +413,14 @@ function parsePemToArray(pem: string): Uint8Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function digestString(data: string, algorithm: string): Promise<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 messageBuffer = new TextEncoder().encode(data);
|
||||||
const hashBuffer = await crypto.subtle.digest(hashAlgorithm, messageBuffer);
|
const hashBuffer = await crypto.subtle.digest(hashAlgorithm, messageBuffer);
|
||||||
return new Uint8Array(hashBuffer);
|
return new Uint8Array(hashBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function digestFile(filename: string, algorithm: string): Promise<Uint8Array> {
|
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 file = await Deno.open(filename, {read: true});
|
||||||
const readableStream = file.readable;
|
const readableStream = file.readable;
|
||||||
const hashBuffer = await crypto.subtle.digest(hashAlgorithm, readableStream);
|
const hashBuffer = await crypto.subtle.digest(hashAlgorithm, readableStream);
|
||||||
|
|||||||
Reference in New Issue
Block a user