Skip to content

Conversation

tcheeric
Copy link
Owner

Summary

  • reuse a single SecureRandom instance in NostrUtil
  • add tests for createRandomByteArray

Testing

  • gradle clean test (fails: build halted mid-way)
  • ./mvnw -q test (fails: Network is unreachable)

https://chatgpt.com/codex/tasks/task_b_6887ff2d10a08331823c4492511e8d81

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

The PR improves NostrUtil by reusing a single SecureRandom instance instead of creating new instances for each random byte array generation, and adds comprehensive tests for the createRandomByteArray method.

  • Replace per-call SecureRandom instantiation with a shared static instance
  • Add unit tests to verify random byte array length and uniqueness properties

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
nostr-java-util/src/main/java/nostr/util/NostrUtil.java Introduces shared SecureRandom instance to avoid repeated instantiation overhead
nostr-java-util/src/test/java/nostr/util/NostrUtilRandomTest.java Adds new test class with coverage for createRandomByteArray functionality
Comments suppressed due to low confidence (1)

nostr-java-util/src/test/java/nostr/util/NostrUtilRandomTest.java:23

  • This test could theoretically fail due to the probabilistic nature of random generation. While extremely unlikely for 16-byte arrays, consider adding a retry mechanism or testing with smaller arrays multiple times to make the test more robust.
        assertFalse(Arrays.equals(data1, data2), "Consecutive random arrays should differ");

@tcheeric tcheeric merged commit 1df5dd5 into develop Jul 29, 2025
@tcheeric tcheeric deleted the codex/modify-nostrutil-for-securerandom-usage branch July 29, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant