Skip to content

Commit

Permalink
Fixing deno fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Dec 5, 2020
1 parent 0bda12f commit 2dd64c5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/rsa/basic_encoding_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ type BasicEncodingSimpleValue =
export function ber_decode(
bytes: Uint8Array,
from?: number,
to?: number
to?: number,
): BasicEncodingRule {
return ber_next(bytes);
}

function ber_sequence(
bytes: Uint8Array,
from: number,
length: number
length: number,
): BasicEncodingRule[] {
const end = from + length;
let res: BasicEncodingRule[] = [];
Expand Down Expand Up @@ -73,7 +73,7 @@ function ber_oid(bytes: Uint8Array, from: number, length: number): string {
function ber_unknown(
bytes: Uint8Array,
from: number,
length: number
length: number,
): Uint8Array {
return bytes.slice(from, from + length);
}
Expand All @@ -86,7 +86,7 @@ export function ber_simple(n: BasicEncodingRule): BasicEncodingSimpleValue {
function ber_next(
bytes: Uint8Array,
from?: number,
to?: number
to?: number,
): BasicEncodingRule {
if (!from) from = 0;
if (!to) to = bytes.length;
Expand Down
12 changes: 6 additions & 6 deletions src/rsa/import_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { os2ip } from "./primitives.ts";
type RSAImportKeyFormat = "auto" | "jwk" | "pem";
type RSAPublicKeyFormat = [[string, null], [[bigint, bigint]]];
type RSACertKeyFormat = [
[number, string, null, null, null, RSAPublicKeyFormat]
[number, string, null, null, null, RSAPublicKeyFormat],
];

/**
Expand Down Expand Up @@ -59,7 +59,7 @@ function rsa_import_jwk(key: JSONWebKey): RSAKeyParams {
function rsa_import_pem_cert(key: string): RSAKeyParams {
const trimmedKey = key.substr(27, key.length - 53);
const parseKey = ber_simple(
ber_decode(base64_to_binary(trimmedKey))
ber_decode(base64_to_binary(trimmedKey)),
) as RSACertKeyFormat;

return {
Expand All @@ -78,7 +78,7 @@ function rsa_import_pem_cert(key: string): RSAKeyParams {
function rsa_import_pem_private(key: string): RSAKeyParams {
const trimmedKey = key.substr(31, key.length - 61);
const parseKey = ber_simple(
ber_decode(base64_to_binary(trimmedKey))
ber_decode(base64_to_binary(trimmedKey)),
) as bigint[];

return {
Expand All @@ -105,7 +105,7 @@ function rsa_import_pem_private_pkcs8(key: string): RSAKeyParams {
const parseKey = ber_simple(ber_decode(base64_to_binary(trimmedKey))) as [
number,
unknown,
[bigint[]]
[bigint[]],
];

return {
Expand All @@ -130,7 +130,7 @@ function rsa_import_pem_private_pkcs8(key: string): RSAKeyParams {
function rsa_import_pem_public(key: string): RSAKeyParams {
const trimmedKey = key.substr(26, key.length - 51);
const parseKey = ber_simple(
ber_decode(base64_to_binary(trimmedKey))
ber_decode(base64_to_binary(trimmedKey)),
) as RSAPublicKeyFormat;

return {
Expand Down Expand Up @@ -171,7 +171,7 @@ function rsa_import_pem(key: string): RSAKeyParams {
*/
export function rsa_import_key(
key: string | JSONWebKey,
format: RSAImportKeyFormat
format: RSAImportKeyFormat,
): RSAKeyParams {
const finalFormat = format === "auto" ? detect_format(key) : format;

Expand Down
11 changes: 5 additions & 6 deletions tests/rsa/rsa.import_key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ Deno.test("RSA - Import JWK Public Key", () => {
e: "AQAB",
alg: "RS256",
use: "sig",
n:
"7NfiTQcshWgrEdKbHC2e1s92kK-YX7jS3JLFIBpT8f_j_b5y3dQdtFFS4vBoVNQkwep_34x_ihYlhA3QkwaTL2XMSiedjLnubFZBUjs7G0dgGIR3F8A06Bf5KT4g2x1dKVb0Lwwqg22XIfqaS88HdU5pDwcVmq4pVMaJQgUK-xFEC_sHdfqTV8Z0uBCr9Nik_7xz68FINDYyLhehnvwph9ui-8_WeDgU_h5xrG8H7oY28y2NCtBwXxIadB-K8pHxK2srM8wTCIivdyZS80P0jZMqyxPkt4fO33-GQWvelVmR0bS4Arb3Y4bXnoAMCEao3DTm0bgeNVz39274ippJSQ",
n: "7NfiTQcshWgrEdKbHC2e1s92kK-YX7jS3JLFIBpT8f_j_b5y3dQdtFFS4vBoVNQkwep_34x_ihYlhA3QkwaTL2XMSiedjLnubFZBUjs7G0dgGIR3F8A06Bf5KT4g2x1dKVb0Lwwqg22XIfqaS88HdU5pDwcVmq4pVMaJQgUK-xFEC_sHdfqTV8Z0uBCr9Nik_7xz68FINDYyLhehnvwph9ui-8_WeDgU_h5xrG8H7oY28y2NCtBwXxIadB-K8pHxK2srM8wTCIivdyZS80P0jZMqyxPkt4fO33-GQWvelVmR0bS4Arb3Y4bXnoAMCEao3DTm0bgeNVz39274ippJSQ",
kty: "RSA",
kid: "0a7dc12664590c957ffaebf7b6718297b864ba91",
};

const key = RSA.importKey(jwk);
assertEquals(
key.n,
29898696334083768896266718702903171091859023056380305309417814312144807651236219776572988301924887627930068177446780412276940629516142064593112933354190594654697661829130606057587381851965706738909234655495626384372595795359236395774819608658749454999590004164863045288407450035910884781406353708688482649485901718330442366762092993760752462641504190676097552830866364434725980527790004239511223633036676476183317655075621501198026388523929916443949606011158134681907852424177605535928134115519418874993982126227290991413378693772648195647359413482755806577610702326142298069698977819919395238440777867763969032866121n
29898696334083768896266718702903171091859023056380305309417814312144807651236219776572988301924887627930068177446780412276940629516142064593112933354190594654697661829130606057587381851965706738909234655495626384372595795359236395774819608658749454999590004164863045288407450035910884781406353708688482649485901718330442366762092993760752462641504190676097552830866364434725980527790004239511223633036676476183317655075621501198026388523929916443949606011158134681907852424177605535928134115519418874993982126227290991413378693772648195647359413482755806577610702326142298069698977819919395238440777867763969032866121n,
);
assertEquals(key.e, 65537n);
assertEquals(key.length, 256);
Expand Down Expand Up @@ -45,7 +44,7 @@ Deno.test("RSA - Import Certificate PEM", () => {
assertEquals(key.e, 65537n);
assertEquals(
key.n,
23090961311737573793101890708283924695433283000385054150823173852612673758230706931831331316346585281948637691806795052569468114184708524749728610979168598273283877538163829031755269185449374762314082288398270538054993384545276491531066649969558630423935152857250299602221281913410774031127740158653973996811337367884788028635132184093457045502358896056164012639638637637694971273993250785116955454220202034598919946428438516582026303702956399809398972276905876470428715345135826409789537975085486698172979761097583691702126455811212002371429452274581681294432992139097164326433615550289131259416635196384643694156981n
23090961311737573793101890708283924695433283000385054150823173852612673758230706931831331316346585281948637691806795052569468114184708524749728610979168598273283877538163829031755269185449374762314082288398270538054993384545276491531066649969558630423935152857250299602221281913410774031127740158653973996811337367884788028635132184093457045502358896056164012639638637637694971273993250785116955454220202034598919946428438516582026303702956399809398972276905876470428715345135826409789537975085486698172979761097583691702126455811212002371429452274581681294432992139097164326433615550289131259416635196384643694156981n,
);
assertEquals(key.length, 256);
});
Expand Down Expand Up @@ -84,11 +83,11 @@ Deno.test("RSA - Import Private Key (PKCS8)", () => {
assertEquals(key.e, 65537n);
assertEquals(
key.n,
18860626341786571281488823024986320858450594409825894653370543036132043241142573896042059032222842653925236802058387508300831766517210547599910735316414515960981281788934868325895562621846910598716519620622800765932541992515497122274302135166053720433521886017494719475895327062855822141735315456613329660043977602681873027347568355824008701177948209784908095092287571982104446342906805480285143028837509076748632094733769028381835899214426100089454654381383340292544225149266603150745375542089871264998183586873913491071542891188124185517417658034185267204900711933432911892469528812455677450346478816563776340692357n
18860626341786571281488823024986320858450594409825894653370543036132043241142573896042059032222842653925236802058387508300831766517210547599910735316414515960981281788934868325895562621846910598716519620622800765932541992515497122274302135166053720433521886017494719475895327062855822141735315456613329660043977602681873027347568355824008701177948209784908095092287571982104446342906805480285143028837509076748632094733769028381835899214426100089454654381383340292544225149266603150745375542089871264998183586873913491071542891188124185517417658034185267204900711933432911892469528812455677450346478816563776340692357n,
);
assertEquals(
key.d,
675889233296421535959584534071325460876697008626327098961835826056666939623318583538247287416696388446697983317835135300723690022117970081796395234018582764098060974026823771341271141202058228435371968592820841644512299636165137501280011132877728106486853881053264668544941537620562475421678333757690909726581512579603702598150422421865490996288244127528474781858718770957987603681469839575489191876915053252047160475432784849252000744700939988583801783684487872676506769116621572018367654125765915215495461243190782913460732307866572233187464540482209385816659449697777403383908159076257721991916366849321145825505n
675889233296421535959584534071325460876697008626327098961835826056666939623318583538247287416696388446697983317835135300723690022117970081796395234018582764098060974026823771341271141202058228435371968592820841644512299636165137501280011132877728106486853881053264668544941537620562475421678333757690909726581512579603702598150422421865490996288244127528474781858718770957987603681469839575489191876915053252047160475432784849252000744700939988583801783684487872676506769116621572018367654125765915215495461243190782913460732307866572233187464540482209385816659449697777403383908159076257721991916366849321145825505n,
);
assertEquals(key.length, 256);
});

0 comments on commit 2dd64c5

Please sign in to comment.