forked from aws/aws-encryption-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.ts
116 lines (112 loc) · 3.02 KB
/
cli.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import yargs from 'yargs'
import { needs } from '@aws-crypto/client-node'
import { cpus } from 'os'
import {
integrationDecryptTestVectors,
integrationEncryptTestVectors,
} from './integration_tests'
const cli = yargs
.command('decrypt', 'verify decrypt vectors', (y) =>
y.option('vectorFile', {
alias: 'v',
describe: 'a vector zip file from aws-encryption-sdk-test-vectors',
demandOption: true,
type: 'string',
})
)
.command('encrypt', 'verify encrypt manifest', (y) =>
y
.option('manifestFile', {
alias: 'm',
describe:
'a path/url to aws-crypto-tools-test-vector-framework canonical manifest',
demandOption: true,
type: 'string',
})
.option('keyFile', {
alias: 'k',
describe:
'a path/url to aws-crypto-tools-test-vector-framework canonical key list',
demandOption: true,
type: 'string',
})
.option('decryptOracle', {
alias: 'o',
describe: 'a url to the decrypt oracle',
demandOption: true,
type: 'string',
})
)
.option('tolerateFailures', {
alias: 'f',
describe: 'an optional number of failures to tolerate before exiting',
type: 'number',
default: 0,
})
.option('testName', {
alias: 't',
describe: 'an optional test name to execute',
type: 'string',
})
.option('concurrency', {
alias: 'c',
describe: `an optional concurrency for running tests, pass 'cpu' to maximize`,
default: 1,
coerce: (value: any) => {
if (typeof value === 'string') {
needs(
value.toLowerCase() === 'cpu',
`The only supported string is 'cpu'`
)
return cpus().length - 1
}
needs(
typeof value === 'number' && value > 0,
`Must be a number greater than 0`
)
return value
},
})
.demandCommand()
;(async (argv) => {
// prettier-ignore
const {
// @ts-ignore // ignoring TS2339
_: [command], tolerateFailures, testName, concurrency,
} = argv
/* I set the result to 1 so that if I fall through the exit condition is a failure */
let result = 1
if (command === 'decrypt') {
const { vectorFile } = argv as unknown as { vectorFile: string }
result = await integrationDecryptTestVectors(
vectorFile,
tolerateFailures,
testName,
concurrency
)
} else if (command === 'encrypt') {
const { manifestFile, keyFile, decryptOracle } = argv as unknown as {
manifestFile: string
keyFile: string
decryptOracle: string
}
result = await integrationEncryptTestVectors(
manifestFile,
keyFile,
decryptOracle,
tolerateFailures,
testName,
concurrency
)
} else {
console.log(`Unknown command ${command}`)
cli.showHelp()
}
if (result) process.exit(result)
})(cli.argv).catch((err) => {
console.log(err)
process.exit(1)
})