Skip to content

Commit a440134

Browse files
committed
basics
1 parent 01fe0d7 commit a440134

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+62260
-55299
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@typescript-eslint/no-unsafe-argument": "error",
5757
"@typescript-eslint/no-unsafe-assignment": "off",
5858
"@typescript-eslint/no-unsafe-member-access": "off",
59-
"@typescript-eslint/no-unsafe-return": "error",
59+
"@typescript-eslint/no-unsafe-return": "off",
6060
"@typescript-eslint/no-useless-empty-export": "error",
6161
"@typescript-eslint/prefer-function-type": "error",
6262
"no-array-constructor": "off",

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,5 @@ RUN tar -xvzf v0.46.tar.gz
169169
RUN apt-get -y install default-jdk-headless
170170
RUN apt-get -y install maven
171171
RUN cd ktfmt-0.46 && mvn -B install --file pom.xml && mv ./core/target/ktfmt-0.46-jar-with-dependencies.jar /usr/local/bin
172+
RUN git clone --depth 1 https://github.com/gitGNU/objconv.git
173+
RUN cd objconv/src && ./build.sh && mv objconv /usr/local/bin

code/cli/task.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import _ from 'lodash'
12
import { Input, Link, Value } from './type'
23

34
export const CONVERT_KEY: Record<string, Link> = {
4-
'-i': { name: 'inputPath' },
5-
'-o': { name: 'outputPath', need: false },
6-
'-I': { name: 'inputExtension', need: false },
7-
'-O': { name: 'outputExtension', need: false },
8-
'-x': { name: 'architecture', need: false },
9-
'--arch': { name: 'architecture', need: false },
10-
'-s': { name: 'syntax', need: false },
11-
'-f': { name: 'prettify', need: false },
12-
'-h': { name: 'help', need: false, like: 'boolean' },
5+
'-i': { name: ['input', 'file', 'path'] },
6+
'-o': { name: ['output', 'file', 'path'], need: false },
7+
'-I': { name: ['input', 'file', 'format'], need: false },
8+
'-O': { name: ['output', 'file', 'format'], need: false },
9+
'-x': { name: ['output', 'architecture'], need: false },
10+
'--arch': { name: ['output', 'architecture'], need: false },
11+
'-s': { name: ['output', 'syntax'], need: false },
12+
'-f': { name: ['output', 'prettify'], need: false },
13+
'-h': { name: ['help'], need: false, like: 'boolean' },
1314
}
1415

1516
export async function convert(source: Input) {
@@ -31,7 +32,6 @@ function makeInput(source: Input, map: Record<string, Link>) {
3132
const out: Record<string, Value | Array<Value>> = {}
3233
for (const name in source.detail) {
3334
const form = map[name]
34-
const mapName = form?.name ?? name
3535
const detail = source.detail[name].map(v => {
3636
switch (form?.like) {
3737
case 'string':
@@ -44,7 +44,11 @@ function makeInput(source: Input, map: Record<string, Link>) {
4444
return v
4545
})
4646
const val = form?.list ? detail : detail[0]
47-
out[mapName] = val
47+
if (form.name) {
48+
_.set(out, form.name, val)
49+
} else {
50+
out[name] = val
51+
}
4852
}
4953
return out
5054
}

code/cli/type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type Input = {
77
export type Value = string | boolean | number
88

99
export type Link = {
10-
name: string
10+
name: Array<string>
1111
list?: boolean
1212
need?: boolean
1313
like?: string

code/node/code.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ export async function generateAssemblyFromLlvmIr({
4545
}) {
4646
const architectureKey = LLVM_ARCHITECTURE_CONTENT[architecture].host
4747

48-
return await exec(
49-
`llc --x86-asm-syntax=${syntax} -march=${architectureKey} -o "${outputPath}" "${inputPath}"`,
50-
)
48+
return [
49+
`llc`,
50+
`--x86-asm-syntax=${syntax}`,
51+
`-march=${architectureKey}`,
52+
`-o`,
53+
`"${outputPath}"`,
54+
`"${inputPath}"`,
55+
]
5156
}
5257

5358
// cargo rustc --release -- --emit asm

code/node/crypto.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import murmurhash from 'murmurhash'
2+
import forge from 'node-forge'
3+
// https://github.com/vkandy/jenkins-hash-js/blob/master/src/jenkins.js
4+
// npm install blake3-wasm
5+
6+
// https://en.wikipedia.org/wiki/List_of_hash_functions
7+
// https://www.npmjs.com/package/node-hashes
8+
9+
export const cipher = {
10+
form: 'hash',
11+
hash: {
12+
aes_ecb: { head: 'AES-ECB' },
13+
aes_cbc: { head: 'AES-CBC' },
14+
aes_cfb: { head: 'AES-CFB' },
15+
aes_ofb: { head: 'AES-OFB' },
16+
aes_ctr: { head: 'AES-CTR' },
17+
aes_gcm: { head: 'AES-GCM' },
18+
'3_des_ecb': { head: '3DES-ECB' },
19+
'3_des_cbc': { head: '3DES-CBC' },
20+
des_ecb: { head: 'DES-ECB' },
21+
des_cbc: { head: 'DES-CBC' },
22+
},
23+
}
24+
25+
export const generate_murmur_hash = {
26+
form: 'form',
27+
link: {
28+
input: { like: 'string' },
29+
seed: { like: 'number' },
30+
version: { like: 'string', take: ['2', '3'], fall: '3' },
31+
},
32+
}
33+
34+
export function generateMurmurHash(source: GenerateMurmurHash) {
35+
const { input, seed, version } = GenerateMurmurHashModel.parse(source)
36+
if (version === '2') {
37+
return murmurhash.v2(input, seed)
38+
}
39+
return murmurhash.v3(input, seed)
40+
}
41+
42+
export const get_random_bytes = {
43+
form: 'form',
44+
link: {
45+
size: { like: 'natural_number' },
46+
},
47+
}
48+
49+
// var key = forge.random.getBytesSync(16)
50+
// var iv = forge.random.getBytesSync(16)
51+
export async function getRandomBytes(source: GetRandomBytes) {
52+
return new Promise((res, rej) => {
53+
return forge.random.getBytes(
54+
source.size,
55+
(err: Error | null, bytes) => {
56+
if (err) {
57+
return rej(err)
58+
}
59+
return res(bytes)
60+
},
61+
)
62+
})
63+
}
64+
65+
export const encrypt_bytes_with_aes = {
66+
form: 'form',
67+
link: {
68+
mode: { like: 'string' },
69+
},
70+
}
71+
72+
export async function encryptBytesWithAes(source: EncryptBytesWithAes) {
73+
const cipher = forge.cipher.createCipher(`AES-${mode}`, key)
74+
cipher.start({ iv: iv })
75+
cipher.update(forge.util.createBuffer(input))
76+
cipher.finish()
77+
return cipher.output.bytes()
78+
}
79+
80+
export async function decryptBytesWithAes() {
81+
const decipher = forge.cipher.createDecipher(`AES-${mode}`, key)
82+
decipher.start({ iv: iv })
83+
decipher.update(input) // input == encryptedBytes
84+
if (decipher.finish()) {
85+
return decipher.output.bytes()
86+
}
87+
}

code/node/document.ts

Lines changed: 10 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,14 @@ import libre from 'libreoffice-convert'
55
import fs from 'node:fs/promises'
66
import {
77
BuildCommandToConvertDocumentWithPandoc,
8+
BuildCommandToConvertDocumentWithPandocModel,
89
CallLink,
910
PANDOC_INPUT_FORMAT,
1011
PANDOC_OUTPUT_FORMAT,
11-
PandocInputFormat,
12-
PandocOutputFormat,
1312
} from '../shared'
1413
import path from 'path'
14+
import { replaceFileExtension } from '../shared/tool'
1515

16-
export async function buildCommandToConvertDocumentWithPandoc({
17-
inputPath,
18-
inputFormat,
19-
outputPath,
20-
outputFormat,
21-
outputExtension,
22-
}: {
23-
inputPath: string
24-
inputFormat: PandocInputFormat
25-
outputPath: string
26-
outputFormat: PandocOutputFormat
27-
}) {
28-
const { invariant } = await eval(`import('@epic-web/invariant')`)
29-
invariant(
30-
outputPath || outputExtension,
31-
`Output path or extension needed.`,
32-
)
33-
34-
let iFormat = inputFormat
35-
? inputFormat
36-
: path.extname(inputPath as string).replace(/^\./, '')
37-
38-
if (outputExtension) {
39-
outputPath = `${path.dirname(inputPath as string)}/${path.basename(
40-
inputPath as string,
41-
path.extname(inputPath as string),
42-
)}.${outputExtension}`
43-
}
44-
45-
let oFormat = outputFormat
46-
? outputFormat
47-
: path.extname(outputPath as string).replace(/^\./, '')
48-
49-
const cmd = [
50-
`pandoc`,
51-
`--sandbox`,
52-
`-f`,
53-
`${iFormat}`,
54-
`-t`,
55-
`${oFormat}`,
56-
`-o`,
57-
`${outputPath}`,
58-
`${inputPath}`,
59-
]
60-
return cmd
61-
}
6216
// https://help.libreoffice.org/latest/en-US/text/shared/guide/convertfilters.html
6317
export async function convertDocumentWithLibreOffice({
6418
inputData,
@@ -228,19 +182,13 @@ PANDOC_INPUT_FORMAT.forEach(a => {
228182
) => {
229183
const { invariant } = await eval(`import('@epic-web/invariant')`)
230184
invariant(
231-
source.inputPath
232-
? !!source.inputPath.match(new RegExp(`\\.${a}$`))
233-
: source.inputExtension
234-
? source.inputExtension === a
235-
: false,
185+
source.input.file.path.endsWith(`.${a}`),
236186
`Input path must have extension .${a}`,
237187
)
188+
238189
invariant(
239-
source.outputPath
240-
? !!source.outputPath.match(new RegExp(`\\.${b}$`))
241-
: source.outputExtension
242-
? source.outputExtension === b
243-
: false,
190+
source.output.file.path?.endsWith(`.${b}`) ||
191+
source.output.file.format === b,
244192
`Output path must have extension .${b}`,
245193
)
246194

@@ -260,19 +208,13 @@ CALL_DOCUMENT[String(`/tex/convert/pdf`)] = CALL_DOCUMENT[
260208
] = async (source: BuildCommandToConvertDocumentWithPandoc) => {
261209
const { invariant } = await eval(`import('@epic-web/invariant')`)
262210
invariant(
263-
source.inputPath
264-
? !!source.inputPath.match(new RegExp(`\\.tex$`))
265-
: source.inputExtension
266-
? source.inputExtension === 'tex'
267-
: false,
211+
source.input.file.path.endsWith(`.tex`),
268212
`Input path must have extension .tex`,
269213
)
214+
270215
invariant(
271-
source.outputPath
272-
? !!source.outputPath.match(new RegExp(`\\.pdf$`))
273-
: source.outputExtension
274-
? source.outputExtension === 'pdf'
275-
: false,
216+
source.output.file.path?.endsWith(`.pdf`) ||
217+
source.output.file.format === 'pdf',
276218
`Output path must have extension .pdf`,
277219
)
278220

0 commit comments

Comments
 (0)