@syzlm/ofdparser 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +14 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +18 -0
- package/.prettierrc.json +9 -0
- package/dist/OFD.d.ts +8 -0
- package/dist/Pages.d.ts +7 -0
- package/dist/RootDocumnet.d.ts +1 -0
- package/dist/bundle.cjs.js +64123 -0
- package/dist/bundle.esm.js +64115 -0
- package/dist/bundle.iife.js +14743 -0
- package/dist/bundle.umd.js +64045 -0
- package/dist/constant/index.d.ts +7 -0
- package/dist/constant.d.ts +6 -0
- package/dist/core/ofd-core/Annotations/AnnotationsXml.d.ts +16 -0
- package/dist/core/ofd-core/Asn.1Utils.d.ts +47 -0
- package/dist/core/ofd-core/Documents/DocumentResXml.d.ts +15 -0
- package/dist/core/ofd-core/Documents/DocumnetXml.d.ts +25 -0
- package/dist/core/ofd-core/Documents/PublicResXml.d.ts +15 -0
- package/dist/core/ofd-core/OFDElement.d.ts +232 -0
- package/dist/core/ofd-core/Ofd/OFDXml.d.ts +19 -0
- package/dist/core/ofd-core/Pages/PageXml.d.ts +20 -0
- package/dist/core/ofd-core/Signatures/Signatures.d.ts +20 -0
- package/dist/core/ofd-core/TemplatePages/TemplatePages.d.ts +20 -0
- package/dist/core/ofd-core/constant.d.ts +29 -0
- package/dist/core/ofd-core/utils.d.ts +21 -0
- package/dist/dicom/dicom.d.ts +15 -0
- package/dist/dicom/index.d.ts +1 -0
- package/dist/errors/ErrorHandle.d.ts +6 -0
- package/dist/errors/ErrorMsg.d.ts +16 -0
- package/dist/errors/FetchErrors.d.ts +4 -0
- package/dist/errors/MimeError.d.ts +4 -0
- package/dist/errors/OFDErrors.d.ts +4 -0
- package/dist/errors/UnzipErrors.d.ts +4 -0
- package/dist/errors/XmlErrors.d.ts +4 -0
- package/dist/errors/error-msg.d.ts +9 -0
- package/dist/es.d.ts +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/lib/ParseFile.d.ts +7 -0
- package/dist/lib/UnitCoversion.d.ts +31 -0
- package/dist/lib/asn1/Asn.1.d.ts +34 -0
- package/dist/lib/asn1/Stream.d.ts +27 -0
- package/dist/lib/asn1/asn1.d.ts +4 -0
- package/dist/lib/asn1/base64.d.ts +4 -0
- package/dist/lib/asn1/hex.d.ts +5 -0
- package/dist/lib/asn1/index.d.ts +5 -0
- package/dist/lib/asn1/int10.d.ts +34 -0
- package/dist/lib/asn1/oids.d.ts +2 -0
- package/dist/lib/asn1/string-cut.d.ts +2 -0
- package/dist/lib/decode-html.d.ts +7 -0
- package/dist/lib/fetch.d.ts +17 -0
- package/dist/lib/is-element.d.ts +5 -0
- package/dist/lib/load-files.d.ts +3 -0
- package/dist/lib/load-opentype.d.ts +34 -0
- package/dist/lib/load-script.d.ts +1 -0
- package/dist/lib/mime.d.ts +8 -0
- package/dist/lib/read-buffer.d.ts +2 -0
- package/dist/lib/toFixeds.d.ts +7 -0
- package/dist/libs/Asn.1Utils.d.ts +47 -0
- package/dist/libs/asn1/Asn.1.d.ts +34 -0
- package/dist/libs/asn1/Stream.d.ts +27 -0
- package/dist/libs/asn1/asn1.d.ts +4 -0
- package/dist/libs/asn1/base64.d.ts +4 -0
- package/dist/libs/asn1/hex.d.ts +5 -0
- package/dist/libs/asn1/index.d.ts +5 -0
- package/dist/libs/asn1/int10.d.ts +34 -0
- package/dist/libs/asn1/oids.d.ts +2 -0
- package/dist/libs/asn1/string-cut.d.ts +2 -0
- package/dist/libs/decode-html.d.ts +7 -0
- package/dist/libs/fetch.d.ts +17 -0
- package/dist/libs/mime.d.ts +8 -0
- package/dist/libs/ofdArray.d.ts +10 -0
- package/dist/libs/ofdImageObject.d.ts +9 -0
- package/dist/libs/ofdLayer.d.ts +3 -0
- package/dist/libs/ofdName.d.ts +17 -0
- package/dist/libs/ofdPathObject.d.ts +11 -0
- package/dist/libs/ofdTextObject.d.ts +6 -0
- package/dist/libs/parseAnnotation.d.ts +5 -0
- package/dist/libs/parseColor.d.ts +5 -0
- package/dist/libs/parsePageArea.d.ts +17 -0
- package/dist/libs/parser-elements.d.ts +8 -0
- package/dist/libs/parserElements.d.ts +8 -0
- package/dist/libs/pipeExtensions.d.ts +4 -0
- package/dist/libs/read-buffer.d.ts +2 -0
- package/dist/main.d.ts +15 -0
- package/dist/ofd/ConverterDpi.d.ts +16 -0
- package/dist/ofd/index.d.ts +1 -0
- package/dist/ofd/ofd-utils.d.ts +137 -0
- package/dist/ofd/ofd.d.ts +35 -0
- package/dist/ofd/parse-ofd.d.ts +18 -0
- package/dist/ofd/render.d.ts +18 -0
- package/dist/ofd/svg-image.d.ts +12 -0
- package/dist/ofd/svg-path.d.ts +5 -0
- package/dist/ofd/svg-text.d.ts +8 -0
- package/dist/ofd.parse.d.ts +6 -0
- package/dist/ofd.xml.d.ts +1 -0
- package/dist/ofdParse.d.ts +6 -0
- package/dist/pipe/annotations.d.ts +13 -0
- package/dist/pipe/attachments.d.ts +13 -0
- package/dist/pipe/commonData.d.ts +18 -0
- package/dist/pipe/customTags.d.ts +14 -0
- package/dist/pipe/extensions.d.ts +14 -0
- package/dist/pipe/output.d.ts +7 -0
- package/dist/pipe/pages.d.ts +13 -0
- package/dist/pipe/permissions.d.ts +14 -0
- package/dist/pipe/pipeline.d.ts +63 -0
- package/dist/pipe/startPipe.d.ts +11 -0
- package/dist/xml/index.d.ts +2 -0
- package/dist/xml/render.d.ts +6 -0
- package/dist/xml/xml.d.ts +18 -0
- package/package.json +47 -0
- package/public/index.html +75 -0
- package/public/opentype.min.js +2 -0
- package/rollup.config.dev.mjs +47 -0
- package/rollup.config.mjs +70 -0
- package/src/constant/index.ts +13 -0
- package/src/core/ofd-core/Annotations/Annotation.km +206 -0
- package/src/core/ofd-core/Annotations/Annotations.km +59 -0
- package/src/core/ofd-core/Annotations/Annotations.md +13 -0
- package/src/core/ofd-core/Annotations/AnnotationsXml.ts +114 -0
- package/src/core/ofd-core/Asn.1Utils.ts +225 -0
- package/src/core/ofd-core/Documents/DocumentResXml.ts +55 -0
- package/src/core/ofd-core/Documents/Documnet.km +862 -0
- package/src/core/ofd-core/Documents/DocumnetXml.ts +118 -0
- package/src/core/ofd-core/Documents/Documnets.md +296 -0
- package/src/core/ofd-core/Documents/PublicResXml.ts +63 -0
- package/src/core/ofd-core/Documents//345/233/276/345/261/202/346/270/262/346/237/223/351/241/272/345/272/217.png +0 -0
- package/src/core/ofd-core/Documents//350/241/25022/347/272/277/346/235/241/350/277/236/346/216/245/346/240/267/345/274/217.png +0 -0
- package/src/core/ofd-core/Documents//350/241/25023/347/272/277/346/235/241/350/231/232/347/272/277/346/240/267/345/274/217.png +0 -0
- package/src/core/ofd-core/Documents//350/241/25023/347/273/223/345/220/210/347/202/271/351/225/277/345/272/246.png +0 -0
- package/src/core/ofd-core/Documents//350/241/25024/347/272/277/346/235/241/347/253/257/347/202/271/346/240/267/345/274/217.png +0 -0
- package/src/core/ofd-core/Documents//351/241/265/350/276/271/347/225/214/345/261/202/346/254/241/347/273/223/346/236/204.png +0 -0
- package/src/core/ofd-core/OFDElement.ts +724 -0
- package/src/core/ofd-core/Ofd/CT_DocInfo.km +197 -0
- package/src/core/ofd-core/Ofd/OFD.km +114 -0
- package/src/core/ofd-core/Ofd/OFD.md +99 -0
- package/src/core/ofd-core/Ofd/OFDXml.ts +69 -0
- package/src/core/ofd-core/Pages/PAGE.md +40 -0
- package/src/core/ofd-core/Pages/PageXml.ts +59 -0
- package/src/core/ofd-core/Signatures/Signature.km +308 -0
- package/src/core/ofd-core/Signatures/Signature.md +21 -0
- package/src/core/ofd-core/Signatures/Signatures.km +315 -0
- package/src/core/ofd-core/Signatures/Signatures.md +24 -0
- package/src/core/ofd-core/Signatures/Signatures.ts +247 -0
- package/src/core/ofd-core/TemplatePages/TemplatePages.ts +56 -0
- package/src/core/ofd-core/asn.md +60 -0
- package/src/core/ofd-core/constant.ts +35 -0
- package/src/core/ofd-core/index.d.ts +867 -0
- package/src/core/ofd-core/utils.ts +86 -0
- package/src/dicom/dicom.ts +42 -0
- package/src/dicom/index.ts +1 -0
- package/src/errors/ErrorHandle.ts +14 -0
- package/src/errors/FetchErrors.ts +8 -0
- package/src/errors/MimeError.ts +9 -0
- package/src/errors/OFDErrors.ts +11 -0
- package/src/errors/UnzipErrors.ts +9 -0
- package/src/errors/XmlErrors.ts +11 -0
- package/src/errors/error-msg.ts +17 -0
- package/src/es.ts +3 -0
- package/src/global.d.ts +7 -0
- package/src/index.ts +7 -0
- package/src/lib/ParseFile.ts +12 -0
- package/src/lib/README.md +69 -0
- package/src/lib/UnitCoversion.ts +55 -0
- package/src/lib/asn1/Asn.1.ts +284 -0
- package/src/lib/asn1/README.md +1 -0
- package/src/lib/asn1/Stream.ts +314 -0
- package/src/lib/asn1/asn1.ts +120 -0
- package/src/lib/asn1/base64.ts +97 -0
- package/src/lib/asn1/hex.ts +60 -0
- package/src/lib/asn1/index.ts +5 -0
- package/src/lib/asn1/int10.ts +103 -0
- package/src/lib/asn1/oids.ts +6164 -0
- package/src/lib/asn1/string-cut.ts +8 -0
- package/src/lib/decode-html.ts +37 -0
- package/src/lib/fetch.ts +70 -0
- package/src/lib/is-element.ts +13 -0
- package/src/lib/jbig/README.md +1 -0
- package/src/lib/jbig/arithmetic_decoder.js +184 -0
- package/src/lib/jbig/base_stream.js +117 -0
- package/src/lib/jbig/ccitt.js +1068 -0
- package/src/lib/jbig/ccitt_stream.js +60 -0
- package/src/lib/jbig/compatibility.js +108 -0
- package/src/lib/jbig/core_utils.js +591 -0
- package/src/lib/jbig/decode_stream.js +184 -0
- package/src/lib/jbig/is_node.js +28 -0
- package/src/lib/jbig/jbig2.js +2582 -0
- package/src/lib/jbig/jbig2_stream.js +78 -0
- package/src/lib/jbig/primitives.js +441 -0
- package/src/lib/jbig/stream.js +101 -0
- package/src/lib/jbig/util.js +1231 -0
- package/src/lib/load-files.ts +26 -0
- package/src/lib/load-opentype.ts +161 -0
- package/src/lib/load-script.ts +33 -0
- package/src/lib/mime.ts +97 -0
- package/src/lib/read-buffer.ts +19 -0
- package/src/lib/toFixeds.ts +56 -0
- package/src/ofd/ConverterDpi.ts +35 -0
- package/src/ofd/OFD.md +38 -0
- package/src/ofd/TODO.md +10 -0
- package/src/ofd/index.ts +1 -0
- package/src/ofd/ofd-utils.ts +627 -0
- package/src/ofd/ofd.demo.md +12 -0
- package/src/ofd/ofd.ts +200 -0
- package/src/ofd/ofdxml.km +162 -0
- package/src/ofd/parse-ofd.ts +103 -0
- package/src/ofd/render.ts +393 -0
- package/src/ofd/svg-image.ts +318 -0
- package/src/ofd/svg-path.ts +283 -0
- package/src/ofd/svg-text.ts +272 -0
- package/src/xml/index.ts +3 -0
- package/src/xml/render.ts +171 -0
- package/src/xml/xml.ts +136 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
# Signatures
|
|
3
|
+
|
|
4
|
+
签名节点
|
|
5
|
+
|
|
6
|
+
## MaxSignId
|
|
7
|
+
|
|
8
|
+
xs:ID 可选 安全标识的最大值,作用与文档人口文件Document. xml中的MaxID相同,为了避免在签名时影响文档入口文件,采用了与ST, _ID不一样的ID编码方式。推荐使用“sNNN”的编码方式,NNN从1开始
|
|
9
|
+
|
|
10
|
+
## Signature
|
|
11
|
+
|
|
12
|
+
数字签名或安全签章在列表中的注册信息,一次签名或签章对应一个
|
|
13
|
+
|
|
14
|
+
### ID
|
|
15
|
+
|
|
16
|
+
xs:ID 必选 签名或签章的标识
|
|
17
|
+
|
|
18
|
+
### Type
|
|
19
|
+
|
|
20
|
+
xs:string 可选 签名节点的类型,目前规定了两个可选值,Seal表示是安全签章,Sign表示是纯数字签名
|
|
21
|
+
|
|
22
|
+
### BaseLoc
|
|
23
|
+
|
|
24
|
+
ST_Loc 必选 指向包内的签名描述文件
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { Element } from 'xml-js';
|
|
2
|
+
import OFDElement from '../OFDElement';
|
|
3
|
+
// import PagesXml from '../Pages/PageXml';
|
|
4
|
+
import { NameREG } from '../utils';
|
|
5
|
+
import Asn1Utils from '../Asn.1Utils';
|
|
6
|
+
|
|
7
|
+
// import DocumentResXml from './DocumentResXml';
|
|
8
|
+
// import PublicResXml from './PublicResXml';
|
|
9
|
+
// import { OFD_Q } from '../constant';
|
|
10
|
+
import { Seal, Signature, Signatures, SignedInfo } from '../index.d';
|
|
11
|
+
|
|
12
|
+
class SignaturesXml extends OFDElement {
|
|
13
|
+
static fileName: string;
|
|
14
|
+
|
|
15
|
+
static Signatures: Signatures[];
|
|
16
|
+
// Doc_0/Signs/Signatures.xml 文件夹路径
|
|
17
|
+
signedPath: string;
|
|
18
|
+
|
|
19
|
+
constructor(fileName: string) {
|
|
20
|
+
super();
|
|
21
|
+
SignaturesXml.Signatures = [];
|
|
22
|
+
SignaturesXml.fileName = fileName;
|
|
23
|
+
// 获取 Doc_0/Signs/Signatures.xml 文件夹
|
|
24
|
+
this.signedPath = fileName.substring(0, fileName.lastIndexOf('/') + 1);
|
|
25
|
+
this.getSignatures();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getDocumentRes() {
|
|
29
|
+
// const res = this.getOFDElements(DocumnetXml.fileName, 'DocumentRes');
|
|
30
|
+
// if (res && res.elements) {
|
|
31
|
+
// return new DocumentResXml(res.elements);
|
|
32
|
+
// }
|
|
33
|
+
// return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getPublicRes() {
|
|
37
|
+
// const res = this.getOFDElements(DocumnetXml.fileName, 'PublicRes');
|
|
38
|
+
// if (res && res.elements) {
|
|
39
|
+
// return new PublicResXml(res.elements);
|
|
40
|
+
// }
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getSeal(filePath: string) {
|
|
45
|
+
const result: Seal = {};
|
|
46
|
+
const SealInfo = new Asn1Utils(OFDElement.OFDElements[filePath] as string);
|
|
47
|
+
const pictureInfo = SealInfo.getPicture();
|
|
48
|
+
if (pictureInfo) {
|
|
49
|
+
result.picture = { ...pictureInfo };
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getSignedInfo(signedInfoElement: Element[]): SignedInfo {
|
|
55
|
+
const result: SignedInfo = {};
|
|
56
|
+
for (let item of signedInfoElement) {
|
|
57
|
+
const { name, attributes, elements } = item;
|
|
58
|
+
if (name) {
|
|
59
|
+
const simpleName = name.replace(NameREG, '');
|
|
60
|
+
// 特殊处理 StampAnnot
|
|
61
|
+
if (simpleName === 'StampAnnot' && attributes) {
|
|
62
|
+
if (!result.StampAnnot) {
|
|
63
|
+
result.StampAnnot = [];
|
|
64
|
+
}
|
|
65
|
+
result.StampAnnot.push({
|
|
66
|
+
...attributes
|
|
67
|
+
});
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (simpleName === 'Provider' && attributes) {
|
|
71
|
+
result.Provider = { ...attributes };
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (
|
|
75
|
+
(simpleName === 'SignatureMethod' ||
|
|
76
|
+
simpleName === 'SignatureDateTime') &&
|
|
77
|
+
elements
|
|
78
|
+
) {
|
|
79
|
+
result[simpleName] = String(elements[0].text);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (simpleName === 'References') {
|
|
83
|
+
result.ReferencesCheckMethod = String(
|
|
84
|
+
attributes?.CheckMethod || 'MD5'
|
|
85
|
+
);
|
|
86
|
+
if (elements?.length) {
|
|
87
|
+
if (!result.References) {
|
|
88
|
+
result.References = [];
|
|
89
|
+
}
|
|
90
|
+
elements.forEach(reference => {
|
|
91
|
+
const FileRef = String(reference.attributes?.FileRef || '');
|
|
92
|
+
if (reference.elements?.length) {
|
|
93
|
+
const CheckValueElement = reference.elements.find(
|
|
94
|
+
ritem => ritem.name === this.OFDCommonQName('CheckValue')
|
|
95
|
+
);
|
|
96
|
+
if (CheckValueElement?.elements?.length) {
|
|
97
|
+
result.References?.push({
|
|
98
|
+
FileRef,
|
|
99
|
+
CheckValue: String(CheckValueElement?.elements[0].text)
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// if (
|
|
107
|
+
// simpleName === 'Seal' &&
|
|
108
|
+
// elements &&
|
|
109
|
+
// elements[0].name === this.OFDCommonQName('BaseLoc')
|
|
110
|
+
// ) {
|
|
111
|
+
// const sealLoc = elements[0].elements
|
|
112
|
+
// ? String(elements[0].elements[0].text)
|
|
113
|
+
// : '';
|
|
114
|
+
// console.log('sealLoc:', sealLoc);
|
|
115
|
+
// result.Seal = this.getSeal(sealLoc.replace(/^\//, ''));
|
|
116
|
+
// }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
getSignature(filePath: string) {
|
|
123
|
+
const res = this.getOFDElements(filePath, 'Signature');
|
|
124
|
+
if (res?.elements) {
|
|
125
|
+
const result: Signature = {};
|
|
126
|
+
for (let item of res?.elements) {
|
|
127
|
+
const { name, elements } = item;
|
|
128
|
+
if (name && elements?.length) {
|
|
129
|
+
const simpleName = name?.replace(NameREG, '');
|
|
130
|
+
if (simpleName === 'SignedValue') {
|
|
131
|
+
result.SignedValueLoc = String(elements[0]?.text || '');
|
|
132
|
+
if (!result.SignedInfo) {
|
|
133
|
+
result.SignedInfo = {};
|
|
134
|
+
}
|
|
135
|
+
// 此路径可能为 相对路径
|
|
136
|
+
const currentPath = filePath.substring(
|
|
137
|
+
0,
|
|
138
|
+
filePath.lastIndexOf('/') + 1
|
|
139
|
+
);
|
|
140
|
+
result.SignedInfo.Seal = this.getSeal(
|
|
141
|
+
currentPath +
|
|
142
|
+
result.SignedValueLoc.replace(
|
|
143
|
+
new RegExp(currentPath),
|
|
144
|
+
''
|
|
145
|
+
).replace(/^\//, '')
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
if (simpleName === 'SignedInfo') {
|
|
149
|
+
if (!result.SignedInfo) {
|
|
150
|
+
result.SignedInfo = {};
|
|
151
|
+
}
|
|
152
|
+
Object.assign(result.SignedInfo, this.getSignedInfo(elements));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 获取文档区域坐标
|
|
163
|
+
* @returns
|
|
164
|
+
*/
|
|
165
|
+
getSignatures() {
|
|
166
|
+
const res = this.getOFDElements(SignaturesXml.fileName, 'Signatures');
|
|
167
|
+
if (res && res.elements) {
|
|
168
|
+
const SignaturesElements = res.elements;
|
|
169
|
+
SignaturesElements.forEach(item => {
|
|
170
|
+
if (item?.name) {
|
|
171
|
+
const { name, attributes } = item;
|
|
172
|
+
const simpleName = name.replace(NameREG, '');
|
|
173
|
+
if (simpleName === 'Signature' && attributes?.BaseLoc) {
|
|
174
|
+
// 获取Signature xml文件
|
|
175
|
+
const { ID, Type, BaseLoc } = attributes as {
|
|
176
|
+
ID: string;
|
|
177
|
+
Type: string;
|
|
178
|
+
BaseLoc: string;
|
|
179
|
+
};
|
|
180
|
+
// 此路径可能为 相对路径
|
|
181
|
+
const signedInfo = this.getSignature(
|
|
182
|
+
this.signedPath +
|
|
183
|
+
BaseLoc.replace(new RegExp(this.signedPath), '').replace(
|
|
184
|
+
/^\//,
|
|
185
|
+
''
|
|
186
|
+
)
|
|
187
|
+
);
|
|
188
|
+
if (!SignaturesXml.Signatures) {
|
|
189
|
+
SignaturesXml.Signatures = [];
|
|
190
|
+
}
|
|
191
|
+
SignaturesXml.Signatures.push({
|
|
192
|
+
ID,
|
|
193
|
+
Type,
|
|
194
|
+
BaseLoc,
|
|
195
|
+
Signature: signedInfo
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
if (SignaturesXml.Signatures?.length) {
|
|
201
|
+
// 组装成方便遍历的数据,{[id:pageid]:info}
|
|
202
|
+
const result: { [key: string]: Signatures[] } = {};
|
|
203
|
+
SignaturesXml.Signatures.forEach(item => {
|
|
204
|
+
const { Signature } = item;
|
|
205
|
+
if (Signature?.SignedInfo?.StampAnnot?.length) {
|
|
206
|
+
const StampAnnot = Signature.SignedInfo.StampAnnot.map(sa => ({
|
|
207
|
+
...sa
|
|
208
|
+
}));
|
|
209
|
+
StampAnnot.forEach(cItem => {
|
|
210
|
+
if (cItem?.PageRef) {
|
|
211
|
+
if (!result[cItem.PageRef]) {
|
|
212
|
+
result[cItem.PageRef] = [];
|
|
213
|
+
}
|
|
214
|
+
const newItem = {
|
|
215
|
+
...item,
|
|
216
|
+
Signature: {
|
|
217
|
+
...item.Signature,
|
|
218
|
+
SignedInfo: {
|
|
219
|
+
...item.Signature?.SignedInfo,
|
|
220
|
+
StampAnnot: item.Signature?.SignedInfo?.StampAnnot?.map(
|
|
221
|
+
sa => ({ ...sa })
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
if (newItem.Signature?.SignedInfo?.StampAnnot?.length) {
|
|
227
|
+
newItem.Signature.SignedInfo.StampAnnot = StampAnnot.filter(
|
|
228
|
+
sItem => sItem.PageRef === cItem.PageRef
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
result[cItem.PageRef].push({
|
|
232
|
+
...newItem
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
OFDElement.Signatures = SignaturesXml.Signatures;
|
|
240
|
+
OFDElement.PageSignatures = result;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export default SignaturesXml;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Element } from 'xml-js';
|
|
2
|
+
import { replacePathPriex } from '../utils';
|
|
3
|
+
import VaildOFDError from '../../../errors/OFDErrors';
|
|
4
|
+
|
|
5
|
+
import OFDElement from '../OFDElement';
|
|
6
|
+
// import OFDXMl from '../ofd/OFDXml';
|
|
7
|
+
// import { OFD_PATH } from '../constant';
|
|
8
|
+
|
|
9
|
+
class TemplatePages extends OFDElement {
|
|
10
|
+
/**
|
|
11
|
+
* TemplatePages 文件,以数组存放,存在多页
|
|
12
|
+
* @date 2022/7/27 - 09:41:22
|
|
13
|
+
*
|
|
14
|
+
* @type {Element[]}
|
|
15
|
+
*/
|
|
16
|
+
tplsXml: { [k: string]: Element } | null;
|
|
17
|
+
static fileName: string;
|
|
18
|
+
constructor(tplsElements: Element[]) {
|
|
19
|
+
super();
|
|
20
|
+
// 区分多页TemplatePages 暂时没有该类型OFD
|
|
21
|
+
if (tplsElements?.length) {
|
|
22
|
+
this.setTplsXml(tplsElements);
|
|
23
|
+
} else {
|
|
24
|
+
throw new VaildOFDError(9999, 'Documents下TemplatePage解析失败');
|
|
25
|
+
}
|
|
26
|
+
this.tplsXml = null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
formatTplsXml(tplsFile: { [k: string]: Element }) {
|
|
30
|
+
Object.entries(tplsFile).forEach(([keys, content]) => {
|
|
31
|
+
if (content && content.elements?.length) {
|
|
32
|
+
this.setTpls(content, keys);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
setTplsXml(tplsElements: Element[]): void {
|
|
38
|
+
tplsElements.forEach(tplElement => {
|
|
39
|
+
if (tplElement?.attributes) {
|
|
40
|
+
const { BaseLoc, ID = '' } = tplElement.attributes;
|
|
41
|
+
const tplsPath = replacePathPriex(OFDElement.STLoc, `${BaseLoc}`);
|
|
42
|
+
if (!this.tplsXml) {
|
|
43
|
+
this.tplsXml = {};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.tplsXml[ID] = OFDElement.OFDElements[tplsPath];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (this.tplsXml) {
|
|
50
|
+
// 获取 Tpls xml 内数据
|
|
51
|
+
this.formatTplsXml(this.tplsXml);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default TemplatePages;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# ASN.1 说明
|
|
2
|
+
|
|
3
|
+
Abstract Syntax Notation One,抽象语法标记,ASN.1是描述数据格式的标准方法,它不管语言是如何执行、这些数据具体指什么、用什么类型的编码规则,是一种抽象的语法
|
|
4
|
+
|
|
5
|
+
ASN.1由两部分组成:
|
|
6
|
+
|
|
7
|
+
一部分描述信息内数据,数据类型及序列格式
|
|
8
|
+
另一部分描述如何将各部分组成消息
|
|
9
|
+
|
|
10
|
+
## 语法
|
|
11
|
+
|
|
12
|
+
### 例如
|
|
13
|
+
|
|
14
|
+
```C++
|
|
15
|
+
Report ::= SEQUENCE {
|
|
16
|
+
author OCTET STRING,
|
|
17
|
+
title OCTET STRING,
|
|
18
|
+
body OCTET STRING,
|
|
19
|
+
biblio Bibliography
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Report是结构体名称
|
|
24
|
+
|
|
25
|
+
1. SEQUENCE表示消息是由许多数据单元构成的
|
|
26
|
+
2. 中括号{}里面是各种类型的数据单元
|
|
27
|
+
3. 前三个数据单元author/title/body的类型是OCTET STRING
|
|
28
|
+
4. 最后一个数据单元biblio的类型是另一个ASN.1结构体
|
|
29
|
+
|
|
30
|
+
``` C++
|
|
31
|
+
Bibliography ::= SEQUENCE {
|
|
32
|
+
author OCTET STRING
|
|
33
|
+
title OCTET STRING
|
|
34
|
+
publisher OCTET STRING
|
|
35
|
+
year OCTET STRING
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 数据类型
|
|
40
|
+
|
|
41
|
+
| 类型 | 含义 |
|
|
42
|
+
| ----------------------------- | ---------- |
|
|
43
|
+
| NULL | 空 |
|
|
44
|
+
| BOOLEAN | 布尔类型 |
|
|
45
|
+
| INTEGER | 整型 |
|
|
46
|
+
| REAL | 实数类型 |
|
|
47
|
+
| BIT STRING | 比特串 |
|
|
48
|
+
| OCTEC STRING | 字节串 |
|
|
49
|
+
| OBJECT IDENTIFIER | 实体标识符 |
|
|
50
|
+
| ENUMERATED | 枚举类型 |
|
|
51
|
+
| SEQUENCE | 序列 |
|
|
52
|
+
| SEQUENCE OF | 类型的序列 |
|
|
53
|
+
| SET | 集合 |
|
|
54
|
+
| SET OF | 类型的集合 |
|
|
55
|
+
| CHOICE | CHOICE类型 |
|
|
56
|
+
| …STRING(有很多就不一一列举) | 字符串类型 |
|
|
57
|
+
| UTCTime | 时间类型 |
|
|
58
|
+
| GeneralizedTime | 时间类型 |
|
|
59
|
+
|
|
60
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 命名空间 URI,《GB/T_33190-2016》 7.1 命名空间
|
|
3
|
+
*/
|
|
4
|
+
export const OFD_NAMESPACE_URI = 'http://www.ofdspec.org/2016' as string;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 元素节点应使用命名空间标识符
|
|
8
|
+
* ————《GB/T 33190-2016》 7.1 命名空间
|
|
9
|
+
*/
|
|
10
|
+
export const OFD_VALUE = 'ofd' as string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* OFD命名空间
|
|
14
|
+
*/
|
|
15
|
+
export const OFD_Q = 'ofd:' as string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* OFD地址前缀 DOC_0/
|
|
19
|
+
*/
|
|
20
|
+
export const OFD_PATH = 'DOC_0/' as string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* xs:date 类型日期格式化
|
|
24
|
+
*/
|
|
25
|
+
export const DATE_FORMATTER = 'yyyy-MM-dd' as string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* xs:dateTime 类型时间日期格式化
|
|
29
|
+
*/
|
|
30
|
+
export const DATETIME_FORMATTER = "yyyy-MM-dd'T'hh:mm:ss" as string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* OFD索引文件
|
|
34
|
+
*/
|
|
35
|
+
export const INDEX_FILE = 'OFD.xml' as string;
|