Repository: Zapix/mtpylon (language: python)

Issue:
RSA Key Manager
- [x] Build protocol for rsa key manager
   - [x] get list of public keys as strings
   - [x] get list of fingerprints for public keys
   - [x] get private/public key to decrypt message by fingerprint
- [x] Implement simple rsa key manager, that takes private, public keys as list of tuples of strings 
   - [x] get list of public keys as strings
   - [x] get list of fingerprints for public keys
   - [x] get private/public key to decrypt message by fingerprint
- [x] Describe RSA Key Manager and its protocol  in documentation


Discussion / hints:

Fix patch:
diff --git a/docs/source/3-rsa-key-manager.rst b/docs/source/3-rsa-key-manager.rst
new file mode 100644
index 0000000..a661b85
--- /dev/null
+++ b/docs/source/3-rsa-key-manager.rst
@@ -0,0 +1,90 @@
+RSA Key Manager
+===============
+
+RSA Key Manager is a object that stores info about rsa public/private keys and
+their fingerprints that will be used in auth key exchanges.
+
+.. _rsa_fingerprint:
+
+**fingerprint** - is a 8 lower bytes of sha1 hash of rsa public key. `n` and `e`
+values represent as tl byte string in big endian format
+
+RSA Key Manager allows to check has we got rsa key pair for fingerprint or not.
+Allows to get that pair if it exists. RSA Key Manager could get list of available
+public rsa keys as python `bytes`. Also It returns list of available fingerprints
+
+
+.. _RsaManager_implementation:
+
+MTPylon has got simple RSA Key Manager implementation example of usage:
+
+.. code-block:: python
+
+  from mtpylon.crypto import RsaManager, KeyPair
+
+  rsa_manager = RsaManager([
+      KeyPair(
+          public='''
+          -----BEGIN RSA PUBLIC KEY-----
+          -----END RSA PUBLIC KEY-----
+          ''',
+          private='''
+          -----BEGIN RSA PRIVATE KEY-----
+          -----END RSA PRIVATE KEY-----
+          '''
+      ),
+      KeyPair(
+          public='''
+          -----BEGIN RSA PUBLIC KEY-----
+          -----END RSA PUBLIC KEY-----
+          ''',
+          private='''
+          -----BEGIN RSA PRIVATE KEY-----
+          -----END RSA PRIVATE KEY-----
+          '''
+      ),
+      KeyPair(
+          public='''
+          -----BEGIN RSA PUBLIC KEY-----
+          -----END RSA PUBLIC KEY-----
+          ''',
+          private='''
+          -----BEGIN RSA PRIVATE KEY-----
+          -----END RSA PRIVATE KEY-----
+          '''
+      ),
+  ])
+
+  5339281804123932840 in rsa_manager  # checks has rsa manager this fingerprint
+
+  rsa_manager[5339281804123932840]  # returns key pair by fingerprint
+
+
+  rsa_manager.public_key_list  # list of public rsa keys
+
+  rsa_manager.fingerprint_list  # list of available rsa keys
+
+
+.. _Rsa_Manager_Protocol:
+
+You could implement and use your custom rsa manager by implementing protocol
+`mtpylon.crypto.rsa_manager.RasManagerProtocol`
+
+
+.. code-block:: python
+
+  class RsaManagerProtocol(Protocol):
+
+      def __contains__(self, item: int) -> bool:  # pragma: no cover
+          ...
+
+      def __getitem__(self, item: int) -> KeyPair:  # pragma: no cover
+          ...
+
+      @property
+      def public_key_list(self) -> List[bytes]:  # pragma: no cover
+          ...
+
+      @property
+      def fingerprint_list(self) -> List[int]:  # pragma: no cover
+          ...
diff --git a/mtpylon/crypto/__init__.py b/mtpylon/crypto/__init__.py
index 40a96af..b1b5c31 100644
--- a/mtpylon/crypto/__init__.py
+++ b/mtpylon/crypto/__init__.py
@@ -1,1 +1,4 @@
 # -*- coding: utf-8 -*-
+from .rsa_manager import RsaManager, KeyPair
+
+__all__ = ['RsaManager', 'KeyPair']


Test patch:
diff --git a/tests/test_crypto/test_rsa_manager.py b/tests/test_crypto/test_rsa_manager.py
index 6405086..75eeda2 100644
--- a/tests/test_crypto/test_rsa_manager.py
+++ b/tests/test_crypto/test_rsa_manager.py
@@ -4,7 +4,7 @@
 import pytest
 from rsa import PublicKey, PrivateKey  # type: ignore
 
-from mtpylon.crypto.rsa_manager import KeyPair, RsaManager
+from mtpylon.crypto import KeyPair, RsaManager
 
 
 @dataclass