Skip to content

Commit cc210a1

Browse files
committed
Restored get_attribute for creddef and updated python wrapper
Signed-off-by: Gavin Jaeger-Freeborn <[email protected]>
1 parent 40528ec commit cc210a1

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

src/ffi/cred_def.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::str::FromStr;
22

3-
use ffi_support::FfiStr;
3+
use ffi_support::{rust_string_to_c, FfiStr};
44

55
use super::error::{catch_error, ErrorCode};
66
use super::object::ObjectHandle;
@@ -12,6 +12,31 @@ use crate::services::{
1212
CredentialKeyCorrectnessProof as KeyCorrectnessProof, SignatureType,
1313
},
1414
};
15+
use std::os::raw::c_char;
16+
17+
#[no_mangle]
18+
pub extern "C" fn anoncreds_credential_definition_get_attribute(
19+
handle: ObjectHandle,
20+
name: FfiStr,
21+
result_p: *mut *const c_char,
22+
) -> ErrorCode {
23+
catch_error(|| {
24+
check_useful_c_ptr!(result_p);
25+
let cred_def = handle.load()?;
26+
let cred_def = cred_def.cast_ref::<CredentialDefinition>()?;
27+
let val = match name.as_opt_str().unwrap_or_default() {
28+
"schema_id" => cred_def.schema_id.to_string().to_owned(),
29+
"tag" => cred_def.tag.to_string().to_owned(),
30+
"issuer_id" => cred_def.issuer_id.to_string().to_owned(),
31+
"signature_type" => match cred_def.signature_type {
32+
SignatureType::CL => "CL".to_string()
33+
}
34+
s => return Err(err_msg!("Unsupported attribute: {}", s)),
35+
};
36+
unsafe { *result_p = rust_string_to_c(val) };
37+
Ok(())
38+
})
39+
}
1540

1641
#[no_mangle]
1742
pub extern "C" fn anoncreds_create_credential_definition(

wrappers/python/anoncreds/types.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,46 @@ def load(cls, value: Union[dict, str, bytes, memoryview]) -> "CredentialDefiniti
4040
)
4141

4242
@property
43-
def id(self) -> str:
43+
def schema_id(self) -> str:
4444
return str(
4545
bindings._object_get_attribute(
4646
self.GET_ATTR,
4747
self.handle,
48-
"id",
48+
"schema_id",
4949
)
5050
)
5151

5252
@property
53-
def schema_id(self) -> str:
53+
def tag(self) -> str:
5454
return str(
5555
bindings._object_get_attribute(
5656
self.GET_ATTR,
5757
self.handle,
58-
"schema_id",
58+
"tag",
5959
)
6060
)
6161

62+
@property
63+
def issuer_id(self) -> str:
64+
return str(
65+
bindings._object_get_attribute(
66+
self.GET_ATTR,
67+
self.handle,
68+
"issuer_id",
69+
)
70+
)
71+
72+
@property
73+
def signature_type(self) -> str:
74+
return str(
75+
bindings._object_get_attribute(
76+
self.GET_ATTR,
77+
self.handle,
78+
"signature_type",
79+
)
80+
)
81+
82+
6283

6384
class CredentialDefinitionPrivate(bindings.AnoncredsObject):
6485
@classmethod

0 commit comments

Comments
 (0)