diff --git a/lean/commands/library/add.py b/lean/commands/library/add.py index 7e9dd280..71ecaf21 100644 --- a/lean/commands/library/add.py +++ b/lean/commands/library/add.py @@ -303,6 +303,19 @@ def add(project: Path, name: str, version: Optional[str], no_local: bool) -> Non library_dir = Path(name).expanduser().resolve() if library_manager.is_lean_library(library_dir): + # check encryption conditions + if project_config.get('encrypted', False) and project_config.get('encryption-key-path', None): + library_project_config = container.project_config_manager.get_project_config(library_dir) + is_library_encrypted = library_project_config.get('encrypted', False) + library_encryption_key_path = library_project_config.get('encryption-key-path', None) + if library_encryption_key_path: + library_encryption_key_path = Path(library_encryption_key_path) + project_encryption_key_path = project_config.get('encryption-key-path', None) + if project_encryption_key_path: + project_encryption_key_path = Path(project_encryption_key_path) + if is_library_encrypted and library_encryption_key_path != project_encryption_key_path: + raise RuntimeError(f"Library is encrypted with a different key {library_encryption_key_path}. " + f"Please use the same key as project {project_encryption_key_path}.") logger.info(f"Adding Lean CLI library {library_dir} to project {project}") if project_language == "CSharp": library_manager.add_lean_library_to_csharp_project(project, library_dir, no_local)