Skip to content

P5a: idiomatic-Crystal cleanups - #28

Merged
stakach merged 1 commit into
spider-gazelle:masterfrom
n-rodriguez:feat/p5-idiomatic
Jul 13, 2026
Merged

P5a: idiomatic-Crystal cleanups#28
stakach merged 1 commit into
spider-gazelle:masterfrom
n-rodriguez:feat/p5-idiomatic

Conversation

@n-rodriguez

Copy link
Copy Markdown
Contributor

Most of the P5 (idiomatic Crystal) group from the audit (#7). Kept as a single commit — the changes are entangled at the file level (e.g. session.cr / v3/session.cr each carry three independent idiomatic changes), so a clean one-commit-per-item split would need heavy per-hunk surgery for little reviewer benefit.

Changes

  • VarBind#method_missingforward_missing_to value — the old splat macro swallowed blocks and defeated type-checking.
  • Extract VarBind.from_value(oid, value) — deduplicates the set case that was copied verbatim into Session and V3::Session.
  • REQUEST_ID_RANGE constant — replaces the rand(2147483647) magic literal repeated across pdu / message / session / v3 (× many).
  • Name the magic numbersMAX_MESSAGE_SIZE (65507), PASSKEY_EXPANSION_SIZE / PASSKEY_CHUNK_SIZE.
  • Typed exceptions instead of raise "string"SNMP::Error / SNMP::ParseError in session.cr and the AES/DES salt checks.
  • DeprecationsTime.monotonicTime.instant (timeliness is now a nilable Time::Instant; the RFC 3414 window semantics are unchanged, verified by timeliness_spec); UDPSocket#read_timeout now takes a Time::Span.

Enum.from_value? (nilable decoding) was already handled by the strict-parse work (#13). The Trap class-hierarchy smell is intentionally deferred (see #7).

Tests

Behaviour-preserving refactors, guarded by the full suite (incl. the RFC 3414 passkey vectors and the SEC-3 timeliness_spec). No new deprecation warnings. Deterministic 82/82, multi-threaded 82/82, legacy 3/3, ameba clean, format clean.

Tracked in #7.

🤖 Generated with Claude Code

A batch of pre-1.0 idiomatic fixes (kept as one commit — the changes are
entangled across session.cr / v3/session.cr):

- varbind: forward_missing_to value (drop the method_missing splat that swallowed
  blocks and defeated type-checking)
- varbind: extract VarBind.from_value(oid, value), deduplicating the set case
  shared by Session and V3::Session
- snmp: REQUEST_ID_RANGE constant replacing the repeated rand(2147483647) literal
- v3/message, v3/security: name the magic numbers (MAX_MESSAGE_SIZE,
  PASSKEY_EXPANSION_SIZE/PASSKEY_CHUNK_SIZE)
- session, v3/security/{aes,des}: raise typed SNMP::Error/ParseError, not strings
- v3/session: replace deprecated Time.monotonic with Time.instant (timeliness
  now a nilable Time::Instant; RFC 3414 window semantics unchanged)
- client, snmp_spec: UDPSocket#read_timeout takes a Time::Span (deprecation)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@stakach
stakach merged commit fbefbbb into spider-gazelle:master Jul 13, 2026
6 checks passed
@n-rodriguez
n-rodriguez deleted the feat/p5-idiomatic branch July 21, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants