当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript pvutils.stringToArrayBuffer函数代码示例

本文整理汇总了TypeScript中pvutils.stringToArrayBuffer函数的典型用法代码示例。如果您正苦于以下问题:TypeScript stringToArrayBuffer函数的具体用法?TypeScript stringToArrayBuffer怎么用?TypeScript stringToArrayBuffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了stringToArrayBuffer函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: 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

示例2: ArrayBuffer

pvutils.checkBufferParams({}, new ArrayBuffer(0), 0, 0).valueOf();

pvutils.utilFromBase(new Uint8Array(0), 0).toFixed();

pvutils.utilToBase(0, 0).byteLength;
pvutils.utilToBase(0, 0, 0).byteLength;

pvutils.utilConcatBuf(new ArrayBuffer(0), new ArrayBuffer(0), new ArrayBuffer(0), new ArrayBuffer(0)).byteLength;

pvutils.utilDecodeTC().toFixed();

pvutils.utilEncodeTC(0).byteLength;

pvutils.isEqualBuffer(new ArrayBuffer(0), new ArrayBuffer(0)) === true;

pvutils.padNumber(0, 0).charAt(0);

pvutils.toBase64("").charAt(0);
pvutils.toBase64("", true).charAt(0);
pvutils.toBase64("", true, true).charAt(0);

pvutils.fromBase64("", true).charAt(0);
pvutils.fromBase64("", true, true).charAt(0);

pvutils.arrayBufferToString(new ArrayBuffer(0)).charAt(0);
pvutils.arrayBufferToString(new Uint8Array(0)).charAt(0);

pvutils.stringToArrayBuffer("").byteLength;

pvutils.nearestPowerOf2(0).toFixed();
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:30,代码来源:pvutils-tests.ts


注:本文中的pvutils.stringToArrayBuffer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。