feat: update deno-sshsig-mod.ts

This commit is contained in:
2025-01-19 15:10:32 +08:00
parent c2e741ef16
commit eb6357f6bb
2 changed files with 13 additions and 6 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
*.sshsig
.idea/
# ---> macOS
# General

View File

@@ -1,7 +1,7 @@
import { crypto } from "jsr:@std/crypto";
import { decodeBase64, encodeBase64 } from "jsr:@std/encoding/base64";
import { encodeBase64Url } from "jsr:@std/encoding/base64url";
import { decodeHex, encodeHex } from "jsr:@std/encoding/hex";
import {crypto} from "jsr:@std/crypto";
import {decodeBase64, encodeBase64} from "jsr:@std/encoding/base64";
import {encodeBase64Url} from "jsr:@std/encoding/base64url";
import {decodeHex, encodeHex} from "jsr:@std/encoding/hex";
// IMPORTANT: ONLY supports ECDSA P256 and P384
@@ -285,12 +285,18 @@ export class SshSignatureValue {
// crypto.subtle.sign's signature is R and S
toRs(): Uint8Array {
const writer = new BinaryWriter();
if (this.ecSignatureR.byteLength === 0x21) {
if (
this.ecSignatureR.byteLength === 0x21 ||
this.ecSignatureR.byteLength === 0x31
) {
writer.writeBytes(this.ecSignatureR.slice(1));
} else {
writer.writeBytes(this.ecSignatureR);
}
if (this.ecSignatureS.byteLength === 0x21) {
if (
this.ecSignatureS.byteLength === 0x21 ||
this.ecSignatureS.byteLength === 0x31
) {
writer.writeBytes(this.ecSignatureS.slice(1));
} else {
writer.writeBytes(this.ecSignatureS);