payfrit-beacon-ios/PayfritBeacon/BeaconBanList.swift
Schwifty 237ac38557 refactor: consolidate UUID formatting into shared String extension
Created UUIDFormatting.swift with .normalizedUUID and .uuidWithDashes
String extensions, replacing 4 duplicate formatUuidWithDashes() methods
and 6+ inline .replacingOccurrences(of: "-", with: "").uppercased() calls
across Api.swift, BeaconScanner.swift, ScanView.swift,
ServicePointListView.swift, BeaconBanList.swift, and BeaconProvisioner.swift.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 10:02:58 +00:00

72 lines
2.8 KiB
Swift

import Foundation
enum BeaconBanList {
/// Known default UUID prefixes (first 8 hex chars of the 32-char UUID).
private static let BANNED_PREFIXES: [String: String] = [
// Apple AirLocate / Minew factory default
"E2C56DB5": "Apple AirLocate / Minew factory default",
// Kontakt.io default
"F7826DA6": "Kontakt.io factory default",
// Radius Networks default
"2F234454": "Radius Networks default",
// Estimote default
"B9407F30": "Estimote factory default",
// Generic Chinese bulk manufacturer defaults (also Feasycom)
"FDA50693": "Generic bulk / Feasycom factory default",
"74278BDA": "Generic bulk manufacturer default",
"8492E75F": "Generic bulk manufacturer default",
"A0B13730": "Generic bulk manufacturer default",
// JAALEE default
"EBEFD083": "JAALEE factory default",
// April Brother default
"B5B182C7": "April Brother factory default",
// BlueCharm / unconfigured
"00000000": "Unconfigured / zeroed UUID",
"FFFFFFFF": "Unconfigured / max UUID",
]
/// Full UUIDs that are known defaults (exact match on 32-char uppercase hex).
private static let BANNED_FULL_UUIDS: [String: String] = [
"E2C56DB5DFFB48D2B060D0F5A71096E0": "Apple AirLocate sample UUID",
"B9407F30F5F8466EAFF925556B57FE6D": "Estimote factory default",
"2F234454CF6D4A0FADF2F4911BA9FFA6": "Radius Networks default",
"FDA50693A4E24FB1AFCFC6EB07647825": "Generic Chinese bulk default",
"74278BDAB64445208F0C720EAF059935": "Generic bulk default",
"00000000000000000000000000000000": "Zeroed UUID \u{2014} unconfigured hardware",
]
/// Check if a UUID is on the ban list.
static func isBanned(_ uuid: String) -> Bool {
let normalized = uuid.normalizedUUID
// Check full UUID match
if BANNED_FULL_UUIDS[normalized] != nil { return true }
// Check prefix match (first 8 chars)
let prefix = String(normalized.prefix(8))
if BANNED_PREFIXES[prefix] != nil { return true }
return false
}
/// Get the reason a UUID is banned, or nil if not banned.
static func getBanReason(_ uuid: String) -> String? {
let normalized = uuid.normalizedUUID
// Check full UUID match first
if let reason = BANNED_FULL_UUIDS[normalized] { return reason }
// Check prefix
let prefix = String(normalized.prefix(8))
if let reason = BANNED_PREFIXES[prefix] { return reason }
return nil
}
/// Format a raw UUID string into standard UUID format with dashes.
/// Delegates to String.uuidWithDashes (UUIDFormatting.swift).
static func formatUuid(_ uuid: String) -> String {
uuid.uuidWithDashes
}
}