本文整理汇总了TypeScript中asn1js.fromBER函数的典型用法代码示例。如果您正苦于以下问题:TypeScript fromBER函数的具体用法?TypeScript fromBER怎么用?TypeScript fromBER使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromBER函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: verifyCMSSigned
// *********************************************************************************
// endregion
// *********************************************************************************
// region Verify existing CMS_Signed
// *********************************************************************************
function verifyCMSSigned() {
// region Initial check
if (cmsSignedBuffer.byteLength === 0) {
alert("Nothing to verify!");
return;
}
// endregion
// region Decode existing CMS_Signed
const asn1 = asn1js.fromBER(cmsSignedBuffer);
const cmsContentSimpl = new ContentInfo({ schema: asn1.result });
const cmsSignedSimpl = new SignedData({ schema: cmsContentSimpl.content });
// endregion
// region Verify CMS_Signed
cmsSignedSimpl.verify({ signer: 0, trustedCerts: trustedCertificates }).
then(
result => alert(`Verification result: ${result}`),
error => alert(`Error during verification: ${error}`)
);
// endregion
}
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:27,代码来源:pkijs-tests.ts
示例2: parseCAbundle
// *********************************************************************************
// endregion
// *********************************************************************************
// region Parse "CA Bundle" file
// *********************************************************************************
function parseCAbundle(buffer: ArrayBuffer) {
// region Initial variables
const base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
const startChars = "-----BEGIN CERTIFICATE-----";
const endChars = "-----END CERTIFICATE-----";
const endLineChars = "\r\n";
const view = new Uint8Array(buffer);
let waitForStart = false;
let middleStage = true;
let waitForEnd = false;
let waitForEndLine = false;
let started = false;
let certBodyEncoded = "";
// endregion
for (let i = 0; i < view.length; i++) {
if (started === true) {
if (base64Chars.indexOf(String.fromCharCode(view[i])) !== (-1))
certBodyEncoded = certBodyEncoded + String.fromCharCode(view[i]);
else {
if (String.fromCharCode(view[i]) === "-") {
// region Decoded trustedCertificates
const asn1 = asn1js.fromBER(stringToArrayBuffer(window.atob(certBodyEncoded)));
try {
trustedCertificates.push(new Certificate({ schema: asn1.result }));
}
catch (ex) {
alert("Wrong certificate format");
return;
}
// endregion
// region Set all "flag variables"
certBodyEncoded = "";
started = false;
waitForEnd = true;
// endregion
}
}
}
else {
if (waitForEndLine === true) {
if (endLineChars.indexOf(String.fromCharCode(view[i])) === (-1)) {
waitForEndLine = false;
if (waitForEnd === true) {
waitForEnd = false;
middleStage = true;
}
else {
if (waitForStart === true) {
waitForStart = false;
started = true;
certBodyEncoded = certBodyEncoded + String.fromCharCode(view[i]);
}
else
middleStage = true;
}
}
}
else {
if (middleStage === true) {
if (String.fromCharCode(view[i]) === "-") {
if ((i === 0) ||
((String.fromCharCode(view[i - 1]) === "\r") ||
(String.fromCharCode(view[i - 1]) === "\n"))) {
middleStage = false;
waitForStart = true;
}
}
}
else {
if (waitForStart === true) {
if (startChars.indexOf(String.fromCharCode(view[i])) === (-1))
waitForEndLine = true;
}
else {
if (waitForEnd === true) {
if (endChars.indexOf(String.fromCharCode(view[i])) === (-1))
waitForEndLine = true;
}
}
}
}
}
}
}
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:98,代码来源:pkijs-tests.ts
示例3: parseCMSSigned
export function parseCMSSigned() {
// region Initial check
if (cmsSignedBuffer.byteLength === 0) {
alert("Nothing to parse!");
return;
}
// endregion
// region Initial activities
document.getElementById("cms-dgst-algos").innerHTML = "";
document.getElementById("cms-certs").style.display = "none";
document.getElementById("cms-crls").style.display = "none";
const certificatesTable = document.getElementById("cms-certificates") as HTMLTableElement;
while (certificatesTable.rows.length > 1)
certificatesTable.deleteRow(certificatesTable.rows.length - 1);
const crlsTable = document.getElementById("cms-rev-lists") as HTMLTableElement;
while (crlsTable.rows.length > 1)
crlsTable.deleteRow(crlsTable.rows.length - 1);
// endregion
// region Decode existing CMS Signed Data
const asn1 = asn1js.fromBER(cmsSignedBuffer);
const cmsContentSimpl = new ContentInfo({ schema: asn1.result });
const cmsSignedSimpl = new SignedData({ schema: cmsContentSimpl.content });
// endregion
// region Put information about digest algorithms in the CMS Signed Data
const dgstmap: { [oid: string]: string } = {
"1.3.14.3.2.26": "SHA-1",
"2.16.840.1.101.3.4.2.1": "SHA-256",
"2.16.840.1.101.3.4.2.2": "SHA-384",
"2.16.840.1.101.3.4.2.3": "SHA-512"
};
for (let i = 0; i < cmsSignedSimpl.digestAlgorithms.length; i++) {
let typeval = dgstmap[cmsSignedSimpl.digestAlgorithms[i].algorithmId];
if (typeof typeval === "undefined")
typeval = cmsSignedSimpl.digestAlgorithms[i].algorithmId;
const ulrow = `<li><p><span>${typeval}</span></p></li>`;
document.getElementById("cms-dgst-algos").innerHTML = document.getElementById("cms-dgst-algos").innerHTML + ulrow;
}
// endregion
// region Put information about encapsulated content type
const contypemap: { [oid: string]: string } = {
"1.3.6.1.4.1.311.2.1.4": "Authenticode signing information",
"1.2.840.113549.1.7.1": "Data content"
};
let eContentType = contypemap[cmsSignedSimpl.encapContentInfo.eContentType];
if (typeof eContentType === "undefined")
eContentType = cmsSignedSimpl.encapContentInfo.eContentType;
document.getElementById("cms-encap-type").innerHTML = eContentType;
// endregion
// region Put information about included certificates
const rdnmap: { [oid: string]: string } = {
"2.5.4.6": "C",
"2.5.4.10": "OU",
"2.5.4.11": "O",
"2.5.4.3": "CN",
"2.5.4.7": "L",
"2.5.4.8": "S",
"2.5.4.12": "T",
"2.5.4.42": "GN",
"2.5.4.43": "I",
"2.5.4.4": "SN",
"1.2.840.113549.1.9.1": "E-mail"
};
if ("certificates" in cmsSignedSimpl) {
for (let cert of cmsSignedSimpl.certificates) {
if (cert instanceof Certificate) {
let ul = "<ul>";
for (let i = 0; i < cert.issuer.typesAndValues.length; i++) {
let typeval = rdnmap[cert.issuer.typesAndValues[i].type.toString()];
if (typeof typeval === "undefined")
typeval = cert.issuer.typesAndValues[i].type.toString();
const subjval = cert.issuer.typesAndValues[i].value.valueBlock.value;
const ulrow = `<li><p><span>${typeval}</span> ${subjval}</p></li>`;
ul = ul + ulrow;
}
ul = `${ul}</ul>`;
const row = certificatesTable.insertRow(certificatesTable.rows.length);
const cell0 = row.insertCell(0);
cell0.innerHTML = bufferToHexCodes(cert.serialNumber.valueBlock.valueHex);
const cell1 = row.insertCell(1);
cell1.innerHTML = ul;
}
}
//.........这里部分代码省略.........
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:101,代码来源:pkijs-tests.ts
注:本文中的asn1js.fromBER函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论