diff options
| author | Mason Reed <mason@vector35.com> | 2025-10-29 16:41:12 -0700 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-10-29 16:41:12 -0700 |
| commit | 59077d3400b57a811c6860b9ee7f5cf4ded084f9 (patch) | |
| tree | e5c4de0a5308fbf08ee448cc827278da5b0bfffe /rust | |
| parent | fd6f8a24826636588b2069ab7dabd1e72e4f6a48 (diff) | |
[Rust] Update repository API following updated Core API's
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/src/repository/manager.rs | 19 | ||||
| -rw-r--r-- | rust/tests/repository.rs | 20 |
2 files changed, 14 insertions, 25 deletions
diff --git a/rust/src/repository/manager.rs b/rust/src/repository/manager.rs index f65adc43..93d47660 100644 --- a/rust/src/repository/manager.rs +++ b/rust/src/repository/manager.rs @@ -11,21 +11,16 @@ use std::ptr::NonNull; /// Keeps track of all the repositories and keeps the `enabled_plugins.json` /// file coherent with the plugins that are installed/uninstalled enabled/disabled -pub struct RepositoryManager { -} +pub struct RepositoryManager; impl RepositoryManager { - pub fn new() -> Self { - Self {} - } - /// Check for updates for all managed [`Repository`] objects - pub fn check_for_updates(&self) -> bool { + pub fn check_for_updates() -> bool { unsafe { BNRepositoryManagerCheckForUpdates() } } /// List of [`Repository`] objects being managed - pub fn repositories(&self) -> Array<Repository> { + pub fn repositories() -> Array<Repository> { let mut count = 0; let result = unsafe { BNRepositoryManagerGetRepositories(&mut count) }; @@ -44,7 +39,7 @@ impl RepositoryManager { /// * `repository_path` - path to where the repository will be stored on disk locally /// /// Returns true if the repository was successfully added, false otherwise. - pub fn add_repository(&self, url: &str, repository_path: &Path) -> bool { + pub fn add_repository(url: &str, repository_path: &Path) -> bool { let url = url.to_cstr(); let repo_path = repository_path.to_cstr(); unsafe { @@ -52,7 +47,7 @@ impl RepositoryManager { } } - pub fn repository_by_path(&self, path: &Path) -> Option<Repository> { + pub fn repository_by_path(path: &Path) -> Option<Repository> { let path = path.to_cstr(); let result = unsafe { BNRepositoryGetRepositoryByPath(path.as_ptr()) }; @@ -60,7 +55,7 @@ impl RepositoryManager { } /// Gets the default [`Repository`] - pub fn default_repository(&self) -> Ref<Repository> { + pub fn default_repository() -> Ref<Repository> { let result = unsafe { BNRepositoryManagerGetDefaultRepository() }; assert!(!result.is_null()); unsafe { Repository::ref_from_raw(NonNull::new(result).unwrap()) } @@ -70,7 +65,7 @@ impl RepositoryManager { impl Debug for RepositoryManager { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("RepositoryManager") - .field("repositories", &self.repositories().to_vec()) + .field("repositories", &RepositoryManager::repositories().to_vec()) .finish() } } diff --git a/rust/tests/repository.rs b/rust/tests/repository.rs index ac861b2c..82e0e45d 100644 --- a/rust/tests/repository.rs +++ b/rust/tests/repository.rs @@ -4,22 +4,16 @@ use binaryninja::repository::RepositoryManager; #[test] fn test_list() { let _session = Session::new().expect("Failed to initialize session"); - let manager = RepositoryManager::default(); - let repositories = manager.repositories(); + let repositories = RepositoryManager::repositories(); for repository in &repositories { let repo_path = repository.path(); - let repository_by_path = manager.repository_by_path(&repo_path).unwrap(); + let repository_by_path = RepositoryManager::repository_by_path(&repo_path).unwrap(); assert_eq!(repository.url(), repository_by_path.url()); - } - let repository = manager.default_repository(); - let _full_path = repository.full_path(); - let _path = repository.path(); - let _url = repository.url(); - let plugins = repository.plugins(); - for plugin in &plugins { - let plugin_path = plugin.path(); - let plugin_by_path = repository.plugin_by_path(&plugin_path).unwrap(); - assert_eq!(plugin.package_url(), plugin_by_path.package_url()); + for plugin in &repository.plugins() { + let plugin_path = plugin.path(); + let plugin_by_path = repository.plugin_by_path(&plugin_path).unwrap(); + assert_eq!(plugin.package_url(), plugin_by_path.package_url()); + } } } |
