| | 1 | | using System.Diagnostics; |
| | 2 | |
|
| | 3 | | namespace NLightning.Infrastructure.Transport.Handshake.MessagePatterns; |
| | 4 | |
|
| | 5 | | using Enums; |
| | 6 | |
|
| | 7 | | /// <summary> |
| | 8 | | /// A <see href="https://noiseprotocol.org/noise.html#handshake-patterns">handshake pattern</see> |
| | 9 | | /// consists of a pre-message pattern for the initiator, a pre-message pattern for the responder, |
| | 10 | | /// and a sequence of message patterns for the actual handshake messages. |
| | 11 | | /// </summary> |
| | 12 | | internal sealed class HandshakePattern |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// Gets the pre-message pattern for the initiator. |
| | 16 | | /// </summary> |
| 96 | 17 | | public PreMessagePattern Initiator { get; } |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// Gets the pre-message pattern for the responder. |
| | 21 | | /// </summary> |
| 96 | 22 | | public PreMessagePattern Responder { get; } |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Gets the sequence of message patterns for the handshake messages. |
| | 26 | | /// </summary> |
| 96 | 27 | | public IEnumerable<MessagePattern> Patterns { get; } |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// XK(): |
| | 31 | | /// <para>- ← s</para> |
| | 32 | | /// <para>- ...</para> |
| | 33 | | /// <para>- → e, es</para> |
| | 34 | | /// <para>- ← e, ee</para> |
| | 35 | | /// <para>- → s, se</para> |
| | 36 | | /// </summary> |
| 4 | 37 | | public static readonly HandshakePattern XK = new( |
| 4 | 38 | | PreMessagePattern.EMPTY, |
| 4 | 39 | | PreMessagePattern.S, |
| 4 | 40 | | new MessagePattern(Token.E, Token.ES), |
| 4 | 41 | | new MessagePattern(Token.E, Token.EE), |
| 4 | 42 | | new MessagePattern(Token.S, Token.SE) |
| 4 | 43 | | ); |
| | 44 | |
|
| 4 | 45 | | internal HandshakePattern(PreMessagePattern initiator, PreMessagePattern responder, params MessagePattern[] patterns |
| | 46 | | { |
| | 47 | | Debug.Assert(initiator != null); |
| | 48 | | Debug.Assert(responder != null); |
| | 49 | | Debug.Assert(patterns != null); |
| | 50 | | Debug.Assert(patterns.Length > 0); |
| | 51 | |
|
| 4 | 52 | | Initiator = initiator; |
| 4 | 53 | | Responder = responder; |
| 4 | 54 | | Patterns = patterns; |
| 4 | 55 | | } |
| | 56 | | } |