export function computePadding(size, modulo) {
    return (modulo - (size % modulo)) % modulo;
}
export function senderIdToUserId(senderId) {
    if (senderId >= 0x80) {
        senderId += 0xff00;
    }
    return senderId;
}
export function userIdToSenderId(userId) {
    if (userId > 0xffff) {
        throw new Error(`Invalid user id. Should be between 0 and ${0xffff}`); // TODO custom error
    }
    if (userId > 0x7f && userId < 0xff80) {
        throw new Error(`Invalid user id. Should be between 0 and ${0} and ${0x7f} or ${0xffff} and ${0xff80}`);
    } // TODO custom error
    return 0xff & userId;
}
export function usernameToSenderId(username) {
    switch (username) {
        case 'IoTize':
            return 0xfd;
        case 'admin':
            return userIdToSenderId(0xffff); // TODO constant
        case 'anonymous':
            return userIdToSenderId(0x0);
        case 'supervisor':
            return userIdToSenderId(0xfffe);
        default:
            return 0;
    }
}
// function createCredentialsFromCurrentSessionData() {
//     const authSessionState = this.tap.auth.sessionStateSnapshot;
//     const authSessionData = this.tap.auth.sessionDataSnapshot;
//     console.info('Session data: ', authSessionState);
//     if (!authSessionData.serverKey || !authSessionData.storedKey || !authSessionState.name) {
//         throw SinglePacketError.authSessionRequiredToEncryptSinglePacket();
//     }
//     return SinglePacketEncryptionOptionsBuilder.fromCurrentSessionData({
//         username: authSessionState.name,
//         serverKey: authSessionData.serverKey,
//         storedKey: authSessionData.storedKey
//     });
// }
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uL3NlcnZpY2UvaW1wbC9zaW5nbGUtcGFja2V0L3NyYy9saWIvY3VzdG9tL3V0aWwudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsTUFBTSxVQUFVLGNBQWMsQ0FBQyxJQUFZLEVBQUUsTUFBYztJQUN6RCxPQUFPLENBQUMsTUFBTSxHQUFHLENBQUMsSUFBSSxHQUFHLE1BQU0sQ0FBQyxD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