File tree 2 files changed +44
-2
lines changed
2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -76,12 +76,12 @@ impl SecretsProvider {
76
76
}
77
77
78
78
/// Retrieve data for the given key, if it exists
79
- pub fn get_data < S : BnStrCompatible > ( & self , key : S ) -> Option < BnString > {
79
+ pub fn get_data < S : BnStrCompatible > ( & self , key : S ) -> BnString {
80
80
let key = key. into_bytes_with_nul ( ) ;
81
81
let result = unsafe {
82
82
BNGetSecretsProviderData ( self . as_raw ( ) , key. as_ref ( ) . as_ptr ( ) as * const ffi:: c_char )
83
83
} ;
84
- ( !result . is_null ( ) ) . then ( || unsafe { BnString :: from_raw ( result) } )
84
+ unsafe { BnString :: from_raw ( result) }
85
85
}
86
86
87
87
/// Store data with the given key
Original file line number Diff line number Diff line change
1
+ use binaryninja:: headless:: Session ;
2
+ use binaryninja:: secretsprovider:: { SecretsProvider , SecretsProviderCallback } ;
3
+ use rstest:: * ;
4
+
5
+ #[ fixture]
6
+ fn session ( ) -> Session {
7
+ Session :: new ( ) . expect ( "Failed to initialize session" )
8
+ }
9
+
10
+ #[ rstest]
11
+ fn list_secrets_provider ( _session : Session ) {
12
+ let providers = SecretsProvider :: all ( ) ;
13
+ for _provider in & providers { }
14
+ }
15
+
16
+ struct MySecretsProvider { }
17
+
18
+ impl SecretsProviderCallback for MySecretsProvider {
19
+ fn has_data ( & mut self , key : & str ) -> bool {
20
+ key == "my_key"
21
+ }
22
+
23
+ fn get_data ( & mut self , key : & str ) -> String {
24
+ if key == "my_key" { "my_value" } else { "" } . to_string ( )
25
+ }
26
+
27
+ fn store_data ( & mut self , _key : & str , _data : & str ) -> bool {
28
+ false
29
+ }
30
+
31
+ fn delete_data ( & mut self , _key : & str ) -> bool {
32
+ false
33
+ }
34
+ }
35
+
36
+ #[ rstest]
37
+ fn custom_secrets_provider ( _session : Session ) {
38
+ let my_provider = SecretsProvider :: new ( "MySecretsProvider" , MySecretsProvider { } ) ;
39
+ assert ! ( my_provider. has_data( "my_key" ) ) ;
40
+ assert ! ( !my_provider. has_data( "not_my_key" ) ) ;
41
+ assert_eq ! ( my_provider. get_data( "my_key" ) . as_str( ) , "my_value" ) ;
42
+ }
You can’t perform that action at this time.
0 commit comments