Refactor/repo hardening 01 (#462)

* BinaryProtocol: add optional padding control; BitchatPacket API for padded/unpadded bytes; BLEService: use unpadded encoding and remove ad-hoc unpadding on BLE writes

* BLEService: balance BLE padding — pad Noise handshake/encrypted frames; leave public/announce/leave unpadded; keep fragmentation consistent with chosen padding

* BLEService: replace Timer with DispatchSourceTimer on bleQueue; NostrTransport: cache placeholder NoiseEncryptionService to avoid reallocation

* Unify peerID validation: InputValidator handles 16-hex, 64-hex, or alnum-/_; NoiseSecurityValidator now delegates to InputValidator

* UI: use standard green for geohash toolbar badge and count (less bright in light mode)

* UI: standardize geohash sheet green to app standard (dark: system green, light: darker green) for buttons and checkmark

* Docs: align BinaryProtocol compression docs to zlib; Logs: reduce NostrTransport DELIVERED ack logs to debug to cut noise

* Tests: add InputValidator peerID coverage and BinaryProtocol padding round-trip/length tests

* Project: ensure Xcode project reflects new tests (references added)

---------

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
jack
2025-08-20 13:29:53 +02:00
committed by GitHub
co-authored by jack
parent bdbcbb5d2b
commit 3074fa0fcb
11 changed files with 174 additions and 51 deletions
+10 -7
View File
@@ -45,7 +45,7 @@
///
/// ## Compression Strategy
/// - Automatic compression for payloads > 256 bytes
/// - LZ4 algorithm for speed over ratio
/// - zlib compression for broad compatibility on Apple platforms
/// - Original size stored for decompression
/// - Flag bit indicates compressed payload
///
@@ -117,7 +117,7 @@ struct BinaryProtocol {
}
// Encode BitchatPacket to binary format
static func encode(_ packet: BitchatPacket) -> Data? {
static func encode(_ packet: BitchatPacket, padding: Bool = true) -> Data? {
var data = Data()
@@ -200,11 +200,14 @@ struct BinaryProtocol {
// Apply padding to standard block sizes for traffic analysis resistance
let optimalSize = MessagePadding.optimalBlockSize(for: data.count)
let paddedData = MessagePadding.pad(data, toSize: optimalSize)
return paddedData
if padding {
let optimalSize = MessagePadding.optimalBlockSize(for: data.count)
let paddedData = MessagePadding.pad(data, toSize: optimalSize)
return paddedData
} else {
// Caller explicitly requested no padding (e.g., BLE write path)
return data
}
}
// Decode binary data to BitchatPacket
+6 -1
View File
@@ -232,8 +232,13 @@ struct BitchatPacket: Codable {
BinaryProtocol.encode(self)
}
func toBinaryData(padding: Bool = true) -> Data? {
BinaryProtocol.encode(self, padding: padding)
}
// Backward-compatible helper (defaults to padded encoding)
func toBinaryData() -> Data? {
BinaryProtocol.encode(self)
toBinaryData(padding: true)
}
/// Create binary representation for signing (without signature and TTL fields)