Code style
The conventions for each language in the repository and the security rules that apply to all code. “Enforced by CI” means a pull request fails without it. Everything else is checked in review.
All code
| Rule | Detail |
|---|---|
| Licence | GPL-3.0-or-later. A new source file starts with the line SPDX-License-Identifier: GPL-3.0-or-later in the comment syntax of the language, as the existing ones do. |
| Third-party code | Only under licences compatible with GPL-3.0, credited in NOTICE. A file that follows a technique of another project says so in its header. |
| Reverse engineering | No code or knowledge obtained by reverse engineering proprietary software. See About the licence and distribution. |
| Spelling | British, in documentation and in user interface text: licence (noun), set-up (noun), colour. |
| Protocol constants | Ports, timeouts and limits are defined in one place per side and match the wire protocol reference. |
Logging
Never log message contents, keys, nonces or short authentication string
(SAS) values above the trace level. This covers notification text, SMS and
MMS bodies, clipboard text, contact data, pairing secrets and tokens.
| Side | Facility | Notes |
|---|---|---|
| Rust | tracing (trace!, debug!, info!, warn!, error!) | The level is set with RUST_LOG. The packaged service runs with RUST_LOG=info. |
| Android app | TLog (android/app/src/main/java/org/tether/android/core/TLog.kt): TLog.d, TLog.i, TLog.w, TLog.e with a short tag | Tags appear in logcat with the prefix Tether.. TLog.d is dropped in release builds. |
| Shell helper | ShellLog (android/app/src/main/java/org/tether/shell/ShellLog.kt) | Writes tether-helper: <I|W|E> text to stderr, which the daemon reads. |
Log identifiers in shortened form where the full value is not needed (the core logs the first eight characters of a device id).
Rust (desktop/)
Toolchain and build
| Item | Value | Where |
|---|---|---|
| Edition | 2021 | desktop/Cargo.toml, [workspace.package] |
| Minimum supported Rust version | 1.85 (rust-version) | desktop/Cargo.toml |
| Toolchain in CI | latest stable (dtolnay/rust-toolchain@stable) | .github/workflows/desktop.yml |
| Nightly features | not used | |
| Dependency versions | declared once in [workspace.dependencies], used in crates as name.workspace = true | desktop/Cargo.toml |
| Release profile | lto = "thin", codegen-units = 1, strip = true | desktop/Cargo.toml |
| Protobuf code generation | protox and prost-build in tether-proto/build.rs, without protoc |
There is no rust-toolchain.toml, rustfmt.toml or clippy.toml, and no
[lints] table in any Cargo.toml. Formatting and lints are the tools’
defaults.
Formatting and lints
| Rule | Enforced by CI |
|---|---|
rustfmt defaults: cargo fmt --all --check passes | yes |
cargo clippy --workspace --all-targets -- -D warnings passes | yes |
No compiler warnings (RUSTFLAGS="-D warnings") | yes |
Fix a lint in preference to #[allow]. An #[allow] carries a comment that says why. | no |
#![forbid(unsafe_code)] in tether-core, tetherd and tether-cli | by the compiler |
tether-proto contains only generated code and sets
#![allow(clippy::all)]. tether-gtk does not forbid unsafe. A new Rust
release can add clippy lints that an older local toolchain does not report.
Conventions
| Topic | Rule |
|---|---|
| Errors | thiserror in libraries, anyhow in binaries. |
unwrap() | Not outside tests, except where a comment proves that it cannot fail. |
| Async | tokio everywhere. No blocking calls on the runtime. Use spawn_blocking for bursts of file I/O and for key generation. |
| Documentation | Every public item in tether-core has a doc comment. Modules start with a //! comment that says what they own and names the ADR or reference section they implement. |
| Tests | Unit tests next to the code (#[cfg(test)] mod tests), integration tests in the crate’s tests/ directory. |
| Test vectors | Changes to pairing and framing keep the shared test vectors of the protocol reference green. |
| Test fixtures | Fixtures for external tools (pw-dump, adb output) come from a real capture, not from an assumed shape. |
| External commands | Parse the output of adb. Its exit code is 0 on some failures (Platform findings). |
Kotlin (android/)
Toolchain and build
| Item | Value | Where |
|---|---|---|
| Kotlin | 2.1.21 | android/gradle/libs.versions.toml |
| Android Gradle Plugin | 8.10.1 | android/gradle/libs.versions.toml |
| Gradle | 8.11.1, through the wrapper | android/gradle/wrapper/gradle-wrapper.properties |
| JDK in CI | 21 (Temurin) | .github/workflows/android.yml |
| JVM target | 17 | android/app/build.gradle.kts |
compileSdk / targetSdk / minSdk | 35 / 35 / 34 | android/app/build.gradle.kts |
| Protobuf code generation | Wire 5.3.11, plain Kotlin classes in org.tether.proto.v1 | android/app/build.gradle.kts |
| Dependency versions | version catalogue | android/gradle/libs.versions.toml |
| Release builds | R8 minification and resource shrinking | android/app/proguard-rules.pro |
Formatting and lints
| Rule | Enforced by CI |
|---|---|
Official Kotlin style (kotlin.code.style=official in android/gradle.properties) | no |
| ktlint-compatible formatting: four-space indent, trailing commas in multi-line declarations, no wildcard imports | no |
| Soft limit of 120 columns | no |
Unit tests pass and the debug build assembles (:app:testDebugUnitTest :app:assembleDebug) | yes |
There is no ktlint or detekt Gradle task and no .editorconfig. Run
ktlint yourself if you have it installed. Android lint is configured not to
fail the build (abortOnError = false).
Conventions
| Topic | Rule |
|---|---|
| User interface | Jetpack Compose with Material 3 only. Composables are stateless, with state hoisted out of them. Screens read StateFlows of the singletons in AppGraph. |
| Concurrency | Coroutines. Every coroutine runs in a scope that is passed in. No GlobalScope. |
| Dependency injection | Manual: constructor parameters and the AppGraph object. Adding Hilt or Dagger needs an ADR. |
| Dependencies | No Google Play Services and no Firebase (ADR-0008). |
| Permissions | Every new permission has a comment in AndroidManifest.xml that says why it is needed. If the user sees a prompt, it is described in Grant Android permissions. |
| Components | A new exported activity, service or receiver is explained in the pull request: who can call it and what it can do. |
| Capabilities | A capability is announced only while its permission is held (transport/Protocol.kt). |
| Tests | JUnit 4 unit tests under android/app/src/test/, with the shared vectors from the protocol reference. |
| Shell helper | Code in org.tether.shell uses no resources, no AndroidX and no JNI. |
Protobuf (proto/)
| Rule | Detail |
|---|---|
| Syntax and package | proto3, package tether.v1, option java_package = "org.tether.proto.v1", option java_multiple_files = true. |
| Field numbers | Never reuse or renumber a field. Reserve the number of a removed field. |
Envelope | A new message goes into the oneof msg in the block of its feature area, or in the next free block for a new area. The blocks are listed in Add or change a protocol feature. |
| Enums | The zero value is <PREFIX>_UNSPECIFIED. Values carry the enum’s name as prefix (DND_FILTER_PRIORITY). |
| Names | Messages in UpperCamelCase, fields in snake_case. |
| Comments | State the direction (Desktop -> phone) and the semantics above each message, and units in field comments (ts_ms). |
| Documentation | Behaviour is described in the wire protocol reference in the same pull request. |
| Negotiation | New frames are enabled by a capability in Hello.capabilities. |
Shell and packaging (desktop/packaging/)
| Rule | Detail |
|---|---|
| Shell | POSIX sh (#!/bin/sh), no bash features. |
| Static analysis | shellcheck-clean. CI does not run shellcheck; run it yourself. |
| Error handling | set -eu in build scripts (build-deb.sh). The maintainer scripts use set -e and guard every step with ` |
| Maintainer scripts | postinst, prerm and postrm must never fail the installation or removal of the package: a missing tool or a failed step is skipped. |
| Root helpers | A script that runs as root takes a fixed set of words and no free-form arguments, and sets its own PATH (webcam/tether-webcam-setup). |
| Install-time side effects | The package does not load kernel modules or copy files into a user’s configuration at install time (ADR-0019). |
| Package check | lintian runs in the release workflow for information and does not fail the build. |
The rules for documentation are in Write documentation.
Hardening checklist
Every change is reviewed against this list from
SECURITY.md.
- Validate every length and index that comes off the wire. Frames are capped at 4 MiB and inline blobs at 256 KiB.
- Treat
Hellofrom an unpaired peer as untrusted input. Never show itsnamein user interface or notification markup without escaping. The TLS handshake andHellocan be reached by anyone on the local network before pairing. - Use logging levels so that message bodies, nonces and SAS digits never
appear above
trace. - A new permission, exported Android component or D-Bus method gets a note in the pull request about who can call it and what it can do.
Further rules that follow from the threat model in the same file:
- Identifiers from the peer that end up in file names must be plain tokens
(
Protocol.isValidRefIdon Android). Received files must not escape their directory or overwrite other files. - Secrets do not go into process arguments, which other processes can read. The shell helper receives its token on stdin (ADR-0016).
- The daemon runs as the logged-in user, never as root. The one privileged action goes through polkit with a fixed script.
- No telemetry and no connection to a server that the user did not configure.
The reasoning behind these rules is in the security model.