Skip to content

Restored get_attribute for creddef and updated python wrapper #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/ffi/cred_def.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::str::FromStr;

use ffi_support::FfiStr;
use ffi_support::{rust_string_to_c, FfiStr};

use super::error::{catch_error, ErrorCode};
use super::object::ObjectHandle;
Expand All @@ -12,6 +12,31 @@ use crate::services::{
CredentialKeyCorrectnessProof as KeyCorrectnessProof, SignatureType,
},
};
use std::os::raw::c_char;

#[no_mangle]
pub extern "C" fn anoncreds_credential_definition_get_attribute(
handle: ObjectHandle,
name: FfiStr,
result_p: *mut *const c_char,
) -> ErrorCode {
catch_error(|| {
check_useful_c_ptr!(result_p);
let cred_def = handle.load()?;
let cred_def = cred_def.cast_ref::<CredentialDefinition>()?;
let val = match name.as_opt_str().unwrap_or_default() {
"schema_id" => cred_def.schema_id.to_string().to_owned(),
"tag" => cred_def.tag.to_string().to_owned(),
"issuer_id" => cred_def.issuer_id.to_string().to_owned(),
"signature_type" => match cred_def.signature_type {
SignatureType::CL => "CL".to_string(),
},
s => return Err(err_msg!("Unsupported attribute: {}", s)),
};
unsafe { *result_p = rust_string_to_c(val) };
Ok(())
})
}

#[no_mangle]
pub extern "C" fn anoncreds_create_credential_definition(
Expand Down
29 changes: 25 additions & 4 deletions wrappers/python/anoncreds/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,46 @@ def load(cls, value: Union[dict, str, bytes, memoryview]) -> "CredentialDefiniti
)

@property
def id(self) -> str:
def schema_id(self) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to drop the "id" property accessor?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my knowledge there isn't actually an id field in CredentialDefinition.
https://github.com/Gavinok/anoncreds-rs/blob/main/src/data_types/cred_def.rs#L39-L48

Feel free to correct me if I am missing something

return str(
bindings._object_get_attribute(
self.GET_ATTR,
self.handle,
"id",
"schema_id",
)
)

@property
def schema_id(self) -> str:
def tag(self) -> str:
return str(
bindings._object_get_attribute(
self.GET_ATTR,
self.handle,
"schema_id",
"tag",
)
)

@property
def issuer_id(self) -> str:
return str(
bindings._object_get_attribute(
self.GET_ATTR,
self.handle,
"issuer_id",
)
)

@property
def signature_type(self) -> str:
return str(
bindings._object_get_attribute(
self.GET_ATTR,
self.handle,
"signature_type",
)
)



class CredentialDefinitionPrivate(bindings.AnoncredsObject):
@classmethod
Expand Down