Skip to content

Commit

Permalink
refactor: change credential index type from String to usize
Browse files Browse the repository at this point in the history
  • Loading branch information
itsyaasir committed Nov 12, 2024
1 parent 7694eac commit dfed4b1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl WasmStatusList2021Credential {
pub fn set_credential_status(
&mut self,
credential: &mut WasmCredential,
index: &str,
index: usize,
revoked_or_suspended: bool,
) -> Result<WasmStatusList2021Entry> {
let entry = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl WasmStatusList2021Entry {
pub fn new(
status_list: &str,
purpose: WasmStatusPurpose,
index: &str,
index: usize,
id: Option<String>,
) -> Result<WasmStatusList2021Entry> {
let status_list = Url::parse(status_list).map_err(|e| JsError::new(&e.to_string()))?;
Expand Down
2 changes: 1 addition & 1 deletion examples/1_advanced/8_status_list_2021.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async fn main() -> anyhow::Result<()> {

// Create an unsigned `UniversityDegree` credential for Alice.
// The issuer also chooses a unique `StatusList2021` index to be able to revoke it later.
let credential_index: &str = "420";
let credential_index: usize = 420;
let status: Status = StatusList2021Entry::new(
status_list_credential.id().cloned().unwrap(),
status_list_credential.purpose(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ impl StatusList2021Credential {
pub fn set_credential_status(
&mut self,
credential: &mut Credential,
index: &str,
index: usize,
revoked_or_suspended: bool,
) -> Result<StatusList2021Entry, StatusList2021CredentialError> {
let id = self
.id()
.cloned()
.ok_or(StatusList2021CredentialError::Unreferenceable)?;

let entry = StatusList2021Entry::new(id, self.purpose(), index, None);
let index_int = index.parse::<usize>().expect("should be integer serialized as string");

self.set_entry(index_int, revoked_or_suspended)?;
self.set_entry(index, revoked_or_suspended)?;
credential.credential_status = Some(entry.clone().into());

Ok(entry)
Expand Down
6 changes: 3 additions & 3 deletions identity_credential/src/revocation/status_list_2021/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl From<StatusList2021Entry> for Status {

impl StatusList2021Entry {
/// Creates a new [`StatusList2021Entry`].
pub fn new(status_list: Url, purpose: StatusPurpose, index: impl Into<String>, id: Option<Url>) -> Self {
pub fn new(status_list: Url, purpose: StatusPurpose, index: usize, id: Option<Url>) -> Self {
let id = id.unwrap_or_else(|| {
let mut id = status_list.clone();
id.set_fragment(None);
Expand All @@ -78,7 +78,7 @@ impl StatusList2021Entry {
type_: CREDENTIAL_STATUS_TYPE.to_owned(),
status_purpose: purpose,
status_list_credential: status_list,
status_list_index: index.into(),
status_list_index: index.to_string(),
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ mod tests {
let status = StatusList2021Entry::new(
Url::parse("https://example.com/credentials/status/3").unwrap(),
StatusPurpose::Revocation,
"94567",
94567,
Url::parse("https://example.com/credentials/status/3#94567").ok(),
);
assert_eq!(status, deserialized);
Expand Down

0 comments on commit dfed4b1

Please sign in to comment.