mirror of
https://github.com/morgan9e/noiseprotocol
synced 2026-04-14 00:14:05 +09:00
* Adding handshake patterns
* Adding token constants for handshake patterns
This commit is contained in:
@@ -1,2 +1,12 @@
|
||||
class Empty:
|
||||
pass
|
||||
|
||||
|
||||
# Handshake pattern tokens
|
||||
TOKEN_E = 'e'
|
||||
TOKEN_S = 's'
|
||||
TOKEN_EE = 'ee'
|
||||
TOKEN_ES = 'es'
|
||||
TOKEN_SE = 'se'
|
||||
TOKEN_SS = 'ss'
|
||||
TOKEN_PSK = 'psk'
|
||||
|
||||
161
noise/patterns.py
Normal file
161
noise/patterns.py
Normal file
@@ -0,0 +1,161 @@
|
||||
from noise.constants import TOKEN_E, TOKEN_S, TOKEN_EE, TOKEN_ES, TOKEN_SE, TOKEN_SS, TOKEN_PSK
|
||||
|
||||
|
||||
class Pattern(object):
|
||||
"""
|
||||
TODO document
|
||||
"""
|
||||
# As per specification, if both parties have pre-messages, the initiator is listed first. To reduce complexity,
|
||||
# pre_messages shall be a list of two lists:
|
||||
# the first for the initiator's pre-messages, the second for the responder
|
||||
pre_messages = [
|
||||
[],
|
||||
[]
|
||||
]
|
||||
# TODO Comment
|
||||
tokens = []
|
||||
|
||||
|
||||
# One-way patterns
|
||||
|
||||
class PatternN(Pattern):
|
||||
pre_messages = [
|
||||
[],
|
||||
[TOKEN_S]
|
||||
]
|
||||
tokens = [
|
||||
[TOKEN_E, TOKEN_ES]
|
||||
]
|
||||
|
||||
|
||||
class PatternK(Pattern):
|
||||
pre_messages = [
|
||||
[TOKEN_S],
|
||||
[TOKEN_S]
|
||||
]
|
||||
tokens = [
|
||||
[TOKEN_E, TOKEN_ES, TOKEN_SS]
|
||||
]
|
||||
|
||||
|
||||
class PatternX(Pattern):
|
||||
pre_messages = [
|
||||
[],
|
||||
[TOKEN_S]
|
||||
]
|
||||
tokens = [
|
||||
[TOKEN_E, TOKEN_ES, TOKEN_S, TOKEN_SS]
|
||||
]
|
||||
|
||||
|
||||
# Interactive patterns
|
||||
|
||||
class PatternNN(Pattern):
|
||||
tokens = [
|
||||
[TOKEN_E],
|
||||
[TOKEN_E, TOKEN_EE]
|
||||
]
|
||||
|
||||
|
||||
class PatternKN(Pattern):
|
||||
pre_messages = [
|
||||
[TOKEN_S],
|
||||
[]
|
||||
]
|
||||
tokens = [
|
||||
[TOKEN_E],
|
||||
[TOKEN_E, TOKEN_EE, TOKEN_SE]
|
||||
]
|
||||
|
||||
|
||||
class PatternNK(Pattern):
|
||||
pre_messages = [
|
||||
[],
|
||||
[TOKEN_S]
|
||||
]
|
||||
tokens = [
|
||||
[TOKEN_E, TOKEN_ES],
|
||||
[TOKEN_E, TOKEN_EE]
|
||||
]
|
||||
|
||||
|
||||
class PatternKK(Pattern):
|
||||
pre_messages = [
|
||||
[TOKEN_S],
|
||||
[TOKEN_S]
|
||||
]
|
||||
tokens = [
|
||||
[TOKEN_E, TOKEN_ES, TOKEN_SS],
|
||||
[TOKEN_E, TOKEN_EE, TOKEN_SE]
|
||||
]
|
||||
|
||||
|
||||
class PatternNX(Pattern):
|
||||
tokens = [
|
||||
[TOKEN_E],
|
||||
[TOKEN_E, TOKEN_EE, TOKEN_S, TOKEN_ES]
|
||||
]
|
||||
|
||||
|
||||
class PatternKX(Pattern):
|
||||
pre_messages = [
|
||||
[TOKEN_S],
|
||||
[]
|
||||
]
|
||||
tokens = [
|
||||
[TOKEN_E],
|
||||
[TOKEN_E, TOKEN_EE, TOKEN_SE, TOKEN_S, TOKEN_ES]
|
||||
]
|
||||
|
||||
|
||||
class PatternXN(Pattern):
|
||||
tokens = [
|
||||
[TOKEN_E],
|
||||
[TOKEN_E, TOKEN_EE],
|
||||
[TOKEN_S, TOKEN_SE]
|
||||
]
|
||||
|
||||
|
||||
class PatternIN(Pattern):
|
||||
tokens = [
|
||||
[TOKEN_E, TOKEN_S],
|
||||
[TOKEN_E, TOKEN_EE, TOKEN_SE]
|
||||
]
|
||||
|
||||
|
||||
class PatternXK(Pattern):
|
||||
pre_messages = [
|
||||
[],
|
||||
[TOKEN_S]
|
||||
]
|
||||
tokens = [
|
||||
[TOKEN_E, TOKEN_ES],
|
||||
[TOKEN_E, TOKEN_EE],
|
||||
[TOKEN_S, TOKEN_SE]
|
||||
]
|
||||
|
||||
|
||||
class PatternIK(Pattern):
|
||||
pre_messages = [
|
||||
[],
|
||||
[TOKEN_S]
|
||||
]
|
||||
tokens = [
|
||||
[TOKEN_E, TOKEN_ES, TOKEN_S, TOKEN_SS],
|
||||
[TOKEN_E, TOKEN_EE, TOKEN_SE]
|
||||
]
|
||||
|
||||
|
||||
class PatternXX(Pattern):
|
||||
tokens = [
|
||||
[TOKEN_E],
|
||||
[TOKEN_E, TOKEN_EE, TOKEN_S, TOKEN_ES],
|
||||
[TOKEN_S, TOKEN_SE]
|
||||
]
|
||||
|
||||
|
||||
class PatternIX(Pattern):
|
||||
tokens = [
|
||||
[TOKEN_E, TOKEN_S],
|
||||
[TOKEN_E, TOKEN_EE, TOKEN_SE, TOKEN_S, TOKEN_ES]
|
||||
]
|
||||
Reference in New Issue
Block a user