forked from utily/cryptly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgorithms.spec.ts
More file actions
38 lines (36 loc) · 1.18 KB
/
Algorithms.spec.ts
File metadata and controls
38 lines (36 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import * as cryptly from "./index"
describe("Context.PrimarySecrets", () => {
it("create", async () => {
const generated = {
"2020a": cryptly.Algorithm.aesGcm(256),
"2020b": cryptly.Algorithm.aesGcm(256),
"2021a": cryptly.Algorithm.aesGcm(256),
} as const
const expected = await exportAll(generated)
const algorithm = {
"2020a": await generated["2020a"].export(3),
"2020b": [await generated["2020b"].export()],
"2021a": await generated["2021a"].export(2),
} as const
const secrets = cryptly.Algorithms.create(
cryptly.Algorithm.aesGcm,
"2020a",
`2020a: ${algorithm["2020a"][0]}, 2020b: ${algorithm["2020b"][0]}, 2021a: ${algorithm["2021a"][0]}`,
`2020a: ${algorithm["2020a"][1]}, 2021a: ${algorithm["2021a"][1]}`,
`2020a: ${algorithm["2020a"][2]}`
)
expect(Object.keys(secrets)).toEqual(["current", "2020a", "2020b", "2021a"])
expect(await exportAll(secrets)).toEqual({ current: expected["2020a"], ...expected })
})
})
async function exportAll<T>(
secrets: T
): Promise<
{
[P in keyof T]: string
}
> {
return Object.fromEntries(
await Promise.all(Object.entries(secrets).map(async ([name, algorithm]) => [name, await algorithm.export()]))
)
}