# Path: javatools/crypto.py
# def private_key_type(key_file):
#     """
#     Determines type of the private key: RSA, DSA, EC.
# 
#     :param key_file: file path
#     :type key_file: str
#     :return: one of "RSA", "DSA" or "EC"
#     :except CannotFindKeyTypeError
#     """
# 
#     keytypes = (("RSA", RSA), ("DSA", DSA), ("EC", EC))
# 
#     for key, ktype in keytypes:
#         try:
#             ktype.load_key(key_file)
#         except (RSA.RSAError, DSA.DSAError, ValueError):
#             continue
#         else:
#             return key
#     else:
#         raise CannotFindKeyTypeError()
# 
# class CannotFindKeyTypeError(Exception):
#     """
#     Failed to determine the type of the private key.
#     """
# 
#     pass


from unittest import TestCase
from javatools.crypto import private_key_type, CannotFindKeyTypeError
from . import get_data_fn
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, see
# <http://www.gnu.org/licenses/>.


"""
unit tests for cryptography-related functions of python-javatools.

author: Konstantin Shemyak  <konstantin@shemyak.com>
license: LGPL v.3
"""


class CryptoTest(TestCase):

    def test_private_key_type(self):
        rsa_key = get_data_fn("test_crypto/test_private_key_type__key-rsa.pem")

# Path: javatools/crypto.py
# def private_key_type(key_file):
#     """
#     Determines type of the private key: RSA, DSA, EC.
# 
#     :param key_file: file path
#     :type key_file: str
#     :return: one of "RSA", "DSA" or "EC"
#     :except CannotFindKeyTypeError
#     """
# 
#     keytypes = (("RSA", RSA), ("DSA", DSA), ("EC", EC))
# 
#     for key, ktype in keytypes:
#         try:
#             ktype.load_key(key_file)
#         except (RSA.RSAError, DSA.DSAError, ValueError):
#             continue
#         else:
#             return key
#     else:
#         raise CannotFindKeyTypeError()
# 
# class CannotFindKeyTypeError(Exception):
#     """
#     Failed to determine the type of the private key.
#     """
# 
#     pass


# Path: tests/crypto.py
from unittest import TestCase
from javatools.crypto import private_key_type, CannotFindKeyTypeError
from . import get_data_fn

# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, see
# <http://www.gnu.org/licenses/>.


"""
unit tests for cryptography-related functions of python-javatools.

author: Konstantin Shemyak  <konstantin@shemyak.com>
license: LGPL v.3
"""


class CryptoTest(TestCase):

    def test_private_key_type(self):
        rsa_key = get_data_fn("test_crypto/test_private_key_type__key-rsa.pem")

        self.assertEqual(private_key_type(rsa_key), "RSA")