mirror of
https://gitee.com/Donal/ofd.js.git
synced 2024-11-30 02:48:47 +08:00
优化代码
This commit is contained in:
parent
388895d0f2
commit
fbe46a563d
@ -386,7 +386,7 @@ const decodeSES_Signature = function (der, offset) {
|
||||
})
|
||||
});
|
||||
}
|
||||
const SES_Signature =
|
||||
const SES_Signature =
|
||||
{
|
||||
'toSign':{
|
||||
'version':asn1.sub[0]?.sub[0]?.stream.parseInteger(asn1.sub[0].sub[0].stream.pos + asn1.sub[0].sub[0].header, asn1.sub[0].sub[0].stream.pos + asn1.sub[0].sub[0].header + asn1.sub[0].sub[0].length),
|
||||
@ -410,7 +410,7 @@ const decodeSES_Signature = function (der, offset) {
|
||||
},
|
||||
'picture':{
|
||||
'type':asn1.sub[0]?.sub[1]?.sub[0]?.sub[3]?.sub[0]?.stream.parseStringUTF(asn1.sub[0].sub[1].sub[0].sub[3].sub[0].stream.pos + asn1.sub[0].sub[1].sub[0].sub[3].sub[0].header, asn1.sub[0].sub[1].sub[0].sub[3].sub[0].stream.pos + asn1.sub[0].sub[1].sub[0].sub[3].sub[0].header + asn1.sub[0].sub[1].sub[0].sub[3].sub[0].length),
|
||||
'data':asn1.sub[0]?.sub[1]?.sub[0]?.sub[3]?.sub[1]?.stream.parseOctetString(asn1.sub[0].sub[1].sub[0].sub[3].sub[1].stream.pos + asn1.sub[0].sub[1].sub[0].sub[3].sub[1].header, asn1.sub[0].sub[1].sub[0].sub[3].sub[1].stream.pos + asn1.sub[0].sub[1].sub[0].sub[3].sub[1].header + asn1.sub[0].sub[1].sub[0].sub[3].sub[1].length),
|
||||
'data': {'hex': asn1.sub[0]?.sub[1]?.sub[0]?.sub[3]?.sub[1]?.stream.parseOctetString(asn1.sub[0].sub[1].sub[0].sub[3].sub[1].stream.pos + asn1.sub[0].sub[1].sub[0].sub[3].sub[1].header, asn1.sub[0].sub[1].sub[0].sub[3].sub[1].stream.pos + asn1.sub[0].sub[1].sub[0].sub[3].sub[1].header + asn1.sub[0].sub[1].sub[0].sub[3].sub[1].length), byte: asn1.sub[0]?.sub[1]?.sub[0]?.sub[3]?.sub[1]?.stream.enc.subarray(asn1.sub[0].sub[1].sub[0].sub[3].sub[1].stream.pos + asn1.sub[0].sub[1].sub[0].sub[3].sub[1].header, asn1.sub[0].sub[1].sub[0].sub[3].sub[1].stream.pos + asn1.sub[0].sub[1].sub[0].sub[3].sub[1].header + asn1.sub[0].sub[1].sub[0].sub[3].sub[1].length)},
|
||||
'width':asn1.sub[0]?.sub[1]?.sub[0]?.sub[3]?.sub[2]?.stream.parseInteger(asn1.sub[0].sub[1].sub[0].sub[3].sub[2].stream.pos + asn1.sub[0].sub[1].sub[0].sub[3].sub[2].header, asn1.sub[0].sub[1].sub[0].sub[3].sub[2].stream.pos + asn1.sub[0].sub[1].sub[0].sub[3].sub[2].header + asn1.sub[0].sub[1].sub[0].sub[3].sub[2].length),
|
||||
'height':asn1.sub[0]?.sub[1]?.sub[0]?.sub[3]?.sub[3]?.stream.parseInteger(asn1.sub[0].sub[1].sub[0].sub[3].sub[3].stream.pos + asn1.sub[0].sub[1].sub[0].sub[3].sub[3].header, asn1.sub[0].sub[1].sub[0].sub[3].sub[3].stream.pos + asn1.sub[0].sub[1].sub[0].sub[3].sub[3].header + asn1.sub[0].sub[1].sub[0].sub[3].sub[3].length),
|
||||
},
|
||||
@ -458,10 +458,8 @@ const decode = function (der, offset) {
|
||||
offset = offset || 0;
|
||||
try {
|
||||
const SES_Signature = decodeSES_Signature(der,offset);
|
||||
let asn1 = ASN1.decode(der, offset);
|
||||
const type = getSealType(asn1);
|
||||
const sealObj = asn1.sub[0].sub[1].sub[0].sub[3].sub[1];
|
||||
const ofdArray = sealObj.stream.enc.subarray(sealObj.stream.pos + sealObj.header, sealObj.stream.pos + sealObj.length + sealObj.header);
|
||||
const type = SES_Signature.toSign.eseal.esealInfo.picture.type;
|
||||
const ofdArray = SES_Signature.toSign.eseal.esealInfo.picture.data.byte;
|
||||
return {ofdArray, 'type': type.toLowerCase(), SES_Signature};
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
@ -469,12 +467,6 @@ const decode = function (der, offset) {
|
||||
}
|
||||
}
|
||||
|
||||
const getSealType = function (asn1) {
|
||||
const sealObj = asn1.sub[0].sub[1].sub[0].sub[3].sub[0];
|
||||
const ofdArray = sealObj.stream.enc.subarray(sealObj.stream.pos + sealObj.header, sealObj.stream.pos + sealObj.length + sealObj.header);
|
||||
return Uint8ArrayToString(ofdArray);
|
||||
}
|
||||
|
||||
const Uint8ArrayToString = function (fileData) {
|
||||
let dataString = "";
|
||||
for (let i = 0; i < fileData.length; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user