Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 798b136f authored by Simon Chan's avatar Simon Chan
Browse files

feat: explicitly annotate locally created `Uint8Array`s in return types

parent 443521f9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ import { decodeUtf8, string, struct, u32 } from "@yume-chan/struct";

import { unreachable } from "../../utils/no-op.js";

function encodeAsciiUnchecked(value: string): Uint8Array {
function encodeAsciiUnchecked(value: string): Uint8Array<ArrayBuffer> {
    const result = new Uint8Array(value.length);
    for (let i = 0; i < value.length; i += 1) {
        result[i] = value.charCodeAt(i);
+7 −2
Original line number Diff line number Diff line
@@ -140,7 +140,9 @@ export function adbGetPublicKeySize() {
    return 4 + 4 + ModulusLengthInBytes + ModulusLengthInBytes + 4;
}

export function adbGeneratePublicKey(privateKey: Uint8Array): Uint8Array;
export function adbGeneratePublicKey(
    privateKey: Uint8Array,
): Uint8Array<ArrayBuffer>;
export function adbGeneratePublicKey(
    privateKey: Uint8Array,
    output: Uint8Array,
@@ -287,7 +289,10 @@ export const SHA1_DIGEST_INFO = new Uint8Array([
// encrypt the given data with its private key)
// However SubtileCrypto.encrypt() doesn't accept 'RSASSA-PKCS1-v1_5' algorithm
// So we need to implement the encryption by ourself
export function rsaSign(privateKey: Uint8Array, data: Uint8Array): Uint8Array {
export function rsaSign(
    privateKey: Uint8Array,
    data: Uint8Array,
): Uint8Array<ArrayBuffer> {
    const [n, d] = rsaParsePrivateKey(privateKey);

    // PKCS#1 padding
+2 −2
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ export function calculateBase64EncodedLength(
 * @param input The input buffer
 * @returns The encoded output buffer
 */
export function encodeBase64(input: Uint8Array): Uint8Array;
export function encodeBase64(input: Uint8Array): Uint8Array<ArrayBuffer>;
/**
 * Encode the given input into base64 and write it to the output buffer.
 *
@@ -295,7 +295,7 @@ function encodeBackward(
    }
}

export function decodeBase64(input: string): Uint8Array {
export function decodeBase64(input: string): Uint8Array<ArrayBuffer> {
    let padding: number;
    if (input[input.length - 2] === "=") {
        padding = 2;
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ export class HidMouse {
        buttons?: number;
        scrollX?: number;
        scrollY?: number;
    }): Uint8Array {
    }): Uint8Array<ArrayBuffer> {
        return new Uint8Array([
            report.buttons ?? 0,
            report.movementX ?? 0,
+1 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ export class HidTouchScreen {
        this.#fingers.delete(id);
    }

    serializeInputReport(): Uint8Array {
    serializeInputReport(): Uint8Array<ArrayBuffer> {
        const report = new Uint8Array(1 + 6 * 10);
        report[0] = this.#fingers.size;
        let offset = 1;