Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { loadI18nMessages } from "./store/i18n";
import { Encryption } from "./models/encryption";
import { EntryStorage } from "./models/storage";
import { getOTPAuthPerLineFromOPTAuthMigration } from "./models/migration";
import { OTPAlgorithm } from "./models/otp";
import * as CryptoJS from "crypto-js";

async function init() {
Expand Down Expand Up @@ -311,7 +312,12 @@ export async function getEntryDataFromOTPAuthPerLine(importCode: string) {
exportData[hash].digits = digits;
}
if (algorithm) {
exportData[hash].algorithm = algorithm;
const algorithmValue =
OTPAlgorithm[algorithm.toUpperCase() as keyof typeof OTPAlgorithm];
exportData[hash].algorithm =
typeof algorithmValue === "number"
? String(algorithmValue)
: algorithm;
}

succeededCount++;
Expand Down
19 changes: 19 additions & 0 deletions src/test/import.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import "mocha";
import { expect } from "chai";
import { getEntryDataFromOTPAuthPerLine } from "../import";
import { OTPAlgorithm } from "../models/otp";

mocha.setup("bdd");

describe("OTPAuth URI imports", () => {
for (const algorithm of ["SHA256", "SHA512"] as const) {
it(`preserves the ${algorithm} algorithm`, async () => {
const result = await getEntryDataFromOTPAuthPerLine(
`otpauth://totp/alice?secret=JBSWY3DPEHPK3PXP&algorithm=${algorithm}`
);
const entry = Object.values(result.exportData)[0];

expect(entry.algorithm).to.equal(String(OTPAlgorithm[algorithm]));
});
}
});