Exemple #1
0
    def test_key_level(self):
        # Level 3 key
        private_key = ServerIDPrivateKey(
            key_string="sk32Tee5C4fCkbjbN4zc4VPkr9vX4xg8n53XQuWZx6xAKm2cAP7gv")
        assert private_key.key_level == 3
        public_key = private_key.get_public_key()
        assert public_key.key_level == 3
        private_key.key_level = 4
        assert private_key.key_level == 4 and public_key.key_level == 3

        with self.assertRaises(InvalidKeyLevelError):
            private_key.key_level = 5

        with self.assertRaises(InvalidKeyLevelError):
            private_key.key_level = -1
Exemple #2
0
    def test_key_imports_and_exports(self):
        private_bytes = b"\x00" * 32
        private_string = "sk11pz4AG9XgB1eNVkbppYAWsgyg7sftDXqBASsagKJqvVRKYodCU"
        public_string = "id12HQxrj9A4ESYVWqKDx7UC1gJfXpUJDVWt6wHem4fjyNyUKVUx2"

        private_from_bytes = ServerIDPrivateKey(seed_bytes=private_bytes)
        private_from_bytes.key_level = 1
        private_from_string = ServerIDPrivateKey(key_string=private_string)
        assert private_from_bytes.key_bytes == private_bytes
        assert private_from_string.key_bytes == private_bytes
        assert private_from_bytes.to_string() == private_string
        assert private_from_string.to_string() == private_string

        public_from_private = private_from_string.get_public_key()
        public_from_string = ServerIDPublicKey(key_string=public_string)
        assert public_from_private.key_bytes == public_from_string.key_bytes
        assert public_from_private.to_string() == public_string
        assert public_from_string.to_string() == public_string