mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 22:45:20 +00:00
* 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>
35 lines
1.5 KiB
Swift
35 lines
1.5 KiB
Swift
//
|
|
// BinaryProtocolPaddingTests.swift
|
|
// bitchatTests
|
|
//
|
|
// This is free and unencumbered software released into the public domain.
|
|
//
|
|
|
|
import XCTest
|
|
@testable import bitchat
|
|
|
|
final class BinaryProtocolPaddingTests: XCTestCase {
|
|
func test_padded_vs_unpadded_length() throws {
|
|
// Use helper to create a small test packet
|
|
let packet = TestHelpers.createTestPacket()
|
|
guard let padded = BinaryProtocol.encode(packet, padding: true) else { return XCTFail("encode padded") }
|
|
guard let unpadded = BinaryProtocol.encode(packet, padding: false) else { return XCTFail("encode unpadded") }
|
|
XCTAssertGreaterThanOrEqual(padded.count, unpadded.count, "Padded frame should be >= unpadded")
|
|
}
|
|
|
|
func test_decode_padded_and_unpadded_round_trip() throws {
|
|
let packet = TestHelpers.createTestPacket()
|
|
// Padded
|
|
guard let padded = BinaryProtocol.encode(packet, padding: true) else { return XCTFail("encode padded") }
|
|
guard let dec1 = BinaryProtocol.decode(padded) else { return XCTFail("decode padded") }
|
|
XCTAssertEqual(dec1.type, packet.type)
|
|
XCTAssertEqual(dec1.payload, packet.payload)
|
|
// Unpadded
|
|
guard let unpadded = BinaryProtocol.encode(packet, padding: false) else { return XCTFail("encode unpadded") }
|
|
guard let dec2 = BinaryProtocol.decode(unpadded) else { return XCTFail("decode unpadded") }
|
|
XCTAssertEqual(dec2.type, packet.type)
|
|
XCTAssertEqual(dec2.payload, packet.payload)
|
|
}
|
|
}
|
|
|