mirror of
https://github.com/morgan9e/noiseprotocol
synced 2026-04-14 00:14:05 +09:00
* Created NoiseBackend class serving as a base for backends
* Refactored NoiseProtocol name parsing
* Refactored existing spec-defined functions into abstract classes.
Implementing classes are connecting crypto primitives to expected
interfaces.
* Refactored existing usage of Cryptography as source of crypto into
"default" backend (along with in-house implementation of X448).
* Provisioned "experimental" backend, it will contain e.g. non-default
crypto algorithms
* Backend can be chosen while creating NoiseConnection, though by
default, the Cryptography backend ("default") is used
Closes #7
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
from noise.backends.default import noise_backend
|
|
from noise.noise_protocol import NoiseProtocol
|
|
from noise.state import CipherState, SymmetricState
|
|
|
|
|
|
class TestRevision33Compatibility(object):
|
|
def test_noise_protocol_accepts_slash(self):
|
|
class FakeSHA3_256():
|
|
fn = None
|
|
|
|
noise_name = b"Noise_NN_25519_AESGCM_SHA3/256"
|
|
|
|
modified_backend = noise_backend
|
|
modified_backend.hashes['SHA3/256'] = FakeSHA3_256 # Add callable to hash functions mapping
|
|
modified_class = NoiseProtocol
|
|
modified_class(noise_name, modified_backend)
|
|
|
|
def test_cipher_state_set_nonce(self):
|
|
noise_protocol = NoiseProtocol(b"Noise_NN_25519_AESGCM_SHA256", backend=noise_backend)
|
|
cipher_state = CipherState(noise_protocol)
|
|
cipher_state.initialize_key(b'\x00'*32)
|
|
assert cipher_state.n == 0
|
|
cipher_state.set_nonce(42)
|
|
assert cipher_state.n == 42
|
|
|
|
def test_symmetric_state_get_handshake_hash(self):
|
|
symmetric_state = SymmetricState()
|
|
symmetric_state.h = 42
|
|
assert symmetric_state.get_handshake_hash() == 42
|