# Path: oppy/crypto/ntor.py
# PROTOID     = "ntor-curve25519-sha256-1"
# T_MAC       = PROTOID + ":mac"
# T_KEY       = PROTOID + ":key_extract"
# T_VERIFY    = PROTOID + ":verify"
# M_EXPAND    = PROTOID + ":key_expand"
# SERVER_STR  = "Server"
# CURVE25519_PUBKEY_LEN   = 32
# DIGEST_LEN              = 20
# KEY_LEN                 = 16
#     AUTH = hdata[CURVE25519_PUBKEY_LEN:CURVE25519_PUBKEY_LEN+DIGEST_LEN]
# class KeyDerivationFailed(Exception):
# class NTorState(namedtuple('NTorState',
#     ('relay_identity', 'relay_ntor_onion_key', 'secret_key', 'public_key'))):
#     def __new__(cls, microdescriptor):
#     def memwipe(self):
# def createOnionSkin(ntorstate):
# def deriveRelayCrypto(ntorstate, cell):
# def _buildSecretInput(ntorstate, relay_pubkey):
# def _buildAuthInput(ntorstate, verify, relay_pubkey):
# def _makeRelayCrypto(secret_input):
# def _EXP(n, p):


import hashlib
import mock
from twisted.trial import unittest
from oppy.crypto import ntor



# NOTE: the test values here are borrowed from tor, specifically the
#       test/test_crypto.c file.


class NTorTest(unittest.TestCase):

    @mock.patch('oppy.crypto.ntor.decodeMicrodescriptorIdentifier',
        return_value='relay_identity')
    @mock.patch('base64.b64decode', return_value='ntor_onion_key')
    @mock.patch('oppy.crypto.ntor.PrivateKey.generate')
    def test_NTorState(self, mock_sk, mock_b64, mock_dmi):
        mock_sk_g = mock.Mock()
        mock_sk_g.public_key = 'pk'
        mock_sk.return_value = mock_sk_g
        mock_sk.public_key = 'pk'
        mock_md = mock.Mock()
        mock_md.ntor_onion_key = 'test'


# Path: oppy/crypto/ntor.py
# PROTOID     = "ntor-curve25519-sha256-1"
# T_MAC       = PROTOID + ":mac"
# T_KEY       = PROTOID + ":key_extract"
# T_VERIFY    = PROTOID + ":verify"
# M_EXPAND    = PROTOID + ":key_expand"
# SERVER_STR  = "Server"
# CURVE25519_PUBKEY_LEN   = 32
# DIGEST_LEN              = 20
# KEY_LEN                 = 16
#     AUTH = hdata[CURVE25519_PUBKEY_LEN:CURVE25519_PUBKEY_LEN+DIGEST_LEN]
# class KeyDerivationFailed(Exception):
# class NTorState(namedtuple('NTorState',
#     ('relay_identity', 'relay_ntor_onion_key', 'secret_key', 'public_key'))):
#     def __new__(cls, microdescriptor):
#     def memwipe(self):
# def createOnionSkin(ntorstate):
# def deriveRelayCrypto(ntorstate, cell):
# def _buildSecretInput(ntorstate, relay_pubkey):
# def _buildAuthInput(ntorstate, verify, relay_pubkey):
# def _makeRelayCrypto(secret_input):
# def _EXP(n, p):


# Path: oppy/tests/unit/crypto/test_ntor.py
import hashlib
import mock
from twisted.trial import unittest
from oppy.crypto import ntor




# NOTE: the test values here are borrowed from tor, specifically the
#       test/test_crypto.c file.


class NTorTest(unittest.TestCase):

    @mock.patch('oppy.crypto.ntor.decodeMicrodescriptorIdentifier',
        return_value='relay_identity')
    @mock.patch('base64.b64decode', return_value='ntor_onion_key')
    @mock.patch('oppy.crypto.ntor.PrivateKey.generate')
    def test_NTorState(self, mock_sk, mock_b64, mock_dmi):
        mock_sk_g = mock.Mock()
        mock_sk_g.public_key = 'pk'
        mock_sk.return_value = mock_sk_g
        mock_sk.public_key = 'pk'
        mock_md = mock.Mock()
        mock_md.ntor_onion_key = 'test'


        n = ntor.NTorState(mock_md)