Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr SMS Gateway8 * File : backend/src/security/segments.ts9 * Module : security10 * Repository : https://git.spboucher.ai/maclustr-sms11 * Project Website : https://sms.spboucher.ai12 * Created : 2026-11-3013 * Last Modified : 2026-11-3014 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Sans dépendance Node : ce module est aussi importé par le tableau de bord (compteur de segments de la console).43// Alphabet GSM 03.38 (table de base + extension). Un caractère hors de ces tables impose l'UCS-2.44const GSM_BASIC = "@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà"45const GSM_EXT = "^{}\\[~]|€\f"46const basic = new Set(GSM_BASIC), ext = new Set(GSM_EXT)4748export interface SegmentInfo { encoding: "gsm7" | "ucs2"; chars: number; units: number; segments: number; per_segment: number }49/** Estimation du découpage (identique à celle d'un modem standard ; l'appareil reste l'arbitre final via divideMessage). */50export function segmentInfo(text: string): SegmentInfo {51 let gsm = true, septets = 052 for (const ch of text) { if (basic.has(ch)) septets += 1; else if (ext.has(ch)) septets += 2; else { gsm = false; break } }53 const chars = [...text].length54 if (gsm) {55 const segments = septets <= 160 ? 1 : Math.ceil(septets / 153)56 return { encoding: "gsm7", chars, units: septets, segments: Math.max(segments, 1), per_segment: septets <= 160 ? 160 : 153 }57 }58 const units = text.length // unités UTF-1659 const segments = units <= 70 ? 1 : Math.ceil(units / 67)60 return { encoding: "ucs2", chars, units, segments: Math.max(segments, 1), per_segment: units <= 70 ? 70 : 67 }61}62export const MAX_SEGMENTS = 1063