Skip to content

Commit

Permalink
On second thought: reduce the visibility of HandshakePattern entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
jchambers committed Mar 2, 2024
1 parent bbceeeb commit 49d6c0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
17 changes: 0 additions & 17 deletions src/example/java/HandshakePatternExample.java

This file was deleted.

24 changes: 10 additions & 14 deletions src/main/java/com/eatthepath/noise/HandshakePattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
import java.util.stream.Stream;

/**
* <p>A handshake pattern specifies the sequential exchange of messages that comprise a Noise handshake. Callers
* generally do not need to interact directly with handshake patterns.</p>
*
* <p>Handshake patterns may be retrieved by name. For example:</p>
*
* {@snippet file="HandshakePatternExample.java" region="get-instance"}
* A handshake pattern specifies the sequential exchange of messages that comprise a Noise handshake. Callers generally
* do not need to interact directly with handshake patterns.
*/
public class HandshakePattern {
class HandshakePattern {

private final String name;

Expand Down Expand Up @@ -388,7 +384,7 @@ static Token fromString(final String string) {
*
* @return the name of this handshake pattern
*/
public String getName() {
String getName() {
return name;
}

Expand All @@ -409,7 +405,7 @@ MessagePattern[] getHandshakeMessagePatterns() {
*
* @throws NoSuchPatternException if the given cannot be resolved to a Noise handshake pattern
*/
public static HandshakePattern getInstance(final String name) throws NoSuchPatternException {
static HandshakePattern getInstance(final String name) throws NoSuchPatternException {
if (FUNDAMENTAL_PATTERNS_BY_NAME.containsKey(name)) {
return FUNDAMENTAL_PATTERNS_BY_NAME.get(name);
}
Expand Down Expand Up @@ -599,7 +595,7 @@ private static MessagePattern messagePatternFromString(final String messagePatte
*
* @see <a href="https://noiseprotocol.org/noise.html#one-way-handshake-patterns">The Noise Protocol Framework - One-way handshake patterns</a>
*/
public boolean isOneWayPattern() {
boolean isOneWayPattern() {
return Arrays.stream(getHandshakeMessagePatterns())
.allMatch(messagePattern -> messagePattern.sender() == NoiseHandshake.Role.INITIATOR);
}
Expand All @@ -617,7 +613,7 @@ boolean isFallbackPattern() {
* @return {@code true} if the given party must provide a local static key pair prior to beginning the handshake or
* {@code false} otherwise
*/
public boolean requiresLocalStaticKeyPair(final NoiseHandshake.Role role) {
boolean requiresLocalStaticKeyPair(final NoiseHandshake.Role role) {
// The given role needs a local static key pair if any pre-handshake message or handshake message involves that role
// sending a static key to the other party
return Stream.concat(Arrays.stream(getPreMessagePatterns()), Arrays.stream(getHandshakeMessagePatterns()))
Expand All @@ -635,7 +631,7 @@ public boolean requiresLocalStaticKeyPair(final NoiseHandshake.Role role) {
* @return {@code true} if the given party must provide a remote ephemeral public key prior to beginning the handshake
* or {@code false} otherwise
*/
public boolean requiresRemoteEphemeralPublicKey(final NoiseHandshake.Role role) {
boolean requiresRemoteEphemeralPublicKey(final NoiseHandshake.Role role) {
// The given role needs a remote static key pair if the handshake pattern involves that role receiving an ephemeral
// key from the other party in a pre-handshake message
return Arrays.stream(getPreMessagePatterns())
Expand All @@ -653,7 +649,7 @@ public boolean requiresRemoteEphemeralPublicKey(final NoiseHandshake.Role role)
* @return {@code true} if the given party must provide a remote static public key prior to beginning the handshake or
* {@code false} otherwise
*/
public boolean requiresRemoteStaticPublicKey(final NoiseHandshake.Role role) {
boolean requiresRemoteStaticPublicKey(final NoiseHandshake.Role role) {
// The given role needs a remote static key pair if the handshake pattern involves that role receiving a static key
// from the other party in a pre-handshake message
return Arrays.stream(getPreMessagePatterns())
Expand All @@ -673,7 +669,7 @@ boolean isPreSharedKeyHandshake() {
*
* @return the number of pre-shared keys either party in this handshake must provide prior to beginning the handshake
*/
public int getRequiredPreSharedKeyCount() {
int getRequiredPreSharedKeyCount() {
return Math.toIntExact(Arrays.stream(getHandshakeMessagePatterns())
.flatMap(messagePattern -> Arrays.stream(messagePattern.tokens()))
.filter(token -> token == Token.PSK)
Expand Down

0 comments on commit 49d6c0d

Please sign in to comment.