示例#1
0
def test_oversize_auth_header_packet_encoding():
    auth_header = AuthHeader(
        auth_tag=b"\x00" * NONCE_SIZE,
        auth_scheme_name=AUTH_SCHEME_NAME,
        ephemeral_pubkey=b"\x00" * 32,
        encrypted_auth_response=32,
    )
    header_size = len(rlp.encode(auth_header))
    encrypted_message_size = MAX_PACKET_SIZE - TAG_SIZE - header_size + 1
    encrypted_message = b"\x00" * encrypted_message_size
    packet = AuthHeaderPacket(
        tag=b"\x00" * TAG_SIZE,
        auth_header=auth_header,
        encrypted_message=encrypted_message,
    )
    with pytest.raises(ValidationError):
        packet.to_wire_bytes()
示例#2
0
def test_auth_header_packet_encoding_decoding(tag,
                                              auth_tag,
                                              ephemeral_pubkey,
                                              encrypted_auth_response,
                                              encrypted_message_size):
    auth_header = AuthHeader(
        auth_tag=auth_tag,
        auth_scheme_name=AUTH_SCHEME_NAME,
        ephemeral_pubkey=ephemeral_pubkey,
        encrypted_auth_response=encrypted_auth_response,
    )
    encrypted_message = b"\x00" * encrypted_message_size
    original_packet = AuthHeaderPacket(
        tag=tag,
        auth_header=auth_header,
        encrypted_message=encrypted_message,
    )
    encoded_packet = original_packet.to_wire_bytes()
    decoded_packet = decode_message_packet(encoded_packet)
    assert isinstance(decoded_packet, AuthHeaderPacket)
    assert decoded_packet == original_packet